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() {
|
||||
const swrResponse = useSwr("allPromocodes", promocodeApi.getAllPromocodes, {
|
||||
const { data } = useSwr("allPromocodes", promocodeApi.getAllPromocodes, {
|
||||
keepPreviousData: true,
|
||||
suspense: true,
|
||||
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 { CreatePromocodeBody } from "@root/model/promocodes";
|
||||
import type { ChangeEvent } from "react";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
|
||||
type BonusType = "discount" | "privilege";
|
||||
|
||||
@ -74,23 +75,33 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
|
||||
}, []);
|
||||
|
||||
const submitForm = (values: FormValues) => {
|
||||
|
||||
const currentPrivilege = privileges.find(
|
||||
(item) => item.privilegeId === values.privilegeId
|
||||
);
|
||||
|
||||
const body = {
|
||||
...values,
|
||||
};
|
||||
const body = { ...values };
|
||||
|
||||
if ((body.layer === 1 && bonusType === "discount") || bonusType === "privilege") {
|
||||
if (currentPrivilege === undefined) return;
|
||||
body.serviceKey = currentPrivilege?.serviceKey
|
||||
body.target = body.privilegeId
|
||||
if (
|
||||
(body.layer === 1 && bonusType === "discount") ||
|
||||
bonusType === "privilege"
|
||||
) {
|
||||
if (currentPrivilege === undefined) {
|
||||
enqueueSnackbar("Привилегия не выбрана");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
body.serviceKey = currentPrivilege?.serviceKey;
|
||||
body.target = body.privilegeId;
|
||||
}
|
||||
if ((body.layer === 2 && bonusType === "discount")) {
|
||||
if (body.serviceKey === undefined) return;
|
||||
body.target = body.serviceKey
|
||||
if (body.layer === 2 && bonusType === "discount") {
|
||||
if (!body.serviceKey) {
|
||||
enqueueSnackbar("Сервис не выбран");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
body.target = body.serviceKey;
|
||||
}
|
||||
|
||||
const factorFromDiscountValue = 1 - body.factor / 100;
|
||||
@ -178,6 +189,7 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
|
||||
<CustomTextField
|
||||
name="activationCount"
|
||||
label="Количество активаций промокода"
|
||||
required
|
||||
onChange={({ target }) =>
|
||||
setFieldValue(
|
||||
"activationCount",
|
||||
@ -253,64 +265,57 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
|
||||
>
|
||||
{values.layer === 1 ? "Выбор привилегии" : "Выбор сервиса"}
|
||||
</Typography>
|
||||
{
|
||||
values.layer === 1 ?
|
||||
|
||||
<Field
|
||||
name="privilegeId"
|
||||
as={Select}
|
||||
label={"Привилегия"}
|
||||
sx={{
|
||||
width: "100%",
|
||||
border: "2px solid",
|
||||
color: theme.palette.secondary.main,
|
||||
borderColor: theme.palette.secondary.main,
|
||||
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
|
||||
border: "none",
|
||||
},
|
||||
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
|
||||
}}
|
||||
onChange={({ target }: SelectChangeProps) => {
|
||||
setFieldValue("target", target.value)
|
||||
setFieldValue("privilegeId", target.value)
|
||||
}}
|
||||
children={
|
||||
privileges.map(({ name, privilegeId }) => (
|
||||
<MenuItem key={privilegeId} value={privilegeId}>
|
||||
{name}
|
||||
</MenuItem>
|
||||
))
|
||||
}
|
||||
/>
|
||||
:
|
||||
<Field
|
||||
name="serviceKey"
|
||||
as={Select}
|
||||
label={"Сервис"}
|
||||
sx={{
|
||||
width: "100%",
|
||||
border: "2px solid",
|
||||
color: theme.palette.secondary.main,
|
||||
borderColor: theme.palette.secondary.main,
|
||||
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
|
||||
border: "none",
|
||||
},
|
||||
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
|
||||
}}
|
||||
onChange={({ target }: SelectChangeProps) => {
|
||||
setFieldValue("target", target.value)
|
||||
setFieldValue("serviceKey", target.value)
|
||||
}}
|
||||
children={
|
||||
SERVICE_LIST.map(({ displayName, serviceKey }) => (
|
||||
<MenuItem key={serviceKey} value={serviceKey}>
|
||||
{displayName}
|
||||
</MenuItem>
|
||||
))
|
||||
}
|
||||
/>
|
||||
|
||||
}
|
||||
{values.layer === 1 ? (
|
||||
<Field
|
||||
name="privilegeId"
|
||||
as={Select}
|
||||
label={"Привилегия"}
|
||||
sx={{
|
||||
width: "100%",
|
||||
border: "2px solid",
|
||||
color: theme.palette.secondary.main,
|
||||
borderColor: theme.palette.secondary.main,
|
||||
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
|
||||
border: "none",
|
||||
},
|
||||
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
|
||||
}}
|
||||
onChange={({ target }: SelectChangeProps) => {
|
||||
setFieldValue("target", target.value);
|
||||
setFieldValue("privilegeId", target.value);
|
||||
}}
|
||||
children={privileges.map(({ name, privilegeId }) => (
|
||||
<MenuItem key={privilegeId} value={privilegeId}>
|
||||
{name}
|
||||
</MenuItem>
|
||||
))}
|
||||
/>
|
||||
) : (
|
||||
<Field
|
||||
name="serviceKey"
|
||||
as={Select}
|
||||
label={"Сервис"}
|
||||
sx={{
|
||||
width: "100%",
|
||||
border: "2px solid",
|
||||
color: theme.palette.secondary.main,
|
||||
borderColor: theme.palette.secondary.main,
|
||||
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
|
||||
border: "none",
|
||||
},
|
||||
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
|
||||
}}
|
||||
onChange={({ target }: SelectChangeProps) => {
|
||||
setFieldValue("target", target.value);
|
||||
setFieldValue("serviceKey", target.value);
|
||||
}}
|
||||
children={SERVICE_LIST.map(({ displayName, serviceKey }) => (
|
||||
<MenuItem key={serviceKey} value={serviceKey}>
|
||||
{displayName}
|
||||
</MenuItem>
|
||||
))}
|
||||
/>
|
||||
)}
|
||||
<CustomTextField
|
||||
name="threshold"
|
||||
label="При каком значении применяется скидка"
|
||||
@ -383,7 +388,7 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
|
||||
}}
|
||||
type="submit"
|
||||
>
|
||||
Cоздать
|
||||
Создать
|
||||
</Button>
|
||||
</Form>
|
||||
)}
|
||||
|
@ -29,7 +29,7 @@ export const DateFilter = ({ to, setTo, from, setFrom }: DateFilterProps) => {
|
||||
<DatePicker
|
||||
inputFormat="DD/MM/YYYY"
|
||||
value={from}
|
||||
onChange={(date) => date && setFrom(date)}
|
||||
onChange={(date) => date && setFrom(date.startOf('day'))}
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
@ -61,7 +61,7 @@ export const DateFilter = ({ to, setTo, from, setFrom }: DateFilterProps) => {
|
||||
<DatePicker
|
||||
inputFormat="DD/MM/YYYY"
|
||||
value={to}
|
||||
onChange={(date) => date && setTo(date)}
|
||||
onChange={(date) => date && setTo(date.endOf('day'))}
|
||||
renderInput={(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
|
@ -18,7 +18,7 @@ import type { Moment } from "moment";
|
||||
|
||||
export const QuizInfo = () => {
|
||||
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 { Registrations, Quizes, Results } = useQuizStatistic({
|
||||
from,
|
||||
@ -27,7 +27,7 @@ export const QuizInfo = () => {
|
||||
|
||||
const resetTime = () => {
|
||||
setFrom(moment());
|
||||
setTo(moment(Date.now()));
|
||||
setTo(moment());
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -91,7 +91,7 @@ export const StatisticsPromocode = () => {
|
||||
{Regs}
|
||||
</TableCell>
|
||||
<TableCell sx={{ color: "inherit" }} align="center">
|
||||
{Money}
|
||||
{(Money / 100).toFixed(2)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
|
@ -61,7 +61,8 @@ export const StatisticsSchild = () => {
|
||||
const [to, setTo] = useState<Moment | null>(moment());
|
||||
|
||||
const theme = useTheme();
|
||||
const statistics = useSchildStatistics(from, to);
|
||||
const statistics = useSchildStatistics(from, to)
|
||||
.map((obj) => ({...obj, Money: Number((obj.Money / 100).toFixed(2))}));
|
||||
|
||||
useEffect(() => {
|
||||
if (!openUserModal) {
|
||||
@ -173,7 +174,7 @@ export const StatisticsSchild = () => {
|
||||
{Regs}
|
||||
</TableCell>
|
||||
<TableCell sx={{ color: "inherit" }} align="center">
|
||||
{Money}
|
||||
{(Money / 100).toFixed(2)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { Suspense } from "react";
|
||||
import { Box } from "@mui/material";
|
||||
import { LocalizationProvider } from "@mui/x-date-pickers";
|
||||
import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment";
|
||||
|
||||
@ -9,6 +11,8 @@ export const QuizStatistics = () => (
|
||||
<LocalizationProvider dateAdapter={AdapterMoment}>
|
||||
<QuizInfo />
|
||||
<StatisticsSchild />
|
||||
<StatisticsPromocode />
|
||||
<Suspense fallback={<Box>Loading...</Box>}>
|
||||
<StatisticsPromocode />
|
||||
</Suspense>
|
||||
</LocalizationProvider>
|
||||
);
|
||||
|
@ -46,7 +46,6 @@ export default function EditModal() {
|
||||
updatedTariff.description = descriptionField;
|
||||
updatedTariff.order = parseInt(orderField);
|
||||
|
||||
|
||||
const [_, putedTariffError] = await putTariff(updatedTariff);
|
||||
|
||||
if (putedTariffError) {
|
||||
@ -99,20 +98,20 @@ export default function EditModal() {
|
||||
sx={{ marginBottom: "10px" }}
|
||||
/>
|
||||
<Typography>
|
||||
Цена: {tariff.price}
|
||||
Цена: {Math.trunc((tariff.price ?? 0) / 100)}
|
||||
</Typography>
|
||||
<TextField
|
||||
type="number"
|
||||
onChange={(event) => setPriceField(event.target.value)}
|
||||
onChange={({ target }) =>
|
||||
setPriceField(String(+target.value * 100))
|
||||
}
|
||||
label="Цена"
|
||||
name="price"
|
||||
value={priceField}
|
||||
value={Math.trunc(Number(priceField) / 100)}
|
||||
sx={{ marginBottom: "10px" }}
|
||||
/>
|
||||
|
||||
<Typography>
|
||||
Описание: {tariff.description}
|
||||
</Typography>
|
||||
<Typography>Описание: {tariff.description}</Typography>
|
||||
<TextField
|
||||
type="text"
|
||||
multiline={true}
|
||||
@ -122,9 +121,7 @@ export default function EditModal() {
|
||||
value={descriptionField}
|
||||
sx={{ marginBottom: "10px" }}
|
||||
/>
|
||||
<Typography>
|
||||
Порядок: {tariff.order}
|
||||
</Typography>
|
||||
<Typography>Порядок: {tariff.order}</Typography>
|
||||
<TextField
|
||||
type="number"
|
||||
onChange={(event) => setOrderField(event.target.value)}
|
||||
|
Loading…
Reference in New Issue
Block a user