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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | 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 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x 1x 8x 8x 8x 8x 8x 8x 2x 2x 8x 8x 8x 8x 8x 8x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x | /**
* @file EditSupplierDialog.tsx
* @module dialogs/EditSupplierDialog/EditSupplierDialog
*
* @summary
* Dialog container for editing supplier contact information.
* Orchestrates form logic hook and view components.
*
* @enterprise
* - Separation of concerns: Dialog wrapper, form logic, view components
* - Two-step workflow: search/select → edit info
* - Manages dialog lifecycle (open/close/reset)
* - Clean, readable component hierarchy
*/
import * as React from 'react';
import {
Dialog,
DialogTitle,
DialogContent,
DialogActions,
Button,
Box,
Alert,
Divider,
IconButton,
Stack,
Tooltip,
} from '@mui/material';
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
import { useTranslation } from 'react-i18next';
import { useToast } from '../../../../context/toast';
import { useHelp } from '../../../../hooks/useHelp';
import { useEditSupplierForm } from './useEditSupplierForm';
import { EditSupplierSearchStep } from './EditSupplierSearchStep';
import { EditSupplierInfoStep } from './EditSupplierInfoStep';
import { EditSupplierConfirmation } from './EditSupplierConfirmation';
import type { EditSupplierDialogProps } from './EditSupplierDialog.types';
/**
* Dialog for editing supplier contact information.
*
* @remarks
* Provides a guided two-step workflow:
* 1. Search and select supplier
* 2. Edit contact information
*
* Business rules:
* - Only ADMIN role can edit suppliers
* - Supplier name cannot be changed (immutable)
* - Only contactName, phone, and email are editable
*
* @component
* @param props - Dialog props
* @returns JSX element with dialog and workflow
*
* @example
* ```tsx
* <EditSupplierDialog
* open={isOpen}
* onClose={() => setIsOpen(false)}
* onSupplierUpdated={handleSupplierUpdated}
* />
* ```
*/
export const EditSupplierDialog: React.FC<EditSupplierDialogProps> = ({
open,
onClose,
onSupplierUpdated,
}) => {
const { t } = useTranslation(['common', 'suppliers']);
const toast = useToast();
const { openHelp } = useHelp();
// Form logic hook
const form = useEditSupplierForm(() => {
toast(t('suppliers:status.updated', 'Supplier information updated successfully!'), 'success');
onSupplierUpdated();
handleClose();
});
/**
* Handle dialog close.
*/
const handleClose = React.useCallback(() => {
form.resetForm();
onClose();
}, [form.resetForm, onClose]);
/**
* Handle showing confirmation dialog.
*/
const handleShowConfirmation = form.handleSubmit((values) => {
if (!form.selectedSupplier) {
form.setFormError(
t('errors:supplier.selection.noSupplierSelected', 'Please select a supplier.')
);
return;
}
form.setFormError('');
form.setPendingChanges(values);
form.setShowConfirmation(true);
});
return (
<>
{/* Main Edit Dialog */}
<Dialog open={open && !form.showConfirmation} onClose={handleClose} fullWidth maxWidth="sm">
<DialogTitle>
<Stack direction="row" alignItems="center" justifyContent="space-between">
<Box>{t('suppliers:dialogs.editSupplierTitle', 'Edit Supplier')}</Box>
<Tooltip title={t('actions.help', 'Help')}>
<IconButton size="small" onClick={() => openHelp('suppliers.manage')}>
<HelpOutlineIcon fontSize="small" />
</IconButton>
</Tooltip>
</Stack>
</DialogTitle>
<DialogContent dividers>
<Box sx={{ display: 'grid', gap: 2.5, mt: 1 }}>
{/* Error Display */}
{form.formError && (
<Alert severity="error" onClose={() => form.setFormError('')}>
{form.formError}
</Alert>
)}
{/* Step 1: Search and Select Supplier */}
<EditSupplierSearchStep
searchQuery={form.searchQuery}
onSearchQueryChange={form.handleSearchQueryChange}
searchResults={form.searchResults}
searchLoading={form.searchLoading}
onSelectSupplier={form.handleSelectSupplier}
/>
<Divider />
{/* Step 2: Edit Supplier Info */}
<EditSupplierInfoStep
selectedSupplier={form.selectedSupplier}
control={form.control}
errors={form.formState.errors}
isSubmitting={form.formState.isSubmitting}
/>
</Box>
</DialogContent>
<DialogActions sx={{ gap: 1 }}>
<Button onClick={handleClose} disabled={form.formState.isSubmitting}>
{t('common:actions.cancel', 'Cancel')}
</Button>
<Button
onClick={handleShowConfirmation}
variant="contained"
disabled={!form.selectedSupplier || form.formState.isSubmitting}
>
{t('suppliers:buttons.reviewChanges', 'Review Changes')}
</Button>
</DialogActions>
</Dialog>
{/* Confirmation Dialog */}
<EditSupplierConfirmation
open={form.showConfirmation}
supplier={form.selectedSupplier}
changes={form.pendingChanges}
formError={form.formError}
isSubmitting={form.formState.isSubmitting}
onConfirm={form.handleConfirmChanges}
onCancel={() => form.setShowConfirmation(false)}
/>
</>
);
};
export default EditSupplierDialog;
|