update bugs fix medicine, user record update-delete, user login
This commit is contained in:
@@ -81,17 +81,19 @@ type AuthProviderProps = {
|
||||
function AuthProvider({ children }: AuthProviderProps) {
|
||||
const [state, dispatch] = useReducer(JWTReducer, initialState);
|
||||
let location = useLocation();
|
||||
const accessToken = getSession();
|
||||
|
||||
useEffect(() => {
|
||||
const initialize = async () => {
|
||||
(async () => {
|
||||
try {
|
||||
const accessToken = getSession();
|
||||
// const accessToken = getSession();
|
||||
|
||||
if (accessToken) {
|
||||
setSession(accessToken);
|
||||
|
||||
const response = await axios.get('/user');
|
||||
const user = response.data;
|
||||
|
||||
|
||||
dispatch({
|
||||
type: Types.Initial,
|
||||
payload: {
|
||||
@@ -117,11 +119,10 @@ function AuthProvider({ children }: AuthProviderProps) {
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
initialize();
|
||||
}, []);
|
||||
})();
|
||||
}, [accessToken]);
|
||||
|
||||
|
||||
const login = async (email: string, password: string) => axios
|
||||
.post('/login', { email, password })
|
||||
.then((response) => {
|
||||
|
||||
@@ -30,8 +30,9 @@ const MENU_OPTIONS = [
|
||||
export default function AccountPopover() {
|
||||
const [open, setOpen] = useState<HTMLElement | null>(null);
|
||||
const navigate = useNavigate();
|
||||
const { logout } = useAuth();
|
||||
const { logout, user } = useAuth();
|
||||
|
||||
console.log(user?.email)
|
||||
const handleOpen = (event: React.MouseEvent<HTMLElement>) => {
|
||||
setOpen(event.currentTarget);
|
||||
};
|
||||
@@ -65,7 +66,7 @@ export default function AccountPopover() {
|
||||
}}
|
||||
>
|
||||
<Avatar
|
||||
src="https://minimal-assets-api.vercel.app/assets/images/avatars/avatar_5.jpg"
|
||||
src="https://linksehat.com/assets/img/users/dummy.jpg"
|
||||
alt="Rayan Moran"
|
||||
/>
|
||||
</IconButtonAnimate>
|
||||
@@ -86,10 +87,10 @@ export default function AccountPopover() {
|
||||
>
|
||||
<Box sx={{ my: 1.5, px: 2.5 }}>
|
||||
<Typography variant="subtitle2" noWrap>
|
||||
Rayan Moran
|
||||
{user?.full_name ? user?.full_name : ''}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ color: 'text.secondary' }} noWrap>
|
||||
rayan.moran@gmail.com
|
||||
{user?.email}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
|
||||
@@ -92,9 +92,9 @@ export default function DashboardHeader({
|
||||
<Box sx={{ flexGrow: 1 }} />
|
||||
|
||||
<Stack direction="row" alignItems="center" spacing={{ xs: 0.5, sm: 1.5 }}>
|
||||
<LanguagePopover />
|
||||
{/* <LanguagePopover />
|
||||
<NotificationsPopover />
|
||||
<ContactsPopover />
|
||||
<ContactsPopover /> */}
|
||||
<AccountPopover />
|
||||
</Stack>
|
||||
</Toolbar>
|
||||
|
||||
@@ -108,7 +108,10 @@ const navConfig = [
|
||||
},
|
||||
{
|
||||
title: 'USER MANAGEMENT',
|
||||
path: '/users',
|
||||
children: [
|
||||
{ title: 'User Access', path: '/master/diagnosis' },
|
||||
{ title: 'User Role', path: '/master/diagnosis' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'LINKING TOOLS',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// @mui
|
||||
import { styled } from '@mui/material/styles';
|
||||
import { Box, Link, Typography, Avatar } from '@mui/material';
|
||||
import useAuth from '../../../hooks/useAuth';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -22,6 +23,8 @@ type Props = {
|
||||
};
|
||||
|
||||
export default function NavbarAccount({ isCollapse }: Props) {
|
||||
|
||||
const { logout, user } = useAuth();
|
||||
return (
|
||||
<Link underline="none" color="inherit">
|
||||
<RootStyle
|
||||
@@ -32,7 +35,7 @@ export default function NavbarAccount({ isCollapse }: Props) {
|
||||
}}
|
||||
>
|
||||
<Avatar
|
||||
src="https://minimal-assets-api.vercel.app/assets/images/avatars/avatar_5.jpg"
|
||||
src="https://linksehat.com/assets/img/users/dummy.jpg"
|
||||
alt="Rayan Moran"
|
||||
/>
|
||||
|
||||
@@ -50,10 +53,10 @@ export default function NavbarAccount({ isCollapse }: Props) {
|
||||
}}
|
||||
>
|
||||
<Typography variant="subtitle2" noWrap>
|
||||
Rayan Moran
|
||||
|
||||
</Typography>
|
||||
<Typography variant="body2" noWrap sx={{ color: 'text.secondary' }}>
|
||||
user
|
||||
Hi {user?.full_name}
|
||||
</Typography>
|
||||
</Box>
|
||||
</RootStyle>
|
||||
|
||||
@@ -16,7 +16,7 @@ import { fNumber } from "@/utils/formatNumber";
|
||||
import palette from "@/theme/palette";
|
||||
import DialogBenefit from "../FinalLog/Components/DialogBenefit";
|
||||
import DialogEditBenefit from "../FinalLog/Components/DialogEditBenefit";
|
||||
import DialogDelete from "../FinalLog/Components/DialogDelete";
|
||||
import DialogDeleteBenefit from "../FinalLog/Components/DialogDeleteBenefit";
|
||||
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ export default function CardBenefit({requestLog} : CardDetail ) {
|
||||
|
||||
</DialogEditBenefit>
|
||||
{/* Dialog Delete */}
|
||||
<DialogDelete
|
||||
<DialogDeleteBenefit
|
||||
id={idBenefitData}
|
||||
openDialog={openDialogDeleteBenefit}
|
||||
setOpenDialog={setDialogDeleteBenefit}
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function CardFile({requestLog} : CardDetail ) {
|
||||
<Card sx={{padding:2}} >
|
||||
<Stack direction="row" alignItems="center" sx={{marginBottom: 4}}>
|
||||
<Stack direction="column" spacing={2} sx={{marginBottom: 2}}>
|
||||
<Typography variant='subtitle1' sx={{color: '#19BBBB'}} gutterBottom>Files History</Typography>
|
||||
<Typography variant='subtitle1' sx={{color: '#19BBBB'}} gutterBottom>Files </Typography>
|
||||
{requestLog?.files?.map((documentType, index) => (
|
||||
<Stack direction="column" spacing={2} key={index}>
|
||||
<Stack direction="row" spacing={1} sx={{color: '#19BBBB'}}>
|
||||
|
||||
@@ -17,7 +17,7 @@ type DialogDeleteType = {
|
||||
id: number|undefined;
|
||||
}
|
||||
|
||||
export default function DialogDelete({id, setOpenDialog, openDialog,onSubmit} : DialogDeleteType ) {
|
||||
export default function DialogDeleteBenefit({id, setOpenDialog, openDialog,onSubmit} : DialogDeleteType ) {
|
||||
const handleSubmit = () => {
|
||||
axios
|
||||
.delete(`customer-service/request/benefit_data/${id}`)
|
||||
@@ -67,54 +67,3 @@ export default function DialogDelete({id, setOpenDialog, openDialog,onSubmit} :
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function DialogDeleteMedicine({id, setOpenDialog, openDialog,onSubmit} : DialogDeleteType ) {
|
||||
const handleSubmit = () => {
|
||||
axios
|
||||
.delete(`customer-service/request/medicine-data/${id}`)
|
||||
.then((response) => {
|
||||
enqueueSnackbar('Benefit Data has Deleted', { variant: 'success' });
|
||||
setOpenDialog(false);
|
||||
window.location.reload()
|
||||
})
|
||||
.catch(({ response }) => {
|
||||
enqueueSnackbar(response.data.message ?? 'Something went wrong!', { variant: 'error' });
|
||||
});
|
||||
}
|
||||
|
||||
const style1 = {
|
||||
color: '#919EAB',
|
||||
width: '30%'
|
||||
}
|
||||
const style2 = {
|
||||
width: '70%'
|
||||
}
|
||||
const marginBottom1 = {
|
||||
marginBottom: 1,
|
||||
}
|
||||
|
||||
const handleCloseDialog = () => {
|
||||
setOpenDialog(false);
|
||||
}
|
||||
|
||||
const getContent = () => (
|
||||
<Stack spacing={1} marginTop={2}>
|
||||
<Typography variant="subtitle2">Are you sure to delete this detail medicine ?</Typography>
|
||||
<DialogActions>
|
||||
<Button variant="outlined" sx={{color: '#212B36', borderColor: '#919EAB52'}} onClick={handleCloseDialog}>Cancel</Button>
|
||||
<Button color="error" variant="contained" onClick={handleSubmit}>Delete</Button>
|
||||
</DialogActions>
|
||||
</Stack>
|
||||
);
|
||||
|
||||
|
||||
return (
|
||||
<MuiDialog
|
||||
title={{name: "Delete Medicine"}}
|
||||
openDialog={openDialog}
|
||||
setOpenDialog={setOpenDialog}
|
||||
content={getContent()}
|
||||
maxWidth="xs"
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ export default function DialogDeleteMedicine({id, setOpenDialog, openDialog,onSu
|
||||
axios
|
||||
.delete(`customer-service/request/medicine-data/${id}`)
|
||||
.then((response) => {
|
||||
enqueueSnackbar('Benefit Data has Deleted', { variant: 'success' });
|
||||
enqueueSnackbar('Medicine Data has Deleted', { variant: 'success' });
|
||||
setOpenDialog(false);
|
||||
window.location.reload()
|
||||
})
|
||||
|
||||
@@ -44,9 +44,9 @@ import CardBenefit from '../Components/CardBenefit';
|
||||
import DialogHospitalCare from './Components/DialogHospitalCare';
|
||||
import DialogBenefit from './Components/DialogBenefit';
|
||||
import DialogMedicine from './Components/DialogMedicine';
|
||||
import DialogDelete from './Components/DialogDelete';
|
||||
import DialogDeleteBenfit from './Components/DialogDeleteBenefit';
|
||||
import DialogEditBenefit from './Components/DialogEditBenefit';
|
||||
import { DialogDeleteMedicine } from './Components/DialogDelete';
|
||||
import DialogDeleteMedicine from './Components/DialogDeleteMedicine'
|
||||
|
||||
import MoreMenu from '@/components/MoreMenu';
|
||||
import { MenuItem } from '@mui/material';
|
||||
@@ -102,6 +102,9 @@ export default function Detail() {
|
||||
// Handel Delete Detail Benefit
|
||||
const [idBenefitData, setIdBenefitData] = useState<number>();
|
||||
const [openDialogDeleteBenefit, setDialogDeleteBenefit] = useState(false)
|
||||
|
||||
const [idMedicineData, setIdMedicineData] = useState<number>();
|
||||
const [openDialogDeleteMedicine, setDialogDeleteMedicine] = useState(false)
|
||||
|
||||
const [approve, setApprove] = useState('')
|
||||
|
||||
@@ -327,7 +330,7 @@ export default function Detail() {
|
||||
|
||||
</DialogEditBenefit>
|
||||
{/* Dialog Delete */}
|
||||
<DialogDelete
|
||||
<DialogDeleteBenfit
|
||||
id={idBenefitData}
|
||||
openDialog={openDialogDeleteBenefit}
|
||||
setOpenDialog={setDialogDeleteBenefit}
|
||||
@@ -357,8 +360,8 @@ export default function Detail() {
|
||||
<Typography variant='subtitle1'>{item.medicine}</Typography>
|
||||
<Typography variant="subtitle1">Rp. {fNumber(item.price)}
|
||||
<IconButton size='large' color='error' onClick={() => {
|
||||
setIdBenefitData(item.id)
|
||||
setDialogDeleteBenefit(true)
|
||||
setIdMedicineData(item.id)
|
||||
setDialogDeleteMedicine(true)
|
||||
}}>
|
||||
<Delete color='error'/>
|
||||
</IconButton>
|
||||
@@ -371,10 +374,10 @@ export default function Detail() {
|
||||
openDialog={openDialogMedicine}
|
||||
setOpenDialog={setDialogMedicine}
|
||||
/>
|
||||
<DialogDeleteMedicine
|
||||
id={idBenefitData}
|
||||
openDialog={openDialogDeleteBenefit}
|
||||
setOpenDialog={setDialogDeleteBenefit}
|
||||
<DialogDeleteMedicine
|
||||
id={idMedicineData}
|
||||
openDialog={openDialogDeleteMedicine}
|
||||
setOpenDialog={setDialogDeleteMedicine}
|
||||
/>
|
||||
</Card>
|
||||
</Grid>
|
||||
|
||||
@@ -34,19 +34,19 @@ export default function LoginForm() {
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
|
||||
const LoginSchema = Yup.object().shape({
|
||||
email: Yup.string().email('Email must be a valid email address').required('Email is required'),
|
||||
email: Yup.string().required('Email is required'),
|
||||
password: Yup.string().required('Password is required'),
|
||||
});
|
||||
|
||||
const defaultValues = {
|
||||
email: 'admin@linksehat.dev',
|
||||
password: 'password',
|
||||
email: '',
|
||||
password: '',
|
||||
remember: true,
|
||||
};
|
||||
|
||||
const methods = useForm<FormValuesProps>({
|
||||
resolver: yupResolver(LoginSchema),
|
||||
defaultValues,
|
||||
// defaultValues,
|
||||
});
|
||||
|
||||
const {
|
||||
@@ -75,10 +75,10 @@ export default function LoginForm() {
|
||||
return (
|
||||
<FormProvider methods={methods} onSubmit={handleSubmit(onSubmit)}>
|
||||
<Stack spacing={3}>
|
||||
<Alert severity="info">Email : admin@linksehat.dev & Password : password</Alert>
|
||||
<Alert severity="info">Masukan Email atau Username dan Password</Alert>
|
||||
{!!errors.afterSubmit && <Alert severity="error">{errors.afterSubmit.message}</Alert>}
|
||||
|
||||
<RHFTextField name="email" label="Email address" />
|
||||
<RHFTextField name="email" label="Email Or Username" />
|
||||
|
||||
<RHFTextField
|
||||
name="password"
|
||||
|
||||
Reference in New Issue
Block a user