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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | 6x 9x 9x 9x 9x 9x 9x | import React from 'react';
import {
Dialog,
DialogTitle,
DialogContent,
DialogActions,
Button,
Box,
Typography,
IconButton,
Alert,
} from '@mui/material';
import { Close as CloseIcon, Warning as WarningIcon } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import { useBreakpoints } from '@/hooks/useBreakpoints';
import { useDeleteCompany } from '@/hooks/useCompanyMutations/useCompanyMutations';
import type { components } from '@/types/generated/company-api.types';
type CompanyDetail = components['schemas']['CompanyResponse'];
interface DeleteCompanyDialogProps {
company: CompanyDetail | null;
open: boolean;
onClose: () => void;
onSuccess?: () => void;
}
const DeleteCompanyDialog: React.FC<DeleteCompanyDialogProps> = ({
company,
open,
onClose,
onSuccess,
}) => {
const { t } = useTranslation('common');
const { isMobile } = useBreakpoints();
const deleteCompanyMutation = useDeleteCompany();
const handleDelete = async () => {
if (!company) return;
try {
await deleteCompanyMutation.mutateAsync(company.name);
onSuccess?.();
onClose();
} catch (error) {
console.error('Failed to delete company:', error);
// Error is handled by React Query mutation error state
}
};
Iif (!company) return null;
return (
<Dialog
open={open}
onClose={onClose}
maxWidth="sm"
fullWidth
fullScreen={isMobile}
aria-labelledby="delete-company-dialog-title"
>
<DialogTitle id="delete-company-dialog-title">
<Box display="flex" justifyContent="space-between" alignItems="center">
<Box display="flex" alignItems="center" gap={1}>
<WarningIcon color="error" />
<Typography variant="h6">{t('company.delete.title')}</Typography>
</Box>
<IconButton edge="end" color="inherit" onClick={onClose} aria-label={t('actions.close')}>
<CloseIcon />
</IconButton>
</Box>
</DialogTitle>
<DialogContent dividers>
{/* Company Information */}
<Box sx={{ mb: 3 }}>
<Typography variant="body1" gutterBottom>
{t('company.delete.message')}
</Typography>
<Typography variant="body1" sx={{ mt: 2 }}>
<strong>{company.displayName || company.name}</strong>
</Typography>
{company.industry && (
<Typography variant="body2" color="text.secondary">
{company.industry}
</Typography>
)}
{company.website && (
<Typography variant="body2" color="text.secondary">
{company.website}
</Typography>
)}
</Box>
{/* Data Warning */}
<Alert severity="error" sx={{ mb: 2 }}>
<Typography variant="body2" fontWeight="bold">
{t('company.delete.dataWarning')}
</Typography>
</Alert>
{/* Cascade Warning */}
<Alert severity="warning">
<Typography variant="body2">{t('company.delete.cascadeWarning')}</Typography>
</Alert>
{/* Mutation Error */}
{deleteCompanyMutation.isError && (
<Alert severity="error" sx={{ mt: 2 }}>
{t('company.errors.deleteFailed')}
</Alert>
)}
</DialogContent>
<DialogActions>
<Button onClick={onClose} variant="outlined">
{t('actions.cancel')}
</Button>
<Button
onClick={handleDelete}
variant="contained"
color="error"
disabled={deleteCompanyMutation.isPending}
>
{deleteCompanyMutation.isPending ? t('company.delete.deleting') : t('actions.delete')}
</Button>
</DialogActions>
</Dialog>
);
};
export default DeleteCompanyDialog;
|