diff --git a/src/components/settings/locations/CreateLocationModal/CreateLocationModal.tsx b/src/components/settings/locations/CreateLocationModal/CreateLocationModal.tsx index 71a833d..d813013 100644 --- a/src/components/settings/locations/CreateLocationModal/CreateLocationModal.tsx +++ b/src/components/settings/locations/CreateLocationModal/CreateLocationModal.tsx @@ -39,6 +39,7 @@ export const CreateLocationModal = ({ revalidateTable, }: CreateLocationModalProps) => { const [isSaving, setIsSaving] = useState(false) + const [error, setError] = useState(null) const [formData, setFormData] = useState | null>(null) const [isFormValidState, setIsFormValidState] = useState(false) const [isFormValidating, setIsFormValidating] = useState(false) @@ -138,11 +139,20 @@ export const CreateLocationModal = ({ const handleSave = async () => { if (formData && !isReadonly) { - setIsSaving(true) - await insertLocation(formData) - await revalidateTable() - onClose() - setIsSaving(false) + try { + setIsSaving(true) + await insertLocation(formData) + await revalidateTable() + onClose() + setIsSaving(false) + } catch (e: unknown) { + if (e instanceof Error) { + setError(e.message) + } else { + setError("An unknown error occurred") + } + setIsSaving(false) + } } } @@ -154,6 +164,12 @@ export const CreateLocationModal = ({
+ {error && ( +
+

{error}

+
+ )} + { const [isSaving, setIsSaving] = useState(false) + const [error, setError] = useState(null) const [formData, setFormData] = useState | null>(null) const [previousLocation, setPreviousLocation] = useState | null>( null @@ -134,11 +135,20 @@ export const EditLocationModal = ({ const handleSave = async () => { if (formData && !isReadonly) { - setIsSaving(true) - await updateLocation(formData, previousLocation) - await revalidateTable() - onClose() - setIsSaving(false) + try { + setIsSaving(true) + await updateLocation(formData, previousLocation) + await revalidateTable() + onClose() + setIsSaving(false) + } catch (e: unknown) { + if (e instanceof Error) { + setError(e.message) + } else { + setError("An unknown error occurred") + } + setIsSaving(false) + } } } @@ -165,6 +175,12 @@ export const EditLocationModal = ({ )} + {error && ( +
+

{error}

+
+ )} + { const [isSaving, setIsSaving] = useState(false) + const [error, setError] = useState(null) const [formData, setFormData] = useState | null>(null) const [isFormValidState, setIsFormValidState] = useState(false) const [isFormValidating, setIsFormValidating] = useState(false) @@ -91,11 +92,20 @@ export const CreateServiceCategoryModal = ({ const handleSave = async () => { if (formData && !isReadonly) { - setIsSaving(true) - await insertServiceCategory(formData) - await revalidateTable() - onClose() - setIsSaving(false) + try { + setIsSaving(true) + await insertServiceCategory(formData) + await revalidateTable() + onClose() + setIsSaving(false) + } catch (e: unknown) { + if (e instanceof Error) { + setError(e.message) + } else { + setError("An unknown error occurred") + } + setIsSaving(false) + } } } @@ -107,6 +117,12 @@ export const CreateServiceCategoryModal = ({ + {error && ( +
+

{error}

+
+ )} + { const [isSaving, setIsSaving] = useState(false) + const [error, setError] = useState(null) const [formData, setFormData] = useState | null>(null) const [isFormValidState, setIsFormValidState] = useState(false) const [isFormValidating, setIsFormValidating] = useState(false) @@ -91,11 +92,20 @@ export const EditServiceCategoryModal = ({ const handleSave = async () => { if (formData && !isReadonly) { - setIsSaving(true) - await updateServiceCategory(formData) - await revalidateTable() - onClose() - setIsSaving(false) + try { + setIsSaving(true) + await updateServiceCategory(formData) + await revalidateTable() + onClose() + setIsSaving(false) + } catch (e: unknown) { + if (e instanceof Error) { + setError(e.message) + } else { + setError("An unknown error occurred") + } + setIsSaving(false) + } } } @@ -122,6 +132,12 @@ export const EditServiceCategoryModal = ({ )} + {error && ( +
+

{error}

+
+ )} + { const [isSaving, setIsSaving] = useState(false) + const [error, setError] = useState(null) const [formData, setFormData] = useState | null>(null) const [isFormValidState, setIsFormValidState] = useState(false) const [isFormValidating, setIsFormValidating] = useState(false) @@ -115,11 +116,20 @@ export const CreateServiceModal = ({ const handleSave = async () => { if (formData && !isReadonly) { - setIsSaving(true) - await insertService(formData) - await revalidateTable() - onClose() - setIsSaving(false) + try { + setIsSaving(true) + await insertService(formData) + await revalidateTable() + onClose() + setIsSaving(false) + } catch (e: unknown) { + if (e instanceof Error) { + setError(e.message) + } else { + setError("An unknown error occurred") + } + setIsSaving(false) + } } } @@ -131,6 +141,12 @@ export const CreateServiceModal = ({ + {error && ( +
+

{error}

+
+ )} + { const [isSaving, setIsSaving] = useState(false) + const [error, setError] = useState(null) const [formData, setFormData] = useState | null>(null) const [previousService, setPreviousService] = useState | null>(null) const [isFormValidState, setIsFormValidState] = useState(false) @@ -115,11 +116,20 @@ export const EditServiceModal = ({ const handleSave = async () => { if (formData && !isReadonly) { - setIsSaving(true) - await updateService(formData, previousService) - await revalidateTable() - onClose() - setIsSaving(false) + try { + setIsSaving(true) + await updateService(formData, previousService) + await revalidateTable() + onClose() + setIsSaving(false) + } catch (e: unknown) { + if (e instanceof Error) { + setError(e.message) + } else { + setError("An unknown error occurred") + } + setIsSaving(false) + } } } @@ -146,6 +156,12 @@ export const EditServiceModal = ({ )} + {error && ( +
+

{error}

+
+ )} + { const [isSaving, setIsSaving] = useState(false) + const [error, setError] = useState(null) const [formData, setFormData] = useState(null) const [previousUser, setPreviousUser] = useState(null) const editableRoles = useEditableRoles() @@ -61,11 +62,20 @@ export const EditStaffUserModal = ({ const handleSave = async () => { if (formData && !isReadonly) { - setIsSaving(true) - await updateStaffUser(formData, previousUser, editableRoles) - await revalidateTable() - onClose() - setIsSaving(false) + try { + setIsSaving(true) + await updateStaffUser(formData, previousUser, editableRoles) + await revalidateTable() + onClose() + setIsSaving(false) + } catch (e: unknown) { + if (e instanceof Error) { + setError(e.message) + } else { + setError("An unknown error occurred") + } + setIsSaving(false) + } } } @@ -97,6 +107,12 @@ export const EditStaffUserModal = ({ )} + {error && ( +
+

{error}

+
+ )} +