Skip to content

Commit

Permalink
fixup! ✨(frontend) replace portability request datagrid by Cunningham…
Browse files Browse the repository at this point in the history
… dataGrid
  • Loading branch information
AntoLC committed Aug 1, 2023
1 parent aa4415e commit b58e617
Showing 1 changed file with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
usePagination,
} from '@openfun/cunningham-react';
import { Box, Button, Heading, Text } from 'grommet';
import { CenterLoader } from 'lib-components';
import { CenterLoader, PortabilityRequest } from 'lib-components';
import { useEffect, useMemo, useState } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { IntlShape, defineMessages, useIntl } from 'react-intl';

import { WhiteCard } from 'components/Cards';
import { ITEM_PER_PAGE } from 'conf/global';
Expand Down Expand Up @@ -102,6 +102,38 @@ const messages = defineMessages({
},
});

/**
* Clean the data to be displayed in the table
*/
const cleanupPortabilityRequest = (
portabilityRequests: PortabilityRequest[] | undefined,
intl: IntlShape,
) =>
portabilityRequests
? portabilityRequests.map((portabilityRequest) => ({
id: portabilityRequest.id,
created_on: `${new Date(
portabilityRequest.created_on,
).toLocaleDateString(navigator.language)} ${new Date(
portabilityRequest.created_on,
).toLocaleTimeString(navigator.language)}`,
portabilityRequest: intl.formatMessage(
messages.rowPortabilityRequestText,
{
from_playlist: portabilityRequest.from_playlist.title,
for_playlist: portabilityRequest.for_playlist.title,
},
),
consumerSite: portabilityRequest.from_lti_consumer_site?.name,
fromUserEmail:
portabilityRequest?.from_user?.email ||
intl.formatMessage(messages.requestFromLtiUser),
updatedUserEmail: portabilityRequest?.updated_by_user?.email,
state: portabilityRequest.state,
can_accept_or_reject: portabilityRequest.can_accept_or_reject,
}))
: [];

interface PortabilityRequestsProps {
state?: string;
for_playlist_id?: string;
Expand Down Expand Up @@ -153,35 +185,8 @@ export const PortabilityRequests = ({
const hasNoResult = !isError && data && !data?.count && !isLoading;
const hasResult = !isError && data && data?.count && !isLoading;

/**
* Clean the data to be displayed in the table
*/
const rows = useMemo(
() =>
data?.results
? data?.results.map((portabilityRequest) => ({
id: portabilityRequest.id,
created_on: `${new Date(
portabilityRequest.created_on,
).toLocaleDateString(navigator.language)} ${new Date(
portabilityRequest.created_on,
).toLocaleTimeString(navigator.language)}`,
portabilityRequest: intl.formatMessage(
messages.rowPortabilityRequestText,
{
from_playlist: portabilityRequest.from_playlist.title,
for_playlist: portabilityRequest.for_playlist.title,
},
),
consumerSite: portabilityRequest.from_lti_consumer_site?.name,
fromUserEmail:
portabilityRequest?.from_user?.email ||
intl.formatMessage(messages.requestFromLtiUser),
updatedUserEmail: portabilityRequest?.updated_by_user?.email,
state: portabilityRequest.state,
can_accept_or_reject: portabilityRequest.can_accept_or_reject,
}))
: [],
() => cleanupPortabilityRequest(data?.results, intl),
[data?.results, intl],
);

Expand Down

0 comments on commit b58e617

Please sign in to comment.