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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x | import { memo, useCallback } from 'react';
import { FormattedMessage } from 'react-intl';
import { Modal, type ModalProps } from '@allshares/studio-design-system';
import { useAssignmentsWithStatus } from '@amalia/assignments/common/components';
import { type Plan, type PlanAssignment } from '@amalia/payout-definition/plans/types';
import { useArchivePlan } from '@amalia/payout-definition/state';
export type ArchivePlanConfirmModalProps = Pick<ModalProps, 'isOpen' | 'onClose'> & {
readonly plan: Pick<Plan, 'id' | 'name'>;
readonly planAssignments: PlanAssignment[];
readonly onSuccess?: () => void;
};
export const ArchivePlanConfirmModal = memo(function ArchivePlanConfirmModal({
plan,
planAssignments,
isOpen,
onClose,
onSuccess,
}: ArchivePlanConfirmModalProps) {
const { mutate: archivePlan, isPending } = useArchivePlan();
const handleArchivePlan = useCallback(() => archivePlan(plan.id, { onSuccess }), [plan.id, archivePlan, onSuccess]);
const activeAssignmentsCount = useAssignmentsWithStatus(isOpen ? planAssignments : [], 'active').length;
return (
<Modal
isOpen={isOpen}
variant="danger"
onClose={onClose}
>
<Modal.Content>
<Modal.Header>
<Modal.Title>
<FormattedMessage defaultMessage="Archive plan" />
</Modal.Title>
</Modal.Header>
<Modal.Body>
<FormattedMessage
defaultMessage="Are you sure you want to archive the plan “<b>{planName}</b>”?{hasAssignments, select, true {{br}All active assignments of this plan will end today.} other {}}"
values={{
planName: plan.name,
hasAssignments: !!activeAssignmentsCount,
b: (chunks) => <strong>{chunks}</strong>,
}}
/>
</Modal.Body>
</Modal.Content>
<Modal.Actions>
<Modal.CancelAction />
<Modal.MainAction
isLoading={isPending}
onClick={handleArchivePlan}
>
<FormattedMessage defaultMessage="Archive" />
</Modal.MainAction>
</Modal.Actions>
</Modal>
);
});
|