login validate

This commit is contained in:
Muhammad Fajar
2022-11-14 13:50:10 +07:00
parent 20944e4992
commit 6eb225026a
21 changed files with 633 additions and 714 deletions

View File

@@ -1,15 +1,14 @@
import * as Yup from 'yup';
import { yupResolver } from "@hookform/resolvers/yup";
import { Card, Collapse, Divider, Grid, Stack, Typography } from "@mui/material";
import { useForm } from "react-hook-form";
import { useParams } from "react-router-dom";
import HeaderBreadcrumbs from "../../../components/HeaderBreadcrumbs";
import { FormProvider, RHFCheckbox, RHFSelect, RHFTextField } from "../../../components/hook-form";
import Page from "../../../components/Page";
import useSettings from "../../../hooks/useSettings";
import { yupResolver } from '@hookform/resolvers/yup';
import { Card, Collapse, Divider, Grid, Stack, Typography } from '@mui/material';
import { useForm } from 'react-hook-form';
import { useParams } from 'react-router-dom';
import HeaderBreadcrumbs from '../../components/HeaderBreadcrumbs';
import { FormProvider, RHFCheckbox, RHFSelect, RHFTextField } from '../../components/hook-form';
import Page from '../../components/Page';
import useSettings from '../../hooks/useSettings';
import { useMemo, useState } from 'react';
import Form from "./Form";
import Form from './Form';
export default function Divisions() {
const { themeStretch } = useSettings();
@@ -48,13 +47,12 @@ export default function Divisions() {
} = methods;
const onSubmit = async (data: any) => {
console.log(data)
console.log(data);
};
const pageTitle = 'Create Formularium';
return (
<Page title={pageTitle}>
<HeaderBreadcrumbs
heading={pageTitle}
links={[
@@ -72,12 +70,15 @@ export default function Divisions() {
},
]}
/>
<Grid container spacing={2}>
<Grid item xs={12}>
<Card sx={{ p: 2 }}>
<Form isSubmitting={isSubmitting} isEdit={isEdit} currentFormularium={currentFormularium} />
<Form
isSubmitting={isSubmitting}
isEdit={isEdit}
currentFormularium={currentFormularium}
/>
</Card>
</Grid>
</Grid>

View File

@@ -33,10 +33,10 @@ import {
RHFMultiCheckbox,
RHFCheckbox,
RHFCustomMultiCheckbox,
} from '../../../components/hook-form';
import { Corporate } from '../../../@types/corporates';
import axios from '../../../utils/axios';
import { fCurrency } from '../../../utils/formatNumber';
} from '../../components/hook-form';
import { Corporate } from '../../@types/corporates';
import axios from '../../utils/axios';
import { fCurrency } from '../../utils/formatNumber';
const LabelStyle = styled(Typography)(({ theme }) => ({
...theme.typography.subtitle2,
@@ -110,26 +110,31 @@ export default function FormulariumForm({ isEdit, currentFormularium }: Props) {
if (!isEdit) {
const response = await axios.post('/master/formulariums', data);
} else {
const response = await axios.put('/master/formulariums/' + currentFormularium?.id ?? '', data);
const response = await axios.put(
'/master/formulariums/' + currentFormularium?.id ?? '',
data
);
}
reset();
enqueueSnackbar(!isEdit ? 'Formularium Created Successfully!' : 'Formularium Udpated Successfully!', { variant: 'success' });
enqueueSnackbar(
!isEdit ? 'Formularium Created Successfully!' : 'Formularium Udpated Successfully!',
{ variant: 'success' }
);
navigate('/master/formularium');
} catch (error: any) {
if (error && error.response.status === 422) {
for (const [key, value] of Object.entries(error.response.data.errors)) {
for (const [key, value] of Object.entries(error.response.data.errors)) {
setError(key, { message: value[0] });
enqueueSnackbar(value[0] ?? 'Failed Processing Request', { variant: 'error' });
}
}
else {
} else {
enqueueSnackbar(error.message ?? 'Failed Processing Request', { variant: 'error' });
}
}
const ascent = document?.querySelector("ascent");
const ascent = document?.querySelector('ascent');
if (ascent != null) {
ascent.innerHTML = "";
ascent.innerHTML = '';
}
};
@@ -151,35 +156,34 @@ export default function FormulariumForm({ isEdit, currentFormularium }: Props) {
setValue('logo', null);
};
const linking_rules_checkbox_name = "linking_rules"
const linking_rules_checkbox_name = 'linking_rules';
const linking_tools = [
{
"value" : "nrik",
"label" : "No. KTP"
value: 'nrik',
label: 'No. KTP',
},
{
"value" : "nik",
"label" : "Nomor Induk Karyawan (NIK)"
value: 'nik',
label: 'Nomor Induk Karyawan (NIK)',
},
{
"value" : "member_id",
"label" : "Member ID"
value: 'member_id',
label: 'Member ID',
},
{
"value" : "phone",
"label" : "Nomor Telepon"
value: 'phone',
label: 'Nomor Telepon',
},
{
"value" : "email",
"label" : "E-Mail"
value: 'email',
label: 'E-Mail',
},
]
];
const importForm = useRef<HTMLInputElement>(null)
const importForm = useRef<HTMLInputElement>(null);
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [currentImportFileName, setCurrentImportFileName] = useState<string|null>(null);
const [currentImportFileName, setCurrentImportFileName] = useState<string | null>(null);
const handleClose = () => {
setAnchorEl(null);
};
@@ -189,51 +193,73 @@ export default function FormulariumForm({ isEdit, currentFormularium }: Props) {
handleClose();
importForm.current ? importForm.current.click() : console.log('No File selected');
} else {
alert('No file selected')
alert('No file selected');
}
}
};
const handleCancelImportButton = () => {
importForm.current.value = "";
importForm.current.dispatchEvent(new Event("change", { bubbles: true }));
}
importForm.current.value = '';
importForm.current.dispatchEvent(new Event('change', { bubbles: true }));
};
const handleImportChange = (event: any) => {
if (event.target.files[0]) {
setCurrentImportFileName(event.target.files[0].name)
setCurrentImportFileName(event.target.files[0].name);
} else {
setCurrentImportFileName(null);
}
}
};
return (
<FormProvider methods={methods} onSubmit={handleSubmit(onSubmit)}>
<Stack spacing={3}>
<Typography variant="h6">Formularium Detail</Typography>
<div>
<RHFTextField name="code" label="Code" />
{(!(currentFormularium?.id) && <Typography variant="caption">Will be generated if empty</Typography>)}
<RHFTextField name="code" label="Code" />
{!currentFormularium?.id && (
<Typography variant="caption">Will be generated if empty</Typography>
)}
</div>
<RHFTextField name="name" label="Name" />
<Typography variant="h6">Formularium Drug List Import</Typography>
<input type='file' id='file' ref={importForm} style={{ display: 'none' }} onChange={handleImportChange} accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, text/plain" />
<input
type="file"
id="file"
ref={importForm}
style={{ display: 'none' }}
onChange={handleImportChange}
accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, text/plain"
/>
<ButtonGroup variant="outlined" aria-label="outlined button group" fullWidth>
<Button onClick={handleImportButton} fullWidth>{currentImportFileName ?? "No File Selected"}</Button>
{(currentImportFileName && <Button onClick={handleCancelImportButton} size="small" fullWidth={false} sx={{ p: 1.8 }}><CancelIcon color="error"/></Button>)}
<Button onClick={handleImportButton} fullWidth>
{currentImportFileName ?? 'No File Selected'}
</Button>
{currentImportFileName && (
<Button
onClick={handleCancelImportButton}
size="small"
fullWidth={false}
sx={{ p: 1.8 }}
>
<CancelIcon color="error" />
</Button>
)}
</ButtonGroup>
<LoadingButton type="submit" variant="contained" size="large" fullWidth={true} loading={isSubmitting}>
<LoadingButton
type="submit"
variant="contained"
size="large"
fullWidth={true}
loading={isSubmitting}
>
{!isEdit ? 'Save New Corporate' : 'Save Update'}
</LoadingButton>
</Stack>
</FormProvider>
);
};
}