diff --git a/src/pages/master/pointiers/PointiersMaster.tsx b/src/pages/master/pointiers/PointiersMaster.tsx new file mode 100644 index 0000000..152c908 --- /dev/null +++ b/src/pages/master/pointiers/PointiersMaster.tsx @@ -0,0 +1,43 @@ +import AddDialog from './blocks/AddDialog'; +import EditDialog from './blocks/EditDialog'; +import DeleteDialog from './blocks/DeleteDialog'; +import { ManagePointiersContextProvider } from './hooks/ManagePointiersContext'; +import { Container, DataGridInner } from '@/components'; +import { Breadcrumbs, Link } from '@mui/material'; +import { Helmet } from 'react-helmet'; + +const PointiersMaster = () => { + return ( + <> + + TPAY | Manage Pointiers + + + +

Pointiers

+ + + Dashboard + + + + Master Data + + + + Manage Pointiers + + +
+ +
+ + + +
+
+ + ); +}; + +export default PointiersMaster; diff --git a/src/pages/master/pointiers/blocks/AddDialog.tsx b/src/pages/master/pointiers/blocks/AddDialog.tsx new file mode 100644 index 0000000..5689a8d --- /dev/null +++ b/src/pages/master/pointiers/blocks/AddDialog.tsx @@ -0,0 +1,243 @@ +import React, { useCallback, useEffect, useRef, useState } from 'react'; +import { + Dialog, + DialogBody, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog'; +import { Alert, KeenIcon, useDataGrid } from '@/components'; +import { Input } from '@/components/ui/input'; +import { Button } from '@/components/ui/button'; +import { apiConfig } from '@/config/api.config'; +import { toast } from 'sonner'; +import { getAuth } from '@/auth'; +import { useCallApi } from '@/hooks'; +import { NumericFormat } from 'react-number-format'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select'; +import { doSaveLogActivity } from '@/actions/GlobalActions'; +import { RefreshCw } from 'lucide-react'; +import { initialStatePointiers, validateFormPointiers } from '../../pointiers/blocks/Types'; +import { Textarea } from '@/components/ui/textarea'; +import { useManagePointiersContext } from '../hooks/useManagePointiersContext'; + +const API_URL = apiConfig.service_master_data; + +const AddDialog = () => { + const parentRef = useRef(null); + const { showAddDialog, handleAddDialog } = useManagePointiersContext(); + const { reload } = useDataGrid(); + const { PostData } = useCallApi(); + const parsedUser = getAuth()?.user; + const [errors, setErrors] = useState>({}); + + const [formField, setFormField] = useState(initialStatePointiers); + const [isSubmitting, setIsSubmitting] = useState(false); + const created_time = new Date(); + const formattedTime = created_time.toISOString().slice(0, 19).replace('T', ' '); + + const resetForm = () => { + setFormField(initialStatePointiers); + setErrors({}); + }; + + const handleChange = (e: React.ChangeEvent) => { + setFormField({ ...formField, [e.target.name]: e.target.value }); + }; + + const doCreatePointiers = useCallback( + async (e: React.FormEvent) => { + e.preventDefault(); + setIsSubmitting(true); + + try { + const response = await PostData(`${API_URL}/pointiers/create`, formField); + + if (response?.status) { + handleAddDialog(false); + resetForm(); + reload(); + toast.success('Pointiers Create successfully!'); + const createActivity = { + module: 'Manage Pointiers', + description: `Create New Pointiers => ${formField.name}`, + action: 'C' + }; + + doSaveLogActivity(createActivity); + } else { + toast.error(response?.message); + } + } catch (error) { + toast.error('Something went wrong, please try again.'); + } finally { + setIsSubmitting(false); + } + }, + [formField] + ); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + + if (!validateFormPointiers(formField, setErrors)) { + return; + } + + doCreatePointiers(e); + }; + + useEffect(() => { + if (showAddDialog) { + setFormField((prev) => ({ + ...prev, + created_by: parsedUser?.username, + created_at: formattedTime + })); + } + }, [showAddDialog, parsedUser?.username, formattedTime]); + + useEffect(() => { + if (showAddDialog === false) { + resetForm(); + } + }, [showAddDialog]); + + return ( + + + + Pointiers - Create + + + +
+
+
+ {/* Pointiers Name */} +
+ + { + setFormField((prev) => ({ ...prev, name: target.value })); + setErrors((prev) => ({ ...prev, name: '' })); + }} + /> + {errors.name && ( + + {errors.name} + + )} +
+ + {/* Description */} +
+ +