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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | import { css } from '@emotion/react'; import { IconArrowNarrowRight } from '@tabler/icons-react'; import { Fragment, memo, useMemo, type ReactNode } from 'react'; import { useIntl } from 'react-intl'; import { Collapse, CollapseIconChevron, Group, Stack, Typography, UnstyledButton, } from '@allshares/studio-design-system'; import { UserPrettyFormat } from '@amalia/data-capture/fields/components'; import { convertUtcTimestampToDate, type UnixTimestampInSeconds } from '@amalia/ext/dates'; import { useBoolState } from '@amalia/ext/react/hooks'; import { type UpsertPlanAssignmentsDryRunResponse } from '@amalia/payout-definition/plans/types'; export type PlanAssignmentsBulkCsvPreviewSectionProps = { readonly title: ReactNode; readonly planAssignments: | UpsertPlanAssignmentsDryRunResponse['insertedPlanAssignments'] | UpsertPlanAssignmentsDryRunResponse['unchangedPlanAssignments'] | UpsertPlanAssignmentsDryRunResponse['updatedPlanAssignments']; }; const renderDate = (timestamp: UnixTimestampInSeconds | null, fallback: string): string => timestamp ? (convertUtcTimestampToDate(timestamp) ?? '') : fallback; const renderDiff = (previous: string, next: string) => previous === next ? ( next ) : ( <Group align="center" gap={4} > <s css={(theme) => css` color: ${theme.ds.colors.gray[500]}; [data-color-scheme='dark'] & { color: ${theme.ds.colors.gray[600]}; } `} > {previous} </s> <IconArrowNarrowRight size={16} /> <span>{next}</span> </Group> ); export const PlanAssignmentsBulkCsvPreviewSection = memo(function PlanAssignmentsBulkCsvPreviewSection({ title, planAssignments, }: PlanAssignmentsBulkCsvPreviewSectionProps) { const { formatMessage } = useIntl(); const { isExpanded, toggleExpanded } = useBoolState(false, 'expanded'); const normalizedPlanAssignmentsByPlan = useMemo( () => Object.groupBy( planAssignments.map((planAssignment) => 'previous' in planAssignment ? planAssignment : { previous: planAssignment, next: planAssignment }, ), (planAssignment) => planAssignment.next.plan.id, ), [planAssignments], ); return ( <Stack gap={16}> <Group align="center" as={UnstyledButton} disabled={!planAssignments.length} gap={8} css={(theme) => css` &:disabled { color: ${theme.ds.colors.gray[600]}; [data-color-scheme='dark'] & { color: ${theme.ds.colors.gray[500]}; } } `} onClick={toggleExpanded} > <Typography variant="bodyBaseMedium">{title}</Typography> {!!planAssignments.length && ( <CollapseIconChevron isOpen={isExpanded} size={16} /> )} </Group> <Collapse lazy isOpen={isExpanded} > {Object.entries(normalizedPlanAssignmentsByPlan).map(([planId, planAssignments]) => ( <Stack key={planId} gap={8} css={css` margin-bottom: 16px; `} > <Typography variant="bodySmallMedium">{planAssignments?.[0].next.plan.name}</Typography> <div css={css` display: grid; grid-template-columns: auto auto auto auto; gap: 8px; `} > {planAssignments?.map((assignment) => ( <Fragment key={assignment.next.user.id}> <UserPrettyFormat firstName={assignment.next.user.firstName} lastName={assignment.next.user.lastName} pictureURL={assignment.next.user.pictureURL} /> <div> {renderDiff( renderDate(assignment.previous.effectiveAsOf, formatMessage({ defaultMessage: 'No start date' })), renderDate(assignment.next.effectiveAsOf, formatMessage({ defaultMessage: 'No start date' })), )} </div> <div> {renderDiff( renderDate(assignment.previous.effectiveUntil, formatMessage({ defaultMessage: 'No end date' })), renderDate(assignment.next.effectiveUntil, formatMessage({ defaultMessage: 'No end date' })), )} </div> <div> {renderDiff( assignment.previous.mainTeam?.name ?? formatMessage({ defaultMessage: 'No main team' }), assignment.next.mainTeam?.name ?? formatMessage({ defaultMessage: 'No main team' }), )} </div> </Fragment> ))} </div> </Stack> ))} </Collapse> </Stack> ); }); |