add loading when post/put data on master data module

This commit is contained in:
Wikzyy
2025-04-23 13:35:32 +07:00
parent e248c463c9
commit 94ffc332e9
26 changed files with 838 additions and 454 deletions

View File

@ -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<HTMLFormElement>) => {
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 = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<HTMLFormElement>) => {
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 = () => {
</div>
<div className="flex justify-end">
<Button className="btn btn-primary">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<HTMLFormElement>) => {
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 = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<CurrencyProps[]>([]);
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<HTMLFormElement>) => {
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 = () => {
</div>
</div>
<div className="flex justify-end gap-5">
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<CurrencyProps[]>([]);
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<HTMLFormElement>) => {
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 = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<CurrencyProps[]>([]);
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<HTMLFormElement>) => {
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 = () => {
</div>
<div className="flex justify-end gap-5">
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<HTMLFormElement>) => {
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 = () => {
<Button variant={'outline'} type="reset" onClick={handleReset}>
Reset
</Button>
<Button variant={'default'} type="submit">
Create
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>

View File

@ -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<HTMLFormElement>) => {
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 = () => {
</div>
<div className="flex justify-end pt-2.5">
<Button className="btn btn-primary">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<MunicipioProps[]>([]);
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<HTMLFormElement>) => {
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 = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<MunicipioProps[]>([]);
const [isSubmitting, setIsSubmitting] = useState(false);
const [alert, setAlert] = useState({
show: false,
@ -66,28 +68,38 @@ const EditDialog = () => {
const doUpdatePostoAdm = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
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 = () => {
</div>
<div className="flex justify-end gap-5">
<Button className="btn btn-primary">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<ProviderProps[]>([]);
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<HTMLFormElement>) => {
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 = () => {
<div className="w-full">
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label className="form-label flex items-center gap-1 max-w-56">
Provider
</label>
<label className="form-label flex items-center gap-1 max-w-56">Provider</label>
<Select
value={formField.provider}
onValueChange={(value) =>
@ -408,7 +415,13 @@ const AddDialog = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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: string;
@ -37,6 +38,7 @@ const EditDialog = () => {
const { PutData, GetData } = useCallApi();
const parsedUser = getAuth()?.user;
const [isLoading, setIsLoading] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const created_time = new Date();
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
const [alert, setAlert] = useState({
@ -83,25 +85,32 @@ const EditDialog = () => {
const doUpdateProduct = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setIsSubmitting(true);
const response = await PutData(`${API_URL}/product/update/${selectedProducts}`, formField);
try {
const response = await PutData(`${API_URL}/product/update/${selectedProducts}`, formField);
if (response?.status) {
resetForm();
handleEditDialog(false, null);
toast.success('Product updated successfully.');
reload();
if (response?.status) {
resetForm();
handleEditDialog(false, null);
toast.success('Product updated successfully.');
reload();
const createActivity = {
module: 'Manage Products',
description: `Edit Product => ${selectedProducts}`,
action: 'U'
};
const createActivity = {
module: 'Manage Products',
description: `Edit Product => ${selectedProducts}`,
action: 'U'
};
doSaveLogActivity(createActivity);
} else {
toast.error('Failed to update Product. Please try again.');
setAlert({ show: true, message: 'Failed to update Product. Please try again.' });
doSaveLogActivity(createActivity);
} else {
toast.error('Failed to update Product. Please try again.');
setAlert({ show: true, message: response?.message });
}
} catch (error) {
toast.error('Something went wrong. Please try again.');
} finally {
setIsSubmitting(false);
}
},
[selectedProducts, formField]
@ -449,7 +458,13 @@ const EditDialog = () => {
</div>
<div className="flex justify-end gap-5">
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -16,6 +16,7 @@ import {
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { doSaveLogActivity } from '@/actions/GlobalActions';
import { RefreshCw } from 'lucide-react';
const API_URL = apiConfig.service_master_data;
const AddDialog = () => {
@ -35,6 +36,7 @@ const AddDialog = () => {
created_at: ''
};
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', ' ');
@ -46,25 +48,32 @@ const AddDialog = () => {
const doCreateProfession = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setIsSubmitting(true);
const response = await PostData(`${API_URL}/profession/create`, formField);
try {
const response = await PostData(`${API_URL}/profession/create`, formField);
if (response?.status) {
resetForm();
handleAddDialog(false);
toast.success('Success Create Profession');
reload();
if (response?.status) {
resetForm();
handleAddDialog(false);
toast.success('Success Create Profession');
reload();
const createActivity = {
module: 'Manage Profession',
description: `Create Profession => ${formField.name}`,
action: 'C'
};
const createActivity = {
module: 'Manage Profession',
description: `Create Profession => ${formField.name}`,
action: 'C'
};
doSaveLogActivity(createActivity);
} else {
toast.error('Failed Create Profession');
setAlert({ show: true, message: response?.message });
doSaveLogActivity(createActivity);
} else {
toast.error('Failed Create Profession');
setAlert({ show: true, message: response?.message });
}
} catch (error) {
toast.error('Something went wrong, please try again.');
} finally {
setIsSubmitting(false);
}
},
[formField]
@ -134,7 +143,13 @@ const AddDialog = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Create</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -16,6 +16,7 @@ import {
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { doSaveLogActivity } from '@/actions/GlobalActions';
import { RefreshCw } from 'lucide-react';
const API_URL = apiConfig.service_master_data;
const EditDialog = () => {
@ -24,6 +25,7 @@ const EditDialog = () => {
const { PutData, GetData } = useCallApi();
const parsedUser = getAuth()?.user;
const [isLoading, setIsLoading] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const created_time = new Date();
const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' ');
const [alert, setAlert] = useState({
@ -45,28 +47,35 @@ const EditDialog = () => {
const doUpdateProfession = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setIsSubmitting(true);
const response = await PutData(
`${API_URL}/profession/update/${selectedProfession}`,
formField
);
try {
const response = await PutData(
`${API_URL}/profession/update/${selectedProfession}`,
formField
);
if (response?.status) {
resetForm();
handleEditDialog(false, null);
toast.success('Success Update Profession');
reload();
if (response?.status) {
resetForm();
handleEditDialog(false, null);
toast.success('Success Update Profession');
reload();
const createActivity = {
module: 'Manage Profession',
description: `Edit Profession => ${selectedProfession}`,
action: 'U'
};
const createActivity = {
module: 'Manage Profession',
description: `Edit Profession => ${selectedProfession}`,
action: 'U'
};
doSaveLogActivity(createActivity);
} else {
toast.error('Failed Update Profession');
setAlert({ show: true, message: 'Failed Update Profession' });
doSaveLogActivity(createActivity);
} else {
toast.error('Failed Update Profession');
setAlert({ show: true, message: response?.message });
}
} catch (error) {
toast.error('Something went wrong, please try again.');
} finally {
setIsSubmitting(false);
}
},
[selectedProfession, formField]
@ -170,7 +179,13 @@ const EditDialog = () => {
</div>
<div className="flex justify-end">
<Button className="btn btn-primary">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -32,6 +32,7 @@ import {
CommandList
} from '@/components/ui/command';
import { doSaveLogActivity } from '@/actions/GlobalActions';
import { RefreshCw } from 'lucide-react';
export interface CustomerProps {
id: string;
@ -57,6 +58,7 @@ const AddDialog = () => {
const parentRef = useRef<any | null>(null);
const parsedUser = getAuth()?.user;
const [open, setOpen] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const [alert, setAlert] = useState({
show: false,
message: ''
@ -96,24 +98,31 @@ const AddDialog = () => {
const doCreateProvider = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setIsSubmitting(true);
const response = await PostData(`${API_URL_MASTERDATA}/provider/create`, formField);
try {
const response = await PostData(`${API_URL_MASTERDATA}/provider/create`, formField);
if (response?.status) {
resetForm();
handleAddDialog(false);
toast.success('Success Create Provider');
const createActivity = {
module: 'Manage Provider',
description: `Create Provider => ${formField.name}`,
action: 'C'
};
if (response?.status) {
resetForm();
handleAddDialog(false);
toast.success('Success Create Provider');
const createActivity = {
module: 'Manage Provider',
description: `Create Provider => ${formField.name}`,
action: 'C'
};
doSaveLogActivity(createActivity);
reload();
} else {
toast.error('Failed Create Provider');
setAlert({ show: true, message: 'Failed Create Provider' });
doSaveLogActivity(createActivity);
reload();
} else {
toast.error('Failed Create Provider');
setAlert({ show: true, message: response?.message });
}
} catch (error) {
toast.error('Something went wrong, please try again.');
} finally {
setIsSubmitting(false);
}
},
[formField]
@ -361,7 +370,12 @@ const AddDialog = () => {
<label className="form-label flex items-center gap-1 max-w-56">
Agent Name
</label>
<Input type="text" placeholder="Type Agent Only" readOnly className='cursor-not-allowed' />
<Input
type="text"
placeholder="Type Agent Only"
readOnly
className="cursor-not-allowed"
/>
</div>
</div>
)}
@ -370,7 +384,13 @@ const AddDialog = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Create</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<TransactionProps[]>([]);
const [customers, setCustomers] = useState<CustomerProps[]>([]);
const [isSubmitting, setIsSubmitting] = useState(false);
const resetForm = () => {
setFormField(initialState);
@ -85,27 +87,34 @@ const EditDialog = () => {
const doUpdateProvider = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
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 = () => {
)}
<div className="flex justify-end">
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<HTMLFormElement>) => {
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 = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default" type="submit">
Save Change
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>

View File

@ -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<HTMLFormElement>) => {
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 = () => {
</div>
</div>
<div className="flex justify-end gap-5">
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<PostoAdmsProps[]>([]);
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<HTMLFormElement>) => {
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 = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<PostoAdmsProps[]>([]);
@ -69,24 +71,31 @@ const EditDialog = () => {
const doUpdateSucos = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
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 = () => {
</div>
<div className="flex justify-end gap-5">
<Button className="btn btn-primary">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<CurrencyProps[]>([]);
const [groups, setGroups] = useState<GroupProps[]>([]);
@ -95,24 +97,31 @@ const AddDialog = () => {
const doCreateWallet = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
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 = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Create</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<CurrencyProps[]>([]);
const [groups, setGroups] = useState<GroupProps[]>([]);
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 = () => {
</div>
<div className="flex justify-end gap-5">
<Button variant="default" type="submit">
Update
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>

View File

@ -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<WalletProps[]>([]);
const [isSubmitting, setIsSubmitting] = useState(false);
const resetForm = () => {
setFormField(initialState);
@ -97,24 +99,31 @@ const AddDialog = () => {
const doCreateWalletRule = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
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 = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Create</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<GroupProps[]>([]);
const [wallets, setWallets] = useState<WalletProps[]>([]);
const [isSubmitting, setIsSubmitting] = useState(false);
const resetForm = () => {
setFormField(initialState);
@ -88,27 +90,34 @@ const EditDialog = () => {
const doUpdateWalletRule = useCallback(
async (e: React.FormEvent<HTMLFormElement>) => {
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 = () => {
</div>
<div className="flex justify-end gap-5">
<Button variant="default">Update</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-7" />
) : (
'Save Changes'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<HTMLFormElement>) => {
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 = () => {
<Button type="button" variant="outline" onClick={resetForm}>
Reset
</Button>
<Button variant="default">Save Changes</Button>
<Button variant="default" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<RefreshCw className="animate-spin h-8 w-8 text-white mx-3" />
) : (
'Create'
)}
</Button>
</div>
</div>
</form>

View File

@ -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<HTMLFormElement>) => {
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: '' });
};