Skip to content

The open alternative to Salesforce, designed for AI.

1.6 KB
Raw Blame
import { ROLE_SETTINGS_DELETE_ROLE_CONFIRMATION_MODAL_ID } from '@/settings/roles/role-settings/components/constants/RoleSettingsDeleteRoleConfirmationModalId';
import { SettingsRoleSettingsDeleteRoleConfirmationModalSubtitle } from '@/settings/roles/role-settings/components/SettingsRoleSettingsDeleteRoleConfirmationModalSubtitle';
import { ConfirmationDialog } from '@/ui/layout/dialog/components/ConfirmationDialog';
import { SettingsPath } from 'twenty-shared/types';
import { useMutation } from '@apollo/client/react';
import { DeleteOneRoleDocument } from '~/generated-metadata/graphql';
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
import { useLingui } from '@lingui/react/macro';

type SettingsRoleSettingsDeleteRoleConfirmationModalProps = {
  roleId: string;
};

export const SettingsRoleSettingsDeleteRoleConfirmationModal = ({
  roleId,
}: SettingsRoleSettingsDeleteRoleConfirmationModalProps) => {
  const { t } = useLingui();
  const [deleteRole] = useMutation(DeleteOneRoleDocument);

  const navigateSettings = useNavigateSettings();

  const handleConfirmClick = async () => {
    await deleteRole({
      variables: { roleId },
    });
    navigateSettings(SettingsPath.Roles);
  };

  return (
    <ConfirmationDialog
      dialogId={ROLE_SETTINGS_DELETE_ROLE_CONFIRMATION_MODAL_ID}
      title={t`Delete Role Permanently`}
      subtitle={
        <SettingsRoleSettingsDeleteRoleConfirmationModalSubtitle
          roleId={roleId}
        />
      }
      onConfirmClick={handleConfirmClick}
      confirmButtonText={t`Confirm`}
      confirmButtonColor="danger"
    />
  );
};