Files
user-front/src/middlewares/Deadline.jsx
AmirHossein Mahmoodi b8019eb4c0 fixed fucking bug
2024-01-06 14:03:30 +03:30

41 lines
1.5 KiB
JavaScript

import {CenterLayout, FullPageLayout, useConfig} from "@witel/webapp-builder";
import moment from "jalali-moment";
import SvgMaintenance from "@/core/components/svgs/SvgMaintenance";
import {Typography} from "@mui/material";
const DeadlineMiddleware = ({children, type = '', withMessage = false, serverToday}) => {
const {config} = useConfig()
const middleware = config.deadlines[type]
if (!middleware) return children
const fromDate = moment(middleware.date.from, 'jYYYY/jMM/jDD')
const toDate = moment(middleware.date.to, 'jYYYY/jMM/jDD')
const today = moment(serverToday)
if (today.isBetween(fromDate, toDate, null, '[]')) {
return children
} else if (today.isAfter(toDate, null)) {
if (!withMessage) return
return (
<FullPageLayout>
<CenterLayout spacing={3}>
<SvgMaintenance height={200} width={200}/>
<Typography>{middleware.messages.after || ''}</Typography>
</CenterLayout>
</FullPageLayout>
)
} else if (today.isBefore(fromDate, null)) {
if (!withMessage) return
return (
<FullPageLayout>
<CenterLayout spacing={3}>
<SvgMaintenance height={200} width={200}/>
<Typography>{middleware.messages.before || ''}</Typography>
</CenterLayout>
</FullPageLayout>
)
}
}
export default DeadlineMiddleware