Merge branch 'dev' of penahub.gitlab.yandexcloud.net:frontend/admin into dev
This commit is contained in:
commit
495278c1e0
@ -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;
|
||||||
}
|
}
|
||||||
if ((body.layer === 2 && bonusType === "discount")) {
|
|
||||||
if (body.serviceKey === undefined) return;
|
body.serviceKey = currentPrivilege?.serviceKey;
|
||||||
body.target = body.serviceKey
|
body.target = body.privilegeId;
|
||||||
|
}
|
||||||
|
if (body.layer === 2 && bonusType === "discount") {
|
||||||
|
if (!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,9 +265,7 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
|
|||||||
>
|
>
|
||||||
{values.layer === 1 ? "Выбор привилегии" : "Выбор сервиса"}
|
{values.layer === 1 ? "Выбор привилегии" : "Выбор сервиса"}
|
||||||
</Typography>
|
</Typography>
|
||||||
{
|
{values.layer === 1 ? (
|
||||||
values.layer === 1 ?
|
|
||||||
|
|
||||||
<Field
|
<Field
|
||||||
name="privilegeId"
|
name="privilegeId"
|
||||||
as={Select}
|
as={Select}
|
||||||
@ -271,18 +281,16 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
|
|||||||
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
|
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
|
||||||
}}
|
}}
|
||||||
onChange={({ target }: SelectChangeProps) => {
|
onChange={({ target }: SelectChangeProps) => {
|
||||||
setFieldValue("target", target.value)
|
setFieldValue("target", target.value);
|
||||||
setFieldValue("privilegeId", target.value)
|
setFieldValue("privilegeId", target.value);
|
||||||
}}
|
}}
|
||||||
children={
|
children={privileges.map(({ name, privilegeId }) => (
|
||||||
privileges.map(({ name, privilegeId }) => (
|
|
||||||
<MenuItem key={privilegeId} value={privilegeId}>
|
<MenuItem key={privilegeId} value={privilegeId}>
|
||||||
{name}
|
{name}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))
|
))}
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
:
|
) : (
|
||||||
<Field
|
<Field
|
||||||
name="serviceKey"
|
name="serviceKey"
|
||||||
as={Select}
|
as={Select}
|
||||||
@ -298,19 +306,16 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
|
|||||||
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
|
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
|
||||||
}}
|
}}
|
||||||
onChange={({ target }: SelectChangeProps) => {
|
onChange={({ target }: SelectChangeProps) => {
|
||||||
setFieldValue("target", target.value)
|
setFieldValue("target", target.value);
|
||||||
setFieldValue("serviceKey", target.value)
|
setFieldValue("serviceKey", target.value);
|
||||||
}}
|
}}
|
||||||
children={
|
children={SERVICE_LIST.map(({ displayName, serviceKey }) => (
|
||||||
SERVICE_LIST.map(({ displayName, serviceKey }) => (
|
|
||||||
<MenuItem key={serviceKey} value={serviceKey}>
|
<MenuItem key={serviceKey} value={serviceKey}>
|
||||||
{displayName}
|
{displayName}
|
||||||
</MenuItem>
|
</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 />
|
||||||
|
<Suspense fallback={<Box>Loading...</Box>}>
|
||||||
<StatisticsPromocode />
|
<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)}
|
||||||
|
Loading…
Reference in New Issue
Block a user