diff --git a/src/pages/master/aldeias/blocks/AddDialog.tsx b/src/pages/master/aldeias/blocks/AddDialog.tsx index 7d33c9b..bd4fe9a 100644 --- a/src/pages/master/aldeias/blocks/AddDialog.tsx +++ b/src/pages/master/aldeias/blocks/AddDialog.tsx @@ -25,6 +25,7 @@ import { CommandList } from '@/components/ui/command'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface SucosProps { id: number; @@ -54,6 +55,7 @@ const AddDialog = () => { const [formField, setFormField] = useState(initialState); const created_time = new Date(); const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); + const [isSubmitting, setIsSubmitting] = useState(false); const resetForm = () => { setFormField(initialState); @@ -63,24 +65,31 @@ const AddDialog = () => { const doCreateAldeias = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PostData(`${API_URL}/aldeias/create`, formField); + try { + const response = await PostData(`${API_URL}/aldeias/create`, formField); - if (response?.status) { - resetForm(); - handleAddDialog(false); - toast.success('Success Create Aldeia'); - reload(); - const createActivity = { - module: 'Manage Aldeia', - description: `Create Aldeia => ${formField.name}`, - action: 'C' - }; + if (response?.status) { + resetForm(); + handleAddDialog(false); + toast.success('Success Create Aldeia'); + reload(); - doSaveLogActivity(createActivity); - } else { - toast.error('Error Create Aldeia'); - setAlert({ show: true, message: 'Failed to create Aldeia. Please try again.' }); + const createActivity = { + module: 'Manage Aldeia', + description: `Create Aldeia => ${formField.name}`, + action: 'C' + }; + doSaveLogActivity(createActivity); + } else { + toast.error('Error Create Aldeia'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -221,7 +230,13 @@ const AddDialog = () => { - + diff --git a/src/pages/master/aldeias/blocks/EditDialog.tsx b/src/pages/master/aldeias/blocks/EditDialog.tsx index a7bcb66..502a6c2 100644 --- a/src/pages/master/aldeias/blocks/EditDialog.tsx +++ b/src/pages/master/aldeias/blocks/EditDialog.tsx @@ -25,6 +25,7 @@ import { CommandList } from '@/components/ui/command'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface SucosProps { id: number; @@ -54,6 +55,7 @@ const EditDialog = () => { const [formField, setFormField] = useState(initialState); const created_time = new Date(); const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); + const [isSubmitting, setIsSubmitting] = useState(false); const resetForm = () => { setFormField(initialState); @@ -63,24 +65,31 @@ const EditDialog = () => { const doUpdateAldeias = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PutData(`${API_URL}/aldeias/update/${selectedAldeias}`, formField); + try { + const response = await PutData(`${API_URL}/aldeias/update/${selectedAldeias}`, formField); - if (response?.status) { - resetForm(); - handleEditDialog(false, null); - toast.success('Success Update Aldeia'); - reload(); - const createActivity = { - module: 'Manage Aldeia', - description: `Edit Aldeia => ${selectedAldeias}`, - action: 'U' - }; + if (response?.status) { + resetForm(); + handleEditDialog(false, null); + toast.success('Success Update Aldeia'); + reload(); + const createActivity = { + module: 'Manage Aldeia', + description: `Edit Aldeia => ${selectedAldeias}`, + action: 'U' + }; - doSaveLogActivity(createActivity); - } else { - toast.error('Error Update Aldeia'); - setAlert({ show: true, message: 'Error Update Aldeia' }); + doSaveLogActivity(createActivity); + } else { + toast.error('Error Update Aldeia'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong'); + } finally { + setIsSubmitting(false); } }, [selectedAldeias, formField] @@ -258,7 +267,13 @@ const EditDialog = () => {
- +
diff --git a/src/pages/master/conversion/blocks/AddDialog.tsx b/src/pages/master/conversion/blocks/AddDialog.tsx index 96270b1..4b3197d 100644 --- a/src/pages/master/conversion/blocks/AddDialog.tsx +++ b/src/pages/master/conversion/blocks/AddDialog.tsx @@ -34,6 +34,7 @@ import { } from '@/components/ui/select'; import { useManageConversionContext } from '../hooks/useManageConversionContext'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface CurrencyProps { ID: string; name: string; @@ -65,6 +66,7 @@ const AddDialog = () => { const [formField, setFormField] = useState(initialState); const created_time = new Date(); const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); + const [isSubmitting, setIsSubmitting] = useState(false); const resetForm = () => { setFormField(initialState); @@ -74,24 +76,31 @@ const AddDialog = () => { const doCreateConversion = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PostData(`${API_URL}/dashboard/conversion`, formField); + try { + const response = await PostData(`${API_URL}/dashboard/conversion`, formField); - if (response?.status) { - resetForm(); - handleAddDialog(false); - toast.success('Success Create Conversion'); - const createActivity = { - module: 'Manage Conversion', - description: `Create Conversion => ${formField.id_currency_origin} => ${formField.id_currency_destination}`, - action: 'C' - }; + if (response?.status) { + resetForm(); + handleAddDialog(false); + toast.success('Success Create Conversion'); + const createActivity = { + module: 'Manage Conversion', + description: `Create Conversion => ${formField.id_currency_origin} => ${formField.id_currency_destination}`, + action: 'C' + }; - doSaveLogActivity(createActivity); - reload(); - } else { - toast.error('Error Create Conversion'); - setAlert({ show: true, message: 'Failed to create Conversion. Please try again.' }); + doSaveLogActivity(createActivity); + reload(); + } else { + toast.error('Error Create Conversion'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something Went Wrong'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -280,7 +289,13 @@ const AddDialog = () => { - + diff --git a/src/pages/master/conversion/blocks/EditDialog.tsx b/src/pages/master/conversion/blocks/EditDialog.tsx index f32f8f2..a178229 100644 --- a/src/pages/master/conversion/blocks/EditDialog.tsx +++ b/src/pages/master/conversion/blocks/EditDialog.tsx @@ -34,6 +34,7 @@ import { } from '@/components/ui/select'; import { useManageConversionContext } from '../hooks/useManageConversionContext'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface CurrencyProps { ID: string; name: string; @@ -49,6 +50,7 @@ const EditDialog = () => { const parsedUser = getAuth()?.user; const [currencies, setCurrencies] = useState([]); const [open, setOpen] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const [isLoading, setIsLoading] = useState(false); const [alert, setAlert] = useState({ show: false, @@ -75,26 +77,33 @@ const EditDialog = () => { const doUpdateConversion = useCallback( async (e: React.FormEvent) => { e.preventDefault(); - if (!showEditDialog) return; - const response = await PutData(`${API_URL}/dashboard/conversion/${selectedConversion}`, { - ...formField - }); + setIsSubmitting(true); - if (response?.status) { - resetForm(); - handleEditDialog(false, null); - toast.success('Success Update Conversion'); - const createActivity = { - module: 'Manage Conversion', - description: `Update Conversion => ${selectedConversion}`, - action: 'U' - }; + try { + const response = await PutData(`${API_URL}/dashboard/conversion/${selectedConversion}`, { + ...formField + }); - doSaveLogActivity(createActivity); - reload(); - } else { - toast.error('Error Create Conversion'); - setAlert({ show: true, message: 'Failed to Update Conversion. Please try again.' }); + if (response?.status) { + resetForm(); + handleEditDialog(false, null); + toast.success('Success Update Conversion'); + const createActivity = { + module: 'Manage Conversion', + description: `Update Conversion => ${selectedConversion}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); + reload(); + } else { + toast.error('Error Create Conversion'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -305,7 +314,13 @@ const EditDialog = () => {
- +
diff --git a/src/pages/master/currency/blocks/AddDialog.tsx b/src/pages/master/currency/blocks/AddDialog.tsx index 877ac08..9371a44 100644 --- a/src/pages/master/currency/blocks/AddDialog.tsx +++ b/src/pages/master/currency/blocks/AddDialog.tsx @@ -35,6 +35,7 @@ import { import { useManageCurrencyContext } from '../hooks/useManageCurrencyContext'; import { prefix } from 'stylis'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface CurrencyProps { ID: string; name: string; @@ -50,6 +51,7 @@ const AddDialog = () => { const parsedUser = getAuth()?.user; const [currencies, setCurrencies] = useState([]); const [open, setOpen] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -74,24 +76,31 @@ const AddDialog = () => { const doCreateCurrency = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PostData(`${API_URL}/dashboard/currency/`, formField); + try { + const response = await PostData(`${API_URL}/dashboard/currency/`, formField); - if (response?.status) { - resetForm(); - handleAddDialog(false); - toast.success('Success Create Currency'); - const createActivity = { - module: 'Manage Currency', - description: `Create Currency=> ${formField.name}`, - action: 'C' - }; + if (response?.status) { + resetForm(); + handleAddDialog(false); + toast.success('Success Create Currency'); + const createActivity = { + module: 'Manage Currency', + description: `Create Currency=> ${formField.name}`, + action: 'C' + }; - doSaveLogActivity(createActivity); - reload(); - } else { - toast.error('Error Create Currency'); - setAlert({ show: true, message: 'Failed to create Currency. Please try again.' }); + doSaveLogActivity(createActivity); + reload(); + } else { + toast.error('Error Create Currency'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -220,7 +229,13 @@ const AddDialog = () => { - + diff --git a/src/pages/master/currency/blocks/EditDialog.tsx b/src/pages/master/currency/blocks/EditDialog.tsx index faee892..f900f06 100644 --- a/src/pages/master/currency/blocks/EditDialog.tsx +++ b/src/pages/master/currency/blocks/EditDialog.tsx @@ -34,6 +34,7 @@ import { } from '@/components/ui/select'; import { useManageCurrencyContext } from '../hooks/useManageCurrencyContext'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface CurrencyProps { ID: string; name: string; @@ -49,6 +50,7 @@ const EditDialog = () => { const parsedUser = getAuth()?.user; const [currencies, setCurrencies] = useState([]); const [open, setOpen] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const [isLoading, setIsLoading] = useState(false); const [alert, setAlert] = useState({ show: false, @@ -74,26 +76,34 @@ const EditDialog = () => { const doUpdateCurrency = useCallback( async (e: React.FormEvent) => { e.preventDefault(); - if (!showEditDialog) return; - const response = await PutData(`${API_URL}/dashboard/currency/${selectedCurrency}`, { - ...formField - }); + setIsSubmitting(true); - if (response?.status) { - resetForm(); - handleEditDialog(false, null); - toast.success('Success Update Currency'); - const createActivity = { - module: 'Manage Currency', - description: `Update Currency=> ${selectedCurrency}`, - action: 'U' - }; + try { + const response = await PutData( + `${API_URL}/dashboard/currency/${selectedCurrency}`, + formField + ); - doSaveLogActivity(createActivity); - reload(); - } else { - toast.error('Error Create Currency'); - setAlert({ show: true, message: 'Failed to Update Currency. Please try again.' }); + if (response?.status) { + resetForm(); + handleEditDialog(false, null); + toast.success('Success Update Currency'); + const createActivity = { + module: 'Manage Currency', + description: `Update Currency=> ${selectedCurrency}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); + reload(); + } else { + toast.error('Error Create Currency'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -235,7 +245,13 @@ const EditDialog = () => {
- +
diff --git a/src/pages/master/municipios/blocks/AddDialog.tsx b/src/pages/master/municipios/blocks/AddDialog.tsx index 2b88edc..ca2f96b 100644 --- a/src/pages/master/municipios/blocks/AddDialog.tsx +++ b/src/pages/master/municipios/blocks/AddDialog.tsx @@ -17,6 +17,7 @@ import { toast } from 'sonner'; import { getAuth, useAuthContext } from '@/auth'; import { useCallApi } from '@/hooks'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; const API_URL = apiConfig.service_master_data; @@ -39,6 +40,7 @@ const AddDialog = () => { const [formField, setFormField] = useState(initialState); const created_time = new Date(); const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); + const [isSubmitting, setIsSubmitting] = useState(false); const resetForm = () => { setFormField(initialState); @@ -48,23 +50,31 @@ const AddDialog = () => { const doCreateMunicipio = useCallback( async (e: React.FormEvent) => { e.preventDefault(); - const response = await PostData(`${API_URL}/municipios/create`, formField); + setIsSubmitting(true); - if (response?.status) { - handleAddDialog(false); - resetForm(); - reload(); - toast.success('Municipio created successfully!'); - const createActivity = { - module: 'Manage Municipio', - description: `Create Municipio => ${formField.name}`, - action: 'C' - }; + try { + const response = await PostData(`${API_URL}/municipios/create`, formField); - doSaveLogActivity(createActivity); - } else { - toast.error('Failed to create municipio.'); - setAlert({ show: true, message: 'Failed to create municipio. Please try again.' }); + if (response?.status) { + handleAddDialog(false); + resetForm(); + reload(); + toast.success('Municipio created successfully!'); + const createActivity = { + module: 'Manage Municipio', + description: `Create Municipio => ${formField.name}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); + } else { + toast.error('Failed to create municipio.'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong. Please try again.'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -140,8 +150,12 @@ const AddDialog = () => { - diff --git a/src/pages/master/municipios/blocks/EditDialog.tsx b/src/pages/master/municipios/blocks/EditDialog.tsx index ef7b3d3..89e2687 100644 --- a/src/pages/master/municipios/blocks/EditDialog.tsx +++ b/src/pages/master/municipios/blocks/EditDialog.tsx @@ -17,6 +17,7 @@ import { Button } from '@/components/ui/button'; import { getAuth, useAuthContext } from '@/auth'; import { useCallApi } from '@/hooks'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; const API_URL = apiConfig.service_master_data; @@ -27,6 +28,7 @@ const EditDialog = () => { const { PutData, GetData } = useCallApi(); const parsedUser = getAuth()?.user; const [isLoading, setIsLoading] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -50,26 +52,34 @@ const EditDialog = () => { const doUpdateMunicipios = useCallback( async (e: React.FormEvent) => { e.preventDefault(); - const response = await PutData( - `${API_URL}/municipios/update/${selectedMunicipios}`, - formField - ); + setIsSubmitting(true); - if (response?.status) { - handleEditDialog(false, null); - resetForm(); - toast.success('Success update municipio'); - reload(); - const createActivity = { - module: 'Manage Municipios', - description: `Edit Municipio => ${selectedMunicipios}`, - action: 'U' - }; + try { + const response = await PutData( + `${API_URL}/municipios/update/${selectedMunicipios}`, + formField + ); - doSaveLogActivity(createActivity); - } else { - toast.error('Failed update user'); - setAlert({ show: true, message: 'Failed to update municipio. Please try again.' }); + if (response?.status) { + handleEditDialog(false, null); + resetForm(); + toast.success('Success update municipio'); + reload(); + const createActivity = { + module: 'Manage Municipios', + description: `Edit Municipio => ${selectedMunicipios}`, + action: 'U' + }; + + doSaveLogActivity(createActivity); + } else { + toast.error('Failed update user'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [selectedMunicipios, formField] @@ -177,7 +187,13 @@ const EditDialog = () => {
- +
diff --git a/src/pages/master/postoadms/blocks/AddDialog.tsx b/src/pages/master/postoadms/blocks/AddDialog.tsx index 6958a63..b361d70 100644 --- a/src/pages/master/postoadms/blocks/AddDialog.tsx +++ b/src/pages/master/postoadms/blocks/AddDialog.tsx @@ -25,6 +25,7 @@ import { CommandList } from '@/components/ui/command'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface MunicipioProps { id: number; @@ -41,6 +42,7 @@ const AddDialog = () => { const parsedUser = getAuth()?.user; const [municipios, setMunicipios] = useState([]); const [open, setOpen] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -65,27 +67,34 @@ const AddDialog = () => { const doCreatePostoAdm = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PostData(`${API_URL}/postoadms/create`, formField); + try { + const response = await PostData(`${API_URL}/postoadms/create`, formField); - if (response?.status) { - handleAddDialog(false); - resetForm(); - reload(); - toast.success('Postu Administrativo created successfully!'); - const createActivity = { - module: 'Manage Posto Administrativo', - description: `Create Postu Administrativo => ${formField.name}`, - action: 'C' - }; + if (response?.status) { + handleAddDialog(false); + resetForm(); + reload(); + toast.success('Postu Administrativo created successfully!'); + const createActivity = { + module: 'Manage Posto Administrativo', + description: `Create Postu Administrativo => ${formField.name}`, + action: 'C' + }; - doSaveLogActivity(createActivity); - } else { - toast.error('Failed to create Postu Administrativo. Please try again.'); - setAlert({ - show: true, - message: 'Failed to create Postu Administrativo. Please try again.' - }); + doSaveLogActivity(createActivity); + } else { + toast.error('Failed to create Postu Administrativo. Please try again.'); + setAlert({ + show: true, + message: response?.message + }); + } + } catch (error) { + toast.error('Something went wrong. Please try again.'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -222,7 +231,13 @@ const AddDialog = () => { - + diff --git a/src/pages/master/postoadms/blocks/EditDialog.tsx b/src/pages/master/postoadms/blocks/EditDialog.tsx index 93e73a8..7200831 100644 --- a/src/pages/master/postoadms/blocks/EditDialog.tsx +++ b/src/pages/master/postoadms/blocks/EditDialog.tsx @@ -25,6 +25,7 @@ import { CommandList } from '@/components/ui/command'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface MunicipioProps { id: number; @@ -43,6 +44,7 @@ const EditDialog = () => { const [open, setOpen] = useState(false); const [isLoading, setIsLoading] = useState(false); const [municipios, setMunicipios] = useState([]); + const [isSubmitting, setIsSubmitting] = useState(false); const [alert, setAlert] = useState({ show: false, @@ -66,28 +68,38 @@ const EditDialog = () => { const doUpdatePostoAdm = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PutData(`${API_URL}/postoadms/update/${selectedPostoAdms}`, formField); + try { + const response = await PutData( + `${API_URL}/postoadms/update/${selectedPostoAdms}`, + formField + ); - if (response?.status) { - handleEditDialog(false, null); - resetForm(); - toast.success('Success Update Postu Administrativo'); - reload(); + if (response?.status) { + handleEditDialog(false, null); + resetForm(); + toast.success('Success Update Postu Administrativo'); + reload(); - const createActivity = { - module: 'Manage Postu Administrativo', - description: `Edit Postu Administrativo => ${selectedPostoAdms}`, - action: 'U' - }; + const createActivity = { + module: 'Manage Postu Administrativo', + description: `Edit Postu Administrativo => ${selectedPostoAdms}`, + action: 'U' + }; - doSaveLogActivity(createActivity); - } else { - toast.error('Error Update Postu Administrativo'); - setAlert({ - show: true, - message: 'Failed to update Postu Administrativo Please try again.' - }); + doSaveLogActivity(createActivity); + } else { + toast.error('Error Update Postu Administrativo'); + setAlert({ + show: true, + message: response?.message + }); + } + } catch (error) { + toast.error('Something went wrong, please try again'); + } finally { + setIsSubmitting(false); } }, [selectedPostoAdms, formField] @@ -261,7 +273,13 @@ const EditDialog = () => {
- +
diff --git a/src/pages/master/products/blocks/AddDialog.tsx b/src/pages/master/products/blocks/AddDialog.tsx index 465b2db..f20e8dc 100644 --- a/src/pages/master/products/blocks/AddDialog.tsx +++ b/src/pages/master/products/blocks/AddDialog.tsx @@ -24,6 +24,7 @@ import { } from '@/components/ui/select'; import { doSaveLogActivity } from '@/actions/GlobalActions'; import { NumericFormat } from 'react-number-format'; +import { RefreshCw } from 'lucide-react'; interface ProviderProps { provider_id: number; @@ -72,6 +73,7 @@ const AddDialog = () => { }; const [formField, setFormField] = useState(initialState); const [providers, setProviders] = useState([]); + const [isSubmitting, setIsSubmitting] = useState(false); const created_time = new Date(); const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); @@ -83,25 +85,32 @@ const AddDialog = () => { const doCreateProduct = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PostData(`${API_URL}/product/create`, formField); + try { + const response = await PostData(`${API_URL}/product/create`, formField); - if (response?.status) { - resetForm(); - handleAddDialog(false); - toast.success('Success Create Product'); - reload(); + if (response?.status) { + resetForm(); + handleAddDialog(false); + toast.success('Success Create Product'); + reload(); - const createActivity = { - module: 'Manage Products', - description: `Create Product => ${formField.name}`, - action: 'C' - }; + const createActivity = { + module: 'Manage Products', + description: `Create Product => ${formField.name}`, + action: 'C' + }; - doSaveLogActivity(createActivity); - } else { - toast.error('Failed Create Product'); - setAlert({ show: true, message: response?.message }); + doSaveLogActivity(createActivity); + } else { + toast.error('Failed Create Product'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -356,9 +365,7 @@ const AddDialog = () => {
- + +
)} @@ -370,7 +384,13 @@ const AddDialog = () => { - + diff --git a/src/pages/master/provider/blocks/EditDialog.tsx b/src/pages/master/provider/blocks/EditDialog.tsx index 9315e2d..1a34f96 100644 --- a/src/pages/master/provider/blocks/EditDialog.tsx +++ b/src/pages/master/provider/blocks/EditDialog.tsx @@ -33,6 +33,7 @@ import { CommandList } from '@/components/ui/command'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; const API_URL_CUSTOMER = apiConfig.service_customer; const API_URL_MASTERDATA = apiConfig.service_master_data; @@ -76,6 +77,7 @@ const EditDialog = () => { const [formField, setFormField] = useState(initialState); const [transactions, setTransactions] = useState([]); const [customers, setCustomers] = useState([]); + const [isSubmitting, setIsSubmitting] = useState(false); const resetForm = () => { setFormField(initialState); @@ -85,27 +87,34 @@ const EditDialog = () => { const doUpdateProvider = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PutData( - `${API_URL_MASTERDATA}/provider/update/${selectedProvider}`, - formField - ); + try { + const response = await PutData( + `${API_URL_MASTERDATA}/provider/update/${selectedProvider}`, + formField + ); - if (response?.status) { - resetForm(); - handleEditDialog(false, null); - toast.success('Provider updated successfully.'); - const createActivity = { - module: 'Manage Provider', - description: `Update Provider => ${selectedProvider}`, - action: 'U' - }; + if (response?.status) { + resetForm(); + handleEditDialog(false, null); + toast.success('Provider updated successfully.'); + const createActivity = { + module: 'Manage Provider', + description: `Update Provider => ${selectedProvider}`, + action: 'U' + }; - doSaveLogActivity(createActivity); - reload(); - } else { - toast.error('Failed to update provider.'); - setAlert({ show: true, message: 'Failed to update provider.' }); + doSaveLogActivity(createActivity); + reload(); + } else { + toast.error('Failed to update provider.'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [selectedProvider, formField] @@ -409,7 +418,13 @@ const EditDialog = () => { )}
- +
diff --git a/src/pages/master/reward/blocks/AddDialog.tsx b/src/pages/master/reward/blocks/AddDialog.tsx index 7bc759f..71727b8 100644 --- a/src/pages/master/reward/blocks/AddDialog.tsx +++ b/src/pages/master/reward/blocks/AddDialog.tsx @@ -24,6 +24,7 @@ import { SelectValue } from '@/components/ui/select'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; const API_URL = apiConfig.service_master_data; @@ -48,6 +49,7 @@ const AddDialog = () => { }; const [formField, setFormField] = useState(initialState); + const [isSubmitting, setIsSubmitting] = useState(false); const created_time = new Date(); const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); @@ -68,24 +70,31 @@ const AddDialog = () => { const doCreateReward = useCallback( async (e: React.FormEvent) => { e.preventDefault(); - // console.log('Data yang akan dikirim:', formField); - const response = await PostData(`${API_URL}/reward/create`, formField); + setIsSubmitting(true); - if (response?.status) { - handleAddDialog(false); - resetForm(); - reload(); - toast.success('Reward Create successfully!'); - const createActivity = { - module: 'Manage Reward', - description: `Create New Reward => ${formField.name}`, - action: 'C' - }; + try { + const response = await PostData(`${API_URL}/reward/create`, formField); - doSaveLogActivity(createActivity); - } else { - toast.error('Failed to create reward.'); - setAlert({ show: true, message: 'Failed to create reward. Please try again.' }); + if (response?.status) { + handleAddDialog(false); + resetForm(); + reload(); + toast.success('Reward Create successfully!'); + const createActivity = { + module: 'Manage Reward', + description: `Create New Reward => ${formField.name}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); + } else { + toast.error('Failed to create reward.'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -223,8 +232,12 @@ const AddDialog = () => { - diff --git a/src/pages/master/reward/blocks/EditDialog.tsx b/src/pages/master/reward/blocks/EditDialog.tsx index c8a79b0..06ac26d 100644 --- a/src/pages/master/reward/blocks/EditDialog.tsx +++ b/src/pages/master/reward/blocks/EditDialog.tsx @@ -24,6 +24,7 @@ import { } from '@/components/ui/select'; import { useManageRewardContext } from '../hooks/useManageRewardContext'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; const API_URL = apiConfig.service_master_data; @@ -34,6 +35,7 @@ const EditDialog = () => { const { PutData, GetData } = useCallApi(); const parsedUser = getAuth()?.user; const [isLoading, setIsLoading] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -69,25 +71,31 @@ const EditDialog = () => { const doUpdateReward = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - // console.log('Ini datanya:', selectedReward); - const response = await PutData(`${API_URL}/reward/update/${selectedReward}`, formField); + try { + const response = await PutData(`${API_URL}/reward/update/${selectedReward}`, formField); - if (response?.status) { - resetForm(); - handleEditDialog(false, null); - toast.success('Success Update Reward'); - reload(); - const editActivity = { - module: 'Manage Reward', - description: `Edit Reward => ${formField.name}`, - action: 'U' - }; + if (response?.status) { + resetForm(); + handleEditDialog(false, null); + toast.success('Success Update Reward'); + reload(); + const editActivity = { + module: 'Manage Reward', + description: `Edit Reward => ${formField.name}`, + action: 'U' + }; - doSaveLogActivity(editActivity); - } else { - toast.error('Error Update Reward'); - setAlert({ show: true, message: 'Failed to Update Reward. Please try again.' }); + doSaveLogActivity(editActivity); + } else { + toast.error('Error Update Reward'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [selectedReward, formField] @@ -261,7 +269,13 @@ const EditDialog = () => {
- +
diff --git a/src/pages/master/sucos/blocks/AddDialog.tsx b/src/pages/master/sucos/blocks/AddDialog.tsx index 97fbd99..5452053 100644 --- a/src/pages/master/sucos/blocks/AddDialog.tsx +++ b/src/pages/master/sucos/blocks/AddDialog.tsx @@ -25,6 +25,7 @@ import { CommandList } from '@/components/ui/command'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface PostoAdmsProps { PostoAdms_id: number; @@ -40,6 +41,7 @@ const AddDialog = () => { const parsedUser = getAuth()?.user; const [posto_adms, setPostoadms] = useState([]); const [open, setOpen] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -63,23 +65,31 @@ const AddDialog = () => { const doCreateSucos = useCallback( async (e: React.FormEvent) => { e.preventDefault(); - const response = await PostData(`${API_URL}/sucos/create`, formField); + setIsSubmitting(true); - if (response?.status) { - resetForm(); - handleAddDialog(false); - reload(); - toast.success('Sucos created successfully!'); - const createActivity = { - module: 'Manage Sucos', - description: `Create Sucos => ${formField.name}`, - action: 'C' - }; + try { + const response = await PostData(`${API_URL}/sucos/create`, formField); - doSaveLogActivity(createActivity); - } else { - toast.error('Failed to create Sucos Please try again.'); - setAlert({ show: true, message: 'Failed to create Sucos Please try again.' }); + if (response?.status) { + resetForm(); + handleAddDialog(false); + reload(); + toast.success('Sucos created successfully!'); + const createActivity = { + module: 'Manage Sucos', + description: `Create Sucos => ${formField.name}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); + } else { + toast.error('Failed to create Sucos Please try again.'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong. Please try again.'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -225,7 +235,13 @@ const AddDialog = () => { - + diff --git a/src/pages/master/sucos/blocks/EditDialog.tsx b/src/pages/master/sucos/blocks/EditDialog.tsx index 42d1dd8..97e5ffa 100644 --- a/src/pages/master/sucos/blocks/EditDialog.tsx +++ b/src/pages/master/sucos/blocks/EditDialog.tsx @@ -25,6 +25,7 @@ import { CommandList } from '@/components/ui/command'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface PostoAdmsProps { PostoAdms_id: number; // Ubah ke PostoAdms_id @@ -39,6 +40,7 @@ const EditDialog = () => { const { PutData, GetData } = useCallApi(); const parsedUser = getAuth()?.user; const [open, setOpen] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const [isLoading, setIsLoading] = useState(false); const [postoadms, setPostoadms] = useState([]); @@ -69,24 +71,31 @@ const EditDialog = () => { const doUpdateSucos = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PutData(`${API_URL}/sucos/update/${selectedSucos}`, formField); + try { + const response = await PutData(`${API_URL}/sucos/update/${selectedSucos}`, formField); - if (response?.status) { - resetForm(); - handleEditDialog(false, null); - toast.success('Success Update Sucos'); - reload(); - const createActivity = { - module: 'Manage Sucos', - description: `Edit Sucos => ${selectedSucos}`, - action: 'U' - }; + if (response?.status) { + resetForm(); + handleEditDialog(false, null); + toast.success('Success Update Sucos'); + reload(); + const createActivity = { + module: 'Manage Sucos', + description: `Edit Sucos => ${selectedSucos}`, + action: 'U' + }; - doSaveLogActivity(createActivity); - } else { - toast.error('Failed Update Sucos'); - setAlert({ show: true, message: 'Failed Update Sucos. Please try again' }); + doSaveLogActivity(createActivity); + } else { + toast.error('Failed Update Sucos'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [selectedSucos, formField] @@ -260,7 +269,13 @@ const EditDialog = () => {
- +
diff --git a/src/pages/master/wallet/blocks/AddDialog.tsx b/src/pages/master/wallet/blocks/AddDialog.tsx index a0cafb3..90ad6ba 100644 --- a/src/pages/master/wallet/blocks/AddDialog.tsx +++ b/src/pages/master/wallet/blocks/AddDialog.tsx @@ -23,6 +23,7 @@ import { import { Button } from '@/components/ui/button'; import { Checkbox } from '@/components/ui/checkbox'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface CurrencyProps { ID: string; @@ -64,6 +65,7 @@ const AddDialog = () => { id_currency: '' }; const [formField, setFormField] = useState(initialState); + const [isSubmitting, setIsSubmitting] = useState(false); const [currencies, setCurrencies] = useState([]); const [groups, setGroups] = useState([]); @@ -95,24 +97,31 @@ const AddDialog = () => { const doCreateWallet = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PostData(`${API_URL_MASTER_DATA}/wallet/create`, formField); + try { + const response = await PostData(`${API_URL_MASTER_DATA}/wallet/create`, formField); - if (response?.status) { - handleAddDialog(false); - toast.success('Success Create Wallet'); - reload(); + if (response?.status) { + handleAddDialog(false); + toast.success('Success Create Wallet'); + reload(); - const createActivity = { - module: 'Manage Wallet', - description: `Create Wallet => ${formField.name}`, - action: 'C' - }; + const createActivity = { + module: 'Manage Wallet', + description: `Create Wallet => ${formField.name}`, + action: 'C' + }; - doSaveLogActivity(createActivity); - } else { - toast.error('Failed Create Wallet'); - setAlert({ show: true, message: 'Failed Create Wallet' }); + doSaveLogActivity(createActivity); + } else { + toast.error('Failed Create Wallet'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -293,7 +302,13 @@ const AddDialog = () => { - + diff --git a/src/pages/master/wallet/blocks/EditDialog.tsx b/src/pages/master/wallet/blocks/EditDialog.tsx index ffcc1e5..f7590ac 100644 --- a/src/pages/master/wallet/blocks/EditDialog.tsx +++ b/src/pages/master/wallet/blocks/EditDialog.tsx @@ -22,6 +22,7 @@ import { } from '@/components/ui/select'; import { Button } from '@/components/ui/button'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface CurrencyProps { ID: string; @@ -66,6 +67,7 @@ const EditDialog = () => { const [formField, setFormField] = useState(initialState); const [currencies, setCurrencies] = useState([]); const [groups, setGroups] = useState([]); + const [isSubmitting, setIsSubmitting] = useState(false); const resetForm = () => { setFormField(initialState); @@ -75,27 +77,34 @@ const EditDialog = () => { const doUpdateWallet = useCallback( async (payload: { name: string; description: string; status: string }) => { // e.preventDefault(); + setIsSubmitting(true); - const response = await PutData( - `${API_URL_MASTER_DATA}/wallet/update/${selectedWallet?.id}`, - payload - ); + try { + const response = await PutData( + `${API_URL_MASTER_DATA}/wallet/update/${selectedWallet?.id}`, + payload + ); - if (response?.status) { - handleEditDialog(false, null); - toast.success('Success Update Wallet'); - reload(); + if (response?.status) { + handleEditDialog(false, null); + toast.success('Success Update Wallet'); + reload(); - const createActivity = { - module: 'Manage Wallet', - description: `Edit Wallet => ${selectedWallet?.id} - ${selectedWallet?.name}`, - action: 'U' - }; + const createActivity = { + module: 'Manage Wallet', + description: `Edit Wallet => ${selectedWallet?.id} - ${selectedWallet?.name}`, + action: 'U' + }; - doSaveLogActivity(createActivity); - } else { - toast.error('Failed Update Wallet'); - setAlert({ show: true, message: 'Failed Update Wallet' }); + doSaveLogActivity(createActivity); + } else { + toast.error('Failed Update Wallet'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -314,8 +323,12 @@ const EditDialog = () => {
-
diff --git a/src/pages/master/walletRule/blocks/AddDialog.tsx b/src/pages/master/walletRule/blocks/AddDialog.tsx index 043f766..4995c45 100644 --- a/src/pages/master/walletRule/blocks/AddDialog.tsx +++ b/src/pages/master/walletRule/blocks/AddDialog.tsx @@ -32,6 +32,7 @@ import { } from '@/components/ui/command'; import { NumericFormat } from 'react-number-format'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface GroupProps { ID: string; @@ -88,6 +89,7 @@ const AddDialog = () => { }; const [formField, setFormField] = useState(initialState); const [wallets, setWallets] = useState([]); + const [isSubmitting, setIsSubmitting] = useState(false); const resetForm = () => { setFormField(initialState); @@ -97,24 +99,31 @@ const AddDialog = () => { const doCreateWalletRule = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PostData(`${API_URL_WALLET}/dashboard/wallet_rule`, formField); + try { + const response = await PostData(`${API_URL_WALLET}/dashboard/wallet_rule`, formField); - if (response?.status) { - handleAddDialog(false); - toast.success('Success Create Wallet Rule'); - reload(); + if (response?.status) { + handleAddDialog(false); + toast.success('Success Create Wallet Rule'); + reload(); - const createActivity = { - module: 'Manage Wallet Rule', - description: `Create Wallet Rule => ${selectedWalletRule?.ID}`, - action: 'C' - }; + const createActivity = { + module: 'Manage Wallet Rule', + description: `Create Wallet Rule => ${selectedWalletRule?.ID}`, + action: 'C' + }; - doSaveLogActivity(createActivity); - } else { - toast.error('Failed Create Wallet Rule'); - setAlert({ show: true, message: 'Failed Create Wallet Rule' }); + doSaveLogActivity(createActivity); + } else { + toast.error('Failed Create Wallet Rule'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -377,7 +386,13 @@ const AddDialog = () => { - + diff --git a/src/pages/master/walletRule/blocks/EditDialog.tsx b/src/pages/master/walletRule/blocks/EditDialog.tsx index 9c5a132..166225b 100644 --- a/src/pages/master/walletRule/blocks/EditDialog.tsx +++ b/src/pages/master/walletRule/blocks/EditDialog.tsx @@ -32,6 +32,7 @@ import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { NumericFormat } from 'react-number-format'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; interface GroupProps { ID: string; @@ -79,6 +80,7 @@ const EditDialog = () => { const [formField, setFormField] = useState(initialState); const [groups, setGroups] = useState([]); const [wallets, setWallets] = useState([]); + const [isSubmitting, setIsSubmitting] = useState(false); const resetForm = () => { setFormField(initialState); @@ -88,27 +90,34 @@ const EditDialog = () => { const doUpdateWalletRule = useCallback( async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); - const response = await PutData( - `${API_URL_WALLET}/dashboard/wallet_rule/${selectedWalletRule?.ID}`, - formField - ); + try { + const response = await PutData( + `${API_URL_WALLET}/dashboard/wallet_rule/${selectedWalletRule?.ID}`, + formField + ); - if (response?.status) { - handleEditDialog(false, null); - toast.success('Success Update Wallet Rule'); - reload(); + if (response?.status) { + handleEditDialog(false, null); + toast.success('Success Update Wallet Rule'); + reload(); - const createActivity = { - module: 'Manage Wallet Rule', - description: `Edit Wallet Rule => ${selectedWalletRule?.ID}`, - action: 'U' - }; + const createActivity = { + module: 'Manage Wallet Rule', + description: `Edit Wallet Rule => ${selectedWalletRule?.ID}`, + action: 'U' + }; - doSaveLogActivity(createActivity); - } else { - toast.error('Failed Update Wallet Rule'); - setAlert({ show: true, message: 'Failed Update Wallet Rule' }); + doSaveLogActivity(createActivity); + } else { + toast.error('Failed Update Wallet Rule'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again'); + } finally { + setIsSubmitting(false); } }, [formField] @@ -402,7 +411,13 @@ const EditDialog = () => {
- +
diff --git a/src/pages/menu/manage-menu/blocks/AddDIalog.tsx b/src/pages/menu/manage-menu/blocks/AddDIalog.tsx index d7c2f2f..43b6aae 100644 --- a/src/pages/menu/manage-menu/blocks/AddDIalog.tsx +++ b/src/pages/menu/manage-menu/blocks/AddDIalog.tsx @@ -22,6 +22,7 @@ import { SelectValue } from '@/components/ui/select'; import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; const API_URL = apiConfig.service_dashboard; const AddDialog = () => { @@ -43,9 +44,11 @@ const AddDialog = () => { status: '' }; const [formField, setFormField] = useState(initialState); + const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); if ( formField.module === '' || @@ -58,28 +61,31 @@ const AddDialog = () => { return; } - // console.log('Data dikirim ke API:', formField); - const response = await PostData(`${API_URL}/menus/create`, formField); + try { + const response = await PostData(`${API_URL}/menus/create`, formField); - // console.log('Response from API:', response); + if (response?.status) { + handleAddDialog(false); + resetForm(); + toast.success('Success Create Menu'); + const createActivity = { + module: 'Manage Menu', + description: `Create Menu => ${selectedMenu}`, + action: 'C' + }; - if (response?.status) { - handleAddDialog(false); - resetForm(); - toast.success('Success Create Menu'); - const createActivity = { - module: 'Manage Menu', - description: `Create Menu => ${selectedMenu}`, - action: 'C' - }; - - doSaveLogActivity(createActivity); - reload(); - } else { - toast.error('Failed Create Menu'); - setAlert({ show: true, message: 'Failed Create Menu' }); + doSaveLogActivity(createActivity); + reload(); + } else { + toast.error('Failed Create Menu'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please try again'); + } finally { + setIsSubmitting(false); } - // console.log(formField); + setAlert({ show: false, message: '' }); }; @@ -226,7 +232,13 @@ const AddDialog = () => { - + diff --git a/src/pages/menu/manage-menu/blocks/EditDialog.tsx b/src/pages/menu/manage-menu/blocks/EditDialog.tsx index e55c6bc..92c2f61 100644 --- a/src/pages/menu/manage-menu/blocks/EditDialog.tsx +++ b/src/pages/menu/manage-menu/blocks/EditDialog.tsx @@ -32,6 +32,7 @@ const EditDialog = () => { const { reload } = useDataGrid(); const { PutData } = useCallApi(); const [open, setOpen] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const [alert, setAlert] = useState({ show: false, message: '' @@ -49,6 +50,7 @@ const EditDialog = () => { const handleUpdate = async (e: React.FormEvent) => { e.preventDefault(); + setIsSubmitting(true); if ( selectedMenu.module === '' || @@ -62,26 +64,33 @@ const EditDialog = () => { return; } - const updateMenu = selectedMenu; - if (updateMenu.id_parent === null) updateMenu.id_parent = ''; - delete updateMenu.parentName; - const response = await PutData(`${API_URL}/menus/update/${selectedMenu.id}`, selectedMenu); - if (response?.status) { - handleEditDialog(false, null); - resetForm(); - toast.success('Success Update Menu'); - const createActivity = { - module: 'Manage Menu', - description: `Update Menu => ${selectedMenu.name}`, - action: 'U' - }; + try { + const updateMenu = selectedMenu; + if (updateMenu.id_parent === null) updateMenu.id_parent = ''; + delete updateMenu.parentName; + const response = await PutData(`${API_URL}/menus/update/${selectedMenu.id}`, selectedMenu); + if (response?.status) { + handleEditDialog(false, null); + resetForm(); + toast.success('Success Update Menu'); + const createActivity = { + module: 'Manage Menu', + description: `Update Menu => ${selectedMenu.name}`, + action: 'U' + }; - doSaveLogActivity(createActivity); - reload(); - } else { - toast.error('Failed Update Menu'); - setAlert({ show: true, message: 'Failed Update Menu' }); + doSaveLogActivity(createActivity); + reload(); + } else { + toast.error('Failed Update Menu'); + setAlert({ show: true, message: response?.message }); + } + } catch (error) { + toast.error('Something went wrong, please trt again.'); + } finally { + setIsSubmitting(false); } + setAlert({ show: false, message: '' }); };