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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x | import { IconTrash } from '@tabler/icons-react';
import { memo, useCallback } from 'react';
import { useIntl } from 'react-intl';
import { Table } from '@allshares/studio-design-system';
import { canDeleteThisPlanAgreementAssignment } from '@amalia/kernel/auth/shared';
import { useAbilityContext } from '@amalia/kernel/auth/state';
import { useDeletePlanAgreementAssignment, useIsPlanAgreementLoading } from '@amalia/plan-agreements/state';
import { type PlanAgreement, type PlanAgreementAssignment } from '@amalia/plan-agreements/types';
export type PlanAgreementDeleteAssignmentButtonProps = {
readonly planAgreement: PlanAgreement;
readonly assignment: PlanAgreementAssignment;
};
export const PlanAgreementDeleteAssignmentButton = memo(function PlanAgreementDeleteAssignmentButton({
assignment,
planAgreement,
}: PlanAgreementDeleteAssignmentButtonProps) {
const ability = useAbilityContext();
const { formatMessage } = useIntl();
const { mutate: deleteAssignment } = useDeletePlanAgreementAssignment(planAgreement.id, assignment.id);
const isLoading = useIsPlanAgreementLoading(planAgreement.id);
const handleClickDelete = useCallback(() => {
deleteAssignment();
}, [deleteAssignment]);
return (
canDeleteThisPlanAgreementAssignment(ability, planAgreement) && (
<Table.Cell.IconAction
disabled={isLoading}
icon={<IconTrash />}
label={formatMessage({
defaultMessage: 'Delete assignment',
})}
onClick={handleClickDelete}
/>
)
);
});
|