fix: tariff editing is now working

feat: add taariff description support
feat: add tariff ordering support
This commit is contained in:
skeris 2023-12-16 00:21:41 +03:00
parent 05e7d399f3
commit 4c3d063528
9 changed files with 99 additions and 8 deletions

@ -6,7 +6,7 @@
"@date-io/dayjs": "^2.15.0", "@date-io/dayjs": "^2.15.0",
"@emotion/react": "^11.10.4", "@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4", "@emotion/styled": "^11.10.4",
"@frontend/kitui": "^1.0.54", "@frontend/kitui": "^1.0.59",
"@material-ui/pickers": "^3.3.10", "@material-ui/pickers": "^3.3.10",
"@mui/icons-material": "^5.10.3", "@mui/icons-material": "^5.10.3",
"@mui/material": "^5.10.5", "@mui/material": "^5.10.5",

@ -9,6 +9,7 @@ import type { EditTariffRequestBody } from "@root/model/tariff";
type CreateTariffBackendRequest = { type CreateTariffBackendRequest = {
name: string; name: string;
description: string; description: string;
order: number;
price: number; price: number;
isCustom: boolean; isCustom: boolean;
privileges: Omit<PrivilegeWithAmount, "_id" | "updatedAt">[]; privileges: Omit<PrivilegeWithAmount, "_id" | "updatedAt">[];
@ -53,6 +54,8 @@ export const putTariff = async (tariff: Tariff): Promise<[null, string?]> => {
name: tariff.name, name: tariff.name,
price: tariff.price ?? 0, price: tariff.price ?? 0,
isCustom: false, isCustom: false,
order: tariff.order || 1,
description: tariff.description,
privileges: tariff.privileges, privileges: tariff.privileges,
}, },
}); });

@ -20,7 +20,9 @@ export type ServiceType = (typeof SERVICE_LIST)[number]["serviceKey"];
export type PrivilegeType = "unlim" | "gencount" | "activequiz" | "abcount" | "extended"; export type PrivilegeType = "unlim" | "gencount" | "activequiz" | "abcount" | "extended";
export type EditTariffRequestBody = { export type EditTariffRequestBody = {
description: string;
name: string; name: string;
order: number;
price: number; price: number;
isCustom: boolean; isCustom: boolean;
privileges: Omit<PrivilegeWithAmount, "_id" | "updatedAt">[]; privileges: Omit<PrivilegeWithAmount, "_id" | "updatedAt">[];

@ -27,6 +27,7 @@ interface Values {
amountField: string, amountField: string,
customPriceField: string, customPriceField: string,
privilegeIdField: string, privilegeIdField: string,
orderField: number,
privilege: PrivilegeWithAmount | null privilege: PrivilegeWithAmount | null
} }
@ -58,6 +59,7 @@ export default function CreateTariff() {
amountField: "", amountField: "",
customPriceField: "", customPriceField: "",
privilegeIdField: "", privilegeIdField: "",
orderField: 0,
privilege: null privilege: null
}; };
@ -69,6 +71,7 @@ export default function CreateTariff() {
const [_, createdTariffError] = await createTariff({ const [_, createdTariffError] = await createTariff({
name: values.nameField, name: values.nameField,
price: Number(values.customPriceField) * 100, price: Number(values.customPriceField) * 100,
order: values.orderField,
isCustom: false, isCustom: false,
description: values.descriptionField, description: values.descriptionField,
privileges: [ privileges: [
@ -309,6 +312,29 @@ export default function CreateTariff() {
} }
}} }}
/> />
<TextField
id="tariff-order"
name="orderField"
variant="filled"
onChange={(e) => {
props.setFieldValue("orderField", e.target.value)
}}
value={props.values.orderField}
onBlur={props.handleBlur}
label="порядковый номер"
InputProps={{
style: {
backgroundColor: theme.palette.content.main,
color: theme.palette.secondary.main,
}
}}
type={'number'}
InputLabelProps={{
style: {
color: theme.palette.secondary.main
}
}}
/>
<Button <Button
className="btn_createTariffBackend" className="btn_createTariffBackend"
type="submit" type="submit"

@ -14,6 +14,8 @@ import { currencyFormatter } from "@root/utils/currencyFormatter";
export default function EditModal() { export default function EditModal() {
const [nameField, setNameField] = useState(""); const [nameField, setNameField] = useState("");
const [priceField, setPriceField] = useState(""); const [priceField, setPriceField] = useState("");
const [descriptionField, setDescriptionField] = useState("");
const [orderField, setOrderField] = useState("");
const tariffs = useTariffStore((state) => state.tariffs); const tariffs = useTariffStore((state) => state.tariffs);
const editTariffId = useTariffStore((state) => state.editTariffId); const editTariffId = useTariffStore((state) => state.editTariffId);
@ -41,6 +43,9 @@ export default function EditModal() {
const updatedTariff = structuredClone(tariff); const updatedTariff = structuredClone(tariff);
updatedTariff.name = nameField; updatedTariff.name = nameField;
updatedTariff.price = price; updatedTariff.price = price;
updatedTariff.description = descriptionField;
updatedTariff.order = orderField;
const [_, putedTariffError] = await putTariff(updatedTariff); const [_, putedTariffError] = await putTariff(updatedTariff);
@ -94,16 +99,40 @@ export default function EditModal() {
sx={{ marginBottom: "10px" }} sx={{ marginBottom: "10px" }}
/> />
<Typography> <Typography>
Цена за единицу: {currencyFormatter.format(tariff.privileges[0].price / 100)} Цена: {tariff.price}
</Typography> </Typography>
<TextField <TextField
type="number" type="number"
onChange={(event) => setPriceField(event.target.value)} onChange={(event) => setPriceField(event.target.value)}
label="Цена за единицу" label="Цена"
name="price" name="price"
value={priceField} value={priceField}
sx={{ marginBottom: "10px" }} sx={{ marginBottom: "10px" }}
/> />
<Typography>
Описание: {tariff.description}
</Typography>
<TextField
type="text"
multiline={true}
onChange={(event) => setDescriptionField(event.target.value)}
label="описание"
name="description"
value={descriptionField}
sx={{ marginBottom: "10px" }}
/>
<Typography>
Порядок: {tariff.order}
</Typography>
<TextField
type="number"
onChange={(event) => setOrderField(event.target.value)}
label="Порядок"
name="order"
value={orderField}
sx={{ marginBottom: "10px" }}
/>
<Button onClick={handleEditClick}>Редактировать</Button> <Button onClick={handleEditClick}>Редактировать</Button>
</Box> </Box>
)} )}

@ -14,7 +14,7 @@ import { currencyFormatter } from "@root/utils/currencyFormatter";
const columns: GridColDef<Tariff, string | number>[] = [ const columns: GridColDef<Tariff, string | number>[] = [
{ field: "_id", headerName: "ID", width: 100, valueGetter: ({ row }) => row._id }, { field: "_id", headerName: "ID", width: 100, valueGetter: ({ row }) => row.order || 1 },
{ {
field: "edit", field: "edit",
headerName: "Изменение", headerName: "Изменение",

@ -28,6 +28,7 @@ describe("Cart calculations", () => {
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
price: 100 * 100, price: 100 * 100,
amount: 100,
appliedPrivilegeDiscount: null, appliedPrivilegeDiscount: null,
}, },
], ],
@ -66,6 +67,7 @@ describe("Cart calculations", () => {
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
price: 100 * 100, price: 100 * 100,
amount: 100,
appliedPrivilegeDiscount: null, appliedPrivilegeDiscount: null,
}, },
], ],
@ -88,6 +90,7 @@ describe("Cart calculations", () => {
price: 200 * 200, price: 200 * 200,
privilegeId: "p2", privilegeId: "p2",
serviceKey: "squiz", serviceKey: "squiz",
amount: 100,
appliedPrivilegeDiscount: null, appliedPrivilegeDiscount: null,
}, },
], ],
@ -107,6 +110,7 @@ describe("Cart calculations", () => {
privileges: [ privileges: [
{ {
description: "d3", description: "d3",
amount: 100,
price: 300 * 300, price: 300 * 300,
privilegeId: "p3", privilegeId: "p3",
serviceKey: "reducer", serviceKey: "reducer",
@ -145,6 +149,7 @@ describe("Cart calculations", () => {
privileges: [ privileges: [
{ {
privilegeId: "p1", privilegeId: "p1",
amount: 100,
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
price: 100 * 100, price: 100 * 100,
@ -159,6 +164,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
description: "d5", description: "d5",
price: 600 * 600, price: 600 * 600,
privilegeId: "p5", privilegeId: "p5",
@ -181,6 +187,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
description: "d3", description: "d3",
price: 300 * 300, price: 300 * 300,
privilegeId: "p3", privilegeId: "p3",
@ -242,6 +249,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -280,6 +288,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
description: "d3", description: "d3",
price: 300 * 300 * 0.95, price: 300 * 300 * 0.95,
privilegeId: "p3", privilegeId: "p3",
@ -319,6 +328,7 @@ describe("Cart calculations", () => {
privileges: [ privileges: [
{ {
privilegeId: "p1", privilegeId: "p1",
amount: 100,
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
price: 100 * 100 * 0.8, price: 100 * 100 * 0.8,
@ -334,6 +344,7 @@ describe("Cart calculations", () => {
privileges: [ privileges: [
{ {
description: "d5", description: "d5",
amount: 100,
price: 600 * 600 * 0.8, price: 600 * 600 * 0.8,
privilegeId: "p5", privilegeId: "p5",
serviceKey: "templategen", serviceKey: "templategen",
@ -371,6 +382,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -388,6 +400,7 @@ describe("Cart calculations", () => {
{ {
description: "d5", description: "d5",
price: 600 * 600, price: 600 * 600,
amount: 100,
privilegeId: "p5", privilegeId: "p5",
serviceKey: "templategen", serviceKey: "templategen",
appliedPrivilegeDiscount: null, appliedPrivilegeDiscount: null,
@ -424,6 +437,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -462,6 +476,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -500,6 +515,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -538,6 +554,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -578,6 +595,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -620,6 +638,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -662,6 +681,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -684,6 +704,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
description: "d3", description: "d3",
price: 300 * 300 * 0.95, price: 300 * 300 * 0.95,
privilegeId: "p3", privilegeId: "p3",
@ -726,6 +747,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
privilegeId: "p1", privilegeId: "p1",
serviceKey: "templategen", serviceKey: "templategen",
description: "d1", description: "d1",
@ -741,6 +763,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
description: "d5", description: "d5",
price: 600 * 600 * 0.8, price: 600 * 600 * 0.8,
privilegeId: "p5", privilegeId: "p5",
@ -763,6 +786,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
description: "d2", description: "d2",
price: 200 * 200, price: 200 * 200,
privilegeId: "p2", privilegeId: "p2",
@ -785,6 +809,7 @@ describe("Cart calculations", () => {
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
amount: 100,
description: "d3", description: "d3",
price: 300 * 300 * 0.95, price: 300 * 300 * 0.95,
privilegeId: "p3", privilegeId: "p3",
@ -810,6 +835,7 @@ const templategenTariff1: Tariff = {
_id: "t1", _id: "t1",
name: "templategenTariff1", name: "templategenTariff1",
price: 0, price: 0,
description: "test",
isCustom: false, isCustom: false,
privileges: [ privileges: [
{ {
@ -830,6 +856,7 @@ const templategenTariff1: Tariff = {
}; };
const templategenTariff2: Tariff = { const templategenTariff2: Tariff = {
description: "test",
_id: "t5", _id: "t5",
name: "templategenTariff2", name: "templategenTariff2",
price: 0, price: 0,
@ -853,6 +880,7 @@ const templategenTariff2: Tariff = {
}; };
const customTemplategenTariff: Tariff = { const customTemplategenTariff: Tariff = {
description: "test",
_id: "t1", _id: "t1",
name: "templategenTariff3", name: "templategenTariff3",
price: 0, price: 0,
@ -876,6 +904,7 @@ const customTemplategenTariff: Tariff = {
}; };
const squizTariff: Tariff = { const squizTariff: Tariff = {
description: "test",
_id: "t2", _id: "t2",
name: "squizTariff", name: "squizTariff",
price: 0, price: 0,
@ -899,6 +928,7 @@ const squizTariff: Tariff = {
}; };
const reducerTariff: Tariff = { const reducerTariff: Tariff = {
description: "test",
_id: "t3", _id: "t3",
name: "reducerTariff", name: "reducerTariff",
price: 0, price: 0,

@ -51,6 +51,7 @@ export function calcCart(
const privilegeCartData: PrivilegeCartData = { const privilegeCartData: PrivilegeCartData = {
serviceKey: privilege.serviceKey, serviceKey: privilege.serviceKey,
amount: privilege.amount,
privilegeId: privilege.privilegeId, privilegeId: privilege.privilegeId,
description: privilege.description, description: privilege.description,
price: privilegePrice, price: privilegePrice,

@ -1433,10 +1433,10 @@
lodash.isundefined "^3.0.1" lodash.isundefined "^3.0.1"
lodash.uniq "^4.5.0" lodash.uniq "^4.5.0"
"@frontend/kitui@^1.0.54": "@frontend/kitui@^1.0.59":
version "1.0.54" version "1.0.59"
resolved "https://penahub.gitlab.yandexcloud.net/api/v4/projects/21/packages/npm/@frontend/kitui/-/@frontend/kitui-1.0.54.tgz#0235d5a8effb9b92351471c3c7775f28cb2839f6" resolved "https://penahub.gitlab.yandexcloud.net/api/v4/projects/21/packages/npm/@frontend/kitui/-/@frontend/kitui-1.0.59.tgz#c4584506bb5cab4fc1df35f5b1d0d66ec379a9a1"
integrity sha1-AjXVqO/7m5I1FHHDx3dfKMsoOfY= integrity sha1-xFhFBrtcq0/B3zX1sdDWbsN5qaE=
dependencies: dependencies:
immer "^10.0.2" immer "^10.0.2"
reconnecting-eventsource "^1.6.2" reconnecting-eventsource "^1.6.2"