diff --git a/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-actions.tsx b/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-actions.tsx new file mode 100644 index 00000000..3c8da517 --- /dev/null +++ b/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-actions.tsx @@ -0,0 +1,40 @@ +import { Button } from "@mui/material"; +import type { VendorEditorState } from "./work-order-vendor-editor-types"; +import { isVendorEditorValid } from "./work-order-vendor-editor-utils"; + +type WorkOrderVendorEditorActionsProps = { + viewOnly: boolean; + editor: VendorEditorState | null; + loading: boolean; + isSaving: boolean; + onClose: () => void; + onSave: () => void; +}; + +export function WorkOrderVendorEditorActions({ + viewOnly, + editor, + loading, + isSaving, + onClose, + onSave, +}: WorkOrderVendorEditorActionsProps) { + if (viewOnly) { + return ; + } + + return ( + <> + + + + ); +} diff --git a/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-dialog.tsx b/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-dialog.tsx index a1c3014a..78439708 100644 --- a/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-dialog.tsx +++ b/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-dialog.tsx @@ -1,18 +1,17 @@ import { Alert, Box, - Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, Stack, - TextField, Typography, } from "@mui/material"; import type { VendorEditorState } from "./work-order-vendor-editor-types"; -import { formatPhoneMask, isVendorEditorValid } from "./work-order-vendor-editor-utils"; +import { WorkOrderVendorEditorActions } from "./work-order-vendor-editor-actions"; +import { WorkOrderVendorEditorFields } from "./work-order-vendor-editor-fields"; type WorkOrderVendorEditorDialogProps = { editor: VendorEditorState | null; @@ -51,75 +50,23 @@ export function WorkOrderVendorEditorDialog({ ) : ( - <> - - onEditorChange((current) => - current ? { ...current, contactName: event.target.value } : current, - ) - } - slotProps={{ htmlInput: { maxLength: 200 } }} - /> - - onEditorChange((current) => - current ? { ...current, phone: formatPhoneMask(event.target.value) } : current, - ) - } - error={Boolean(editor?.phone && !/^\(\d{3}\) \d{3}-\d{4}$/.test(editor.phone))} - helperText="Use (XXX) XXX-XXXX" - /> - - onEditorChange((current) => - current ? { ...current, email: event.target.value } : current, - ) - } - /> - - onEditorChange((current) => - current ? { ...current, notes: event.target.value } : current, - ) - } - slotProps={{ htmlInput: { maxLength: 2000 } }} - /> - + )} - {viewOnly ? ( - - ) : ( - <> - - - - )} + ); diff --git a/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-fields.tsx b/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-fields.tsx new file mode 100644 index 00000000..3366ed82 --- /dev/null +++ b/src/app/(protected)/workorders/_components/view/work-order-vendor-editor-fields.tsx @@ -0,0 +1,71 @@ +import { TextField } from "@mui/material"; +import type { VendorEditorState } from "./work-order-vendor-editor-types"; +import { formatPhoneMask } from "./work-order-vendor-editor-utils"; + +type VendorEditorChange = ( + updater: (current: VendorEditorState | null) => VendorEditorState | null, +) => void; + +type WorkOrderVendorEditorFieldsProps = { + editor: VendorEditorState | null; + disabled: boolean; + onEditorChange: VendorEditorChange; +}; + +export function WorkOrderVendorEditorFields({ + editor, + disabled, + onEditorChange, +}: WorkOrderVendorEditorFieldsProps) { + return ( + <> + + onEditorChange((current) => + current ? { ...current, contactName: event.target.value } : current, + ) + } + slotProps={{ htmlInput: { maxLength: 200 } }} + /> + + onEditorChange((current) => + current ? { ...current, phone: formatPhoneMask(event.target.value) } : current, + ) + } + error={Boolean(editor?.phone && !/^\(\d{3}\) \d{3}-\d{4}$/.test(editor.phone))} + helperText="Use (XXX) XXX-XXXX" + /> + + onEditorChange((current) => + current ? { ...current, email: event.target.value } : current, + ) + } + /> + + onEditorChange((current) => + current ? { ...current, notes: event.target.value } : current, + ) + } + slotProps={{ htmlInput: { maxLength: 2000 } }} + /> + + ); +} diff --git a/src/app/(protected)/workorders/_components/wizard/wizard-step-vendor-time.tsx b/src/app/(protected)/workorders/_components/wizard/wizard-step-vendor-time.tsx index 2c91d342..f009b9d7 100644 --- a/src/app/(protected)/workorders/_components/wizard/wizard-step-vendor-time.tsx +++ b/src/app/(protected)/workorders/_components/wizard/wizard-step-vendor-time.tsx @@ -117,7 +117,7 @@ function WizardVendorDetail({ ); } -type WizardApptTimeFieldsProps = Omit; +type WizardApptTimeFieldsProps = Pick; function WizardApptTimeFields({ draft, onUpdate, onPatch }: WizardApptTimeFieldsProps) { const duration = calcDuration(draft.apptStart, draft.apptEnd);