Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | import { css } from '@emotion/react'; import { Fragment, memo, useMemo } from 'react'; import { defineMessages, FormattedDate, FormattedMessage, FormattedNumber, useIntl } from 'react-intl'; import { Stack, Typography } from '@allshares/studio-design-system'; import { type dayjs } from '@amalia/ext/dayjs'; import { type LtiGrant } from '@amalia/lti/types'; import { buildGrantsEventsHistoryForUserForPlan } from './build-grants-events-history-for-user-for-plan'; import { type GrantsHistoryEventTypes } from './grants-event-history.types'; export const eventsTypeMessages = defineMessages<GrantsHistoryEventTypes>({ ALLOCATION: { defaultMessage: 'Allocation' }, EARNING: { defaultMessage: 'Earning' }, GOOD_LEAVER: { defaultMessage: 'Good Leaver' }, BAD_LEAVER: { defaultMessage: 'Bad Leaver' }, EXCEPTIONAL_LEAVER: { defaultMessage: 'Exceptional Leaver' }, }); const Header = memo(function Header({ label }: { readonly label: string }) { return ( <Typography variant="bodyXsmallRegular" css={css` color: var(--ds-color-gray-500); [data-color-scheme='dark'] & { color: var(--ds-color-dark-400); } margin-bottom: 4px; `} > {label} </Typography> ); }); const DateCell = memo(function DateCell({ date }: { readonly date: dayjs.Dayjs }) { return ( <Typography variant="bodyBaseRegular" css={css` color: var(--ds-color-gray-700); [data-color-scheme='dark'] & { color: var(--ds-color-dark-300); } `} > <FormattedDate day="2-digit" month="long" value={date.toDate()} year="numeric" /> </Typography> ); }); const EventTypeCell = memo(function EventTypeCell({ event }: { readonly event: GrantsHistoryEventTypes }) { return ( <Typography variant="bodyBaseMedium" css={css` color: var(--ds-color-gray-800); [data-color-scheme='dark'] & { color: var(--ds-color-dark-200); } `} > <FormattedMessage {...eventsTypeMessages[event]} /> </Typography> ); }); const SharesCell = memo(function SharesCell({ shares }: { readonly shares: number }) { return ( <Typography variant="bodyBaseRegular" css={css` color: var(--ds-color-gray-800); [data-color-scheme='dark'] & { color: var(--ds-color-dark-200); } place-self: flex-end; `} > <FormattedNumber signDisplay="always" value={shares} /> </Typography> ); }); interface GrantsEventsHistoryProps { readonly grants: LtiGrant[]; } export const GrantsEventsHistory = memo(function GrantsEventsHistory({ grants }: GrantsEventsHistoryProps) { const { formatMessage } = useIntl(); const grantsHistory = useMemo(() => buildGrantsEventsHistoryForUserForPlan(grants), [grants]); return ( <Stack gap={24} css={css` margin: 24px 72px 0px 72px; `} > <Typography variant="bodyBaseBold"> <FormattedMessage defaultMessage="Events history" /> </Typography> <div css={css` width: 360px; display: grid; grid-template-columns: auto auto fit-content(100%); column-gap: 16px; row-gap: 12px; `} > <Header label={formatMessage({ defaultMessage: 'Date' })} /> <Header label={formatMessage({ defaultMessage: 'Event' })} /> <Header label={formatMessage({ defaultMessage: 'Shares' })} /> {grantsHistory.map(({ date, event, value }, index) => ( // eslint-disable-next-line react/no-array-index-key <Fragment key={index}> <DateCell date={date} /> <EventTypeCell event={event} /> <SharesCell shares={value} /> </Fragment> ))} </div> </Stack> ); }); |