Merge branch 'dev' of penahub.gitlab.yandexcloud.net:frontend/admin into dev

This commit is contained in:
IlyaDoronin 2024-05-08 15:17:46 +03:00
commit 495278c1e0
8 changed files with 99 additions and 92 deletions

@ -136,7 +136,7 @@ export function usePromocodes(
} }
export function useAllPromocodes() { export function useAllPromocodes() {
const swrResponse = useSwr("allPromocodes", promocodeApi.getAllPromocodes, { const { data } = useSwr("allPromocodes", promocodeApi.getAllPromocodes, {
keepPreviousData: true, keepPreviousData: true,
suspense: true, suspense: true,
onError(err) { onError(err) {
@ -145,5 +145,5 @@ export function useAllPromocodes() {
}, },
}); });
return swrResponse.data; return data;
} }

@ -21,6 +21,7 @@ import theme from "@root/theme";
import type { TextFieldProps } from "@mui/material"; import type { TextFieldProps } from "@mui/material";
import { CreatePromocodeBody } from "@root/model/promocodes"; import { CreatePromocodeBody } from "@root/model/promocodes";
import type { ChangeEvent } from "react"; import type { ChangeEvent } from "react";
import { enqueueSnackbar } from "notistack";
type BonusType = "discount" | "privilege"; type BonusType = "discount" | "privilege";
@ -74,23 +75,33 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
}, []); }, []);
const submitForm = (values: FormValues) => { const submitForm = (values: FormValues) => {
const currentPrivilege = privileges.find( const currentPrivilege = privileges.find(
(item) => item.privilegeId === values.privilegeId (item) => item.privilegeId === values.privilegeId
); );
const body = { const body = { ...values };
...values,
};
if ((body.layer === 1 && bonusType === "discount") || bonusType === "privilege") { if (
if (currentPrivilege === undefined) return; (body.layer === 1 && bonusType === "discount") ||
body.serviceKey = currentPrivilege?.serviceKey bonusType === "privilege"
body.target = body.privilegeId ) {
if (currentPrivilege === undefined) {
enqueueSnackbar("Привилегия не выбрана");
return;
}
body.serviceKey = currentPrivilege?.serviceKey;
body.target = body.privilegeId;
} }
if ((body.layer === 2 && bonusType === "discount")) { if (body.layer === 2 && bonusType === "discount") {
if (body.serviceKey === undefined) return; if (!body.serviceKey) {
body.target = body.serviceKey enqueueSnackbar("Сервис не выбран");
return;
}
body.target = body.serviceKey;
} }
const factorFromDiscountValue = 1 - body.factor / 100; const factorFromDiscountValue = 1 - body.factor / 100;
@ -178,6 +189,7 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
<CustomTextField <CustomTextField
name="activationCount" name="activationCount"
label="Количество активаций промокода" label="Количество активаций промокода"
required
onChange={({ target }) => onChange={({ target }) =>
setFieldValue( setFieldValue(
"activationCount", "activationCount",
@ -253,64 +265,57 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
> >
{values.layer === 1 ? "Выбор привилегии" : "Выбор сервиса"} {values.layer === 1 ? "Выбор привилегии" : "Выбор сервиса"}
</Typography> </Typography>
{ {values.layer === 1 ? (
values.layer === 1 ? <Field
name="privilegeId"
<Field as={Select}
name="privilegeId" label={"Привилегия"}
as={Select} sx={{
label={"Привилегия"} width: "100%",
sx={{ border: "2px solid",
width: "100%", color: theme.palette.secondary.main,
border: "2px solid", borderColor: theme.palette.secondary.main,
color: theme.palette.secondary.main, "&.Mui-focused .MuiOutlinedInput-notchedOutline": {
borderColor: theme.palette.secondary.main, border: "none",
"&.Mui-focused .MuiOutlinedInput-notchedOutline": { },
border: "none", ".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
}, }}
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main }, onChange={({ target }: SelectChangeProps) => {
}} setFieldValue("target", target.value);
onChange={({ target }: SelectChangeProps) => { setFieldValue("privilegeId", target.value);
setFieldValue("target", target.value) }}
setFieldValue("privilegeId", target.value) children={privileges.map(({ name, privilegeId }) => (
}} <MenuItem key={privilegeId} value={privilegeId}>
children={ {name}
privileges.map(({ name, privilegeId }) => ( </MenuItem>
<MenuItem key={privilegeId} value={privilegeId}> ))}
{name} />
</MenuItem> ) : (
)) <Field
} name="serviceKey"
/> as={Select}
: label={"Сервис"}
<Field sx={{
name="serviceKey" width: "100%",
as={Select} border: "2px solid",
label={"Сервис"} color: theme.palette.secondary.main,
sx={{ borderColor: theme.palette.secondary.main,
width: "100%", "&.Mui-focused .MuiOutlinedInput-notchedOutline": {
border: "2px solid", border: "none",
color: theme.palette.secondary.main, },
borderColor: theme.palette.secondary.main, ".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
"&.Mui-focused .MuiOutlinedInput-notchedOutline": { }}
border: "none", onChange={({ target }: SelectChangeProps) => {
}, setFieldValue("target", target.value);
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main }, setFieldValue("serviceKey", target.value);
}} }}
onChange={({ target }: SelectChangeProps) => { children={SERVICE_LIST.map(({ displayName, serviceKey }) => (
setFieldValue("target", target.value) <MenuItem key={serviceKey} value={serviceKey}>
setFieldValue("serviceKey", target.value) {displayName}
}} </MenuItem>
children={ ))}
SERVICE_LIST.map(({ displayName, serviceKey }) => ( />
<MenuItem key={serviceKey} value={serviceKey}> )}
{displayName}
</MenuItem>
))
}
/>
}
<CustomTextField <CustomTextField
name="threshold" name="threshold"
label="При каком значении применяется скидка" label="При каком значении применяется скидка"
@ -383,7 +388,7 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
}} }}
type="submit" type="submit"
> >
Cоздать Создать
</Button> </Button>
</Form> </Form>
)} )}

@ -29,7 +29,7 @@ export const DateFilter = ({ to, setTo, from, setFrom }: DateFilterProps) => {
<DatePicker <DatePicker
inputFormat="DD/MM/YYYY" inputFormat="DD/MM/YYYY"
value={from} value={from}
onChange={(date) => date && setFrom(date)} onChange={(date) => date && setFrom(date.startOf('day'))}
renderInput={(params) => ( renderInput={(params) => (
<TextField <TextField
{...params} {...params}
@ -61,7 +61,7 @@ export const DateFilter = ({ to, setTo, from, setFrom }: DateFilterProps) => {
<DatePicker <DatePicker
inputFormat="DD/MM/YYYY" inputFormat="DD/MM/YYYY"
value={to} value={to}
onChange={(date) => date && setTo(date)} onChange={(date) => date && setTo(date.endOf('day'))}
renderInput={(params) => ( renderInput={(params) => (
<TextField <TextField
{...params} {...params}

@ -18,7 +18,7 @@ import type { Moment } from "moment";
export const QuizInfo = () => { export const QuizInfo = () => {
const [from, setFrom] = useState<Moment | null>(null); const [from, setFrom] = useState<Moment | null>(null);
const [to, setTo] = useState<Moment | null>(moment(Date.now())); const [to, setTo] = useState<Moment | null>(moment());
const theme = useTheme(); const theme = useTheme();
const { Registrations, Quizes, Results } = useQuizStatistic({ const { Registrations, Quizes, Results } = useQuizStatistic({
from, from,
@ -27,7 +27,7 @@ export const QuizInfo = () => {
const resetTime = () => { const resetTime = () => {
setFrom(moment()); setFrom(moment());
setTo(moment(Date.now())); setTo(moment());
}; };
return ( return (

@ -91,7 +91,7 @@ export const StatisticsPromocode = () => {
{Regs} {Regs}
</TableCell> </TableCell>
<TableCell sx={{ color: "inherit" }} align="center"> <TableCell sx={{ color: "inherit" }} align="center">
{Money} {(Money / 100).toFixed(2)}
</TableCell> </TableCell>
</TableRow> </TableRow>
</TableBody> </TableBody>

@ -61,7 +61,8 @@ export const StatisticsSchild = () => {
const [to, setTo] = useState<Moment | null>(moment()); const [to, setTo] = useState<Moment | null>(moment());
const theme = useTheme(); const theme = useTheme();
const statistics = useSchildStatistics(from, to); const statistics = useSchildStatistics(from, to)
.map((obj) => ({...obj, Money: Number((obj.Money / 100).toFixed(2))}));
useEffect(() => { useEffect(() => {
if (!openUserModal) { if (!openUserModal) {
@ -173,7 +174,7 @@ export const StatisticsSchild = () => {
{Regs} {Regs}
</TableCell> </TableCell>
<TableCell sx={{ color: "inherit" }} align="center"> <TableCell sx={{ color: "inherit" }} align="center">
{Money} {(Money / 100).toFixed(2)}
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))}

@ -1,3 +1,5 @@
import { Suspense } from "react";
import { Box } from "@mui/material";
import { LocalizationProvider } from "@mui/x-date-pickers"; import { LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment"; import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment";
@ -9,6 +11,8 @@ export const QuizStatistics = () => (
<LocalizationProvider dateAdapter={AdapterMoment}> <LocalizationProvider dateAdapter={AdapterMoment}>
<QuizInfo /> <QuizInfo />
<StatisticsSchild /> <StatisticsSchild />
<StatisticsPromocode /> <Suspense fallback={<Box>Loading...</Box>}>
<StatisticsPromocode />
</Suspense>
</LocalizationProvider> </LocalizationProvider>
); );

@ -46,7 +46,6 @@ export default function EditModal() {
updatedTariff.description = descriptionField; updatedTariff.description = descriptionField;
updatedTariff.order = parseInt(orderField); updatedTariff.order = parseInt(orderField);
const [_, putedTariffError] = await putTariff(updatedTariff); const [_, putedTariffError] = await putTariff(updatedTariff);
if (putedTariffError) { if (putedTariffError) {
@ -99,20 +98,20 @@ export default function EditModal() {
sx={{ marginBottom: "10px" }} sx={{ marginBottom: "10px" }}
/> />
<Typography> <Typography>
Цена: {tariff.price} Цена: {Math.trunc((tariff.price ?? 0) / 100)}
</Typography> </Typography>
<TextField <TextField
type="number" type="number"
onChange={(event) => setPriceField(event.target.value)} onChange={({ target }) =>
setPriceField(String(+target.value * 100))
}
label="Цена" label="Цена"
name="price" name="price"
value={priceField} value={Math.trunc(Number(priceField) / 100)}
sx={{ marginBottom: "10px" }} sx={{ marginBottom: "10px" }}
/> />
<Typography> <Typography>Описание: {tariff.description}</Typography>
Описание: {tariff.description}
</Typography>
<TextField <TextField
type="text" type="text"
multiline={true} multiline={true}
@ -122,9 +121,7 @@ export default function EditModal() {
value={descriptionField} value={descriptionField}
sx={{ marginBottom: "10px" }} sx={{ marginBottom: "10px" }}
/> />
<Typography> <Typography>Порядок: {tariff.order}</Typography>
Порядок: {tariff.order}
</Typography>
<TextField <TextField
type="number" type="number"
onChange={(event) => setOrderField(event.target.value)} onChange={(event) => setOrderField(event.target.value)}