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 | import { css } from '@emotion/react'; import { memo, useCallback } from 'react'; import { FormattedMessage } from 'react-intl'; import { Table } from '@allshares/studio-design-system'; import { AssignmentDateCell, type AssignmentDateCellProps } from '@amalia/assignments/common/components'; import { useUpdatePlanAssignments } from '@amalia/assignments/plans/state'; import { dayjs } from '@amalia/ext/dayjs'; import { canModifyPlanAssignments } from '@amalia/kernel/auth/shared'; import { useAbilityContext } from '@amalia/kernel/auth/state'; import { type Plan, type PlanAssignment } from '@amalia/payout-definition/plans/types'; export type PlanAssignmentsTableStartDateCellProps = { readonly plan: Pick<Plan, 'archived'>; readonly planAssignment: Pick<PlanAssignment, 'effectiveAsOf' | 'effectiveUntil' | 'id'>; }; export const PlanAssignmentsTableStartDateCell = memo(function PlanAssignmentsTableStartDateCell({ plan, planAssignment, }: PlanAssignmentsTableStartDateCellProps) { const ability = useAbilityContext(); const { mutate: updatePlanAssignments, isPending } = useUpdatePlanAssignments(); const handleChange: AssignmentDateCellProps< Pick<PlanAssignment, 'effectiveAsOf' | 'effectiveUntil' | 'id'> >['onChange'] = useCallback( (value, planAssignment) => updatePlanAssignments([ { id: planAssignment.id, effectiveAsOf: value, }, ]), [updatePlanAssignments], ); return !plan.archived && canModifyPlanAssignments(ability) ? ( <AssignmentDateCell boundary="start" disabled={isPending} maxDate={planAssignment.effectiveUntil} row={planAssignment} value={planAssignment.effectiveAsOf} onChange={handleChange} /> ) : ( <Table.Cell.Text> {planAssignment.effectiveAsOf ? ( dayjs.utc(planAssignment.effectiveAsOf, 'X').format('YYYY-MM-DD') ) : ( <span css={(theme) => css` color: ${theme.ds.colors.gray[700]}; [data-color-scheme='dark'] & { color: ${theme.ds.colors.gray[400]}; } `} > <FormattedMessage defaultMessage="Indefinite" /> </span> )} </Table.Cell.Text> ); }); |