All files / libs/plan-agreements/components/src/lib/modals PlanAgreementsConfirmModal.tsx

97.18% Statements 69/71
100% Branches 2/2
100% Functions 1/1
97.18% Lines 69/71

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 721x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { IconCheckbox } from '@tabler/icons-react';
import { memo, useCallback, useState } from 'react';
import { FormattedMessage } from 'react-intl';
 
import { Checkbox, Modal, Stack, Typography } from '@allshares/studio-design-system';
import { useConfirmPlanAgreementAssignment } from '@amalia/plan-agreements/state';
 
import { usePlanAgreementsModalsContext } from './PlanAgreementsModals.context';
 
export const PlanAgreementsConfirmModal = memo(function PlanAgreementsConfirmModal() {
  const [isConfirmationChecked, setIsConfirmationChecked] = useState(false);
 
  const { closeModal, planAgreementForModal } = usePlanAgreementsModalsContext();
 
  const { mutate: confirmPlanAgreement, isPending } = useConfirmPlanAgreementAssignment(
    planAgreementForModal?.id,
    planAgreementForModal?.userAssignment!.id,
  );
 
  const handleClickConfirm = useCallback(() => {
    confirmPlanAgreement();
    closeModal();
  }, [confirmPlanAgreement, closeModal]);
 
  return (
    <Modal
      isOpen
      onClose={closeModal}
    >
      <Modal.Content>
        <Modal.Header>
          <Modal.Title>
            <FormattedMessage defaultMessage="Confirm plan agreement" />
          </Modal.Title>
        </Modal.Header>
 
        <Modal.Body>
          <Stack gap={16}>
            <div>
              <FormattedMessage
                defaultMessage='Are you sure you want to confirm "<strong>{planAgreementName}</strong>"?'
                values={{
                  strong: (chunks) => <Typography variant="bodyBaseBold">{chunks}</Typography>,
                  planAgreementName: planAgreementForModal?.name,
                }}
              />
            </div>
 
            <Checkbox
              label={<FormattedMessage defaultMessage="I have read and agree to the plan agreement." />}
              onChange={setIsConfirmationChecked}
            />
          </Stack>
        </Modal.Body>
      </Modal.Content>
 
      <Modal.Actions>
        <Modal.CancelAction />
 
        <Modal.MainAction
          disabled={isPending || !isConfirmationChecked}
          icon={<IconCheckbox />}
          isLoading={isPending}
          onClick={handleClickConfirm}
        >
          <FormattedMessage defaultMessage="Confirm" />
        </Modal.MainAction>
      </Modal.Actions>
    </Modal>
  );
});