fix: tariff editing is now working
feat: add taariff description support feat: add tariff ordering support
This commit is contained in:
parent
05e7d399f3
commit
4c3d063528
@ -6,7 +6,7 @@
|
||||
"@date-io/dayjs": "^2.15.0",
|
||||
"@emotion/react": "^11.10.4",
|
||||
"@emotion/styled": "^11.10.4",
|
||||
"@frontend/kitui": "^1.0.54",
|
||||
"@frontend/kitui": "^1.0.59",
|
||||
"@material-ui/pickers": "^3.3.10",
|
||||
"@mui/icons-material": "^5.10.3",
|
||||
"@mui/material": "^5.10.5",
|
||||
|
@ -9,6 +9,7 @@ import type { EditTariffRequestBody } from "@root/model/tariff";
|
||||
type CreateTariffBackendRequest = {
|
||||
name: string;
|
||||
description: string;
|
||||
order: number;
|
||||
price: number;
|
||||
isCustom: boolean;
|
||||
privileges: Omit<PrivilegeWithAmount, "_id" | "updatedAt">[];
|
||||
@ -53,6 +54,8 @@ export const putTariff = async (tariff: Tariff): Promise<[null, string?]> => {
|
||||
name: tariff.name,
|
||||
price: tariff.price ?? 0,
|
||||
isCustom: false,
|
||||
order: tariff.order || 1,
|
||||
description: tariff.description,
|
||||
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 EditTariffRequestBody = {
|
||||
description: string;
|
||||
name: string;
|
||||
order: number;
|
||||
price: number;
|
||||
isCustom: boolean;
|
||||
privileges: Omit<PrivilegeWithAmount, "_id" | "updatedAt">[];
|
||||
|
@ -27,6 +27,7 @@ interface Values {
|
||||
amountField: string,
|
||||
customPriceField: string,
|
||||
privilegeIdField: string,
|
||||
orderField: number,
|
||||
privilege: PrivilegeWithAmount | null
|
||||
}
|
||||
|
||||
@ -58,6 +59,7 @@ export default function CreateTariff() {
|
||||
amountField: "",
|
||||
customPriceField: "",
|
||||
privilegeIdField: "",
|
||||
orderField: 0,
|
||||
privilege: null
|
||||
};
|
||||
|
||||
@ -69,6 +71,7 @@ export default function CreateTariff() {
|
||||
const [_, createdTariffError] = await createTariff({
|
||||
name: values.nameField,
|
||||
price: Number(values.customPriceField) * 100,
|
||||
order: values.orderField,
|
||||
isCustom: false,
|
||||
description: values.descriptionField,
|
||||
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
|
||||
className="btn_createTariffBackend"
|
||||
type="submit"
|
||||
|
@ -14,6 +14,8 @@ import { currencyFormatter } from "@root/utils/currencyFormatter";
|
||||
export default function EditModal() {
|
||||
const [nameField, setNameField] = useState("");
|
||||
const [priceField, setPriceField] = useState("");
|
||||
const [descriptionField, setDescriptionField] = useState("");
|
||||
const [orderField, setOrderField] = useState("");
|
||||
const tariffs = useTariffStore((state) => state.tariffs);
|
||||
const editTariffId = useTariffStore((state) => state.editTariffId);
|
||||
|
||||
@ -41,6 +43,9 @@ export default function EditModal() {
|
||||
const updatedTariff = structuredClone(tariff);
|
||||
updatedTariff.name = nameField;
|
||||
updatedTariff.price = price;
|
||||
updatedTariff.description = descriptionField;
|
||||
updatedTariff.order = orderField;
|
||||
|
||||
|
||||
const [_, putedTariffError] = await putTariff(updatedTariff);
|
||||
|
||||
@ -94,16 +99,40 @@ export default function EditModal() {
|
||||
sx={{ marginBottom: "10px" }}
|
||||
/>
|
||||
<Typography>
|
||||
Цена за единицу: {currencyFormatter.format(tariff.privileges[0].price / 100)}
|
||||
Цена: {tariff.price}
|
||||
</Typography>
|
||||
<TextField
|
||||
type="number"
|
||||
onChange={(event) => setPriceField(event.target.value)}
|
||||
label="Цена за единицу"
|
||||
label="Цена"
|
||||
name="price"
|
||||
value={priceField}
|
||||
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>
|
||||
</Box>
|
||||
)}
|
||||
|
@ -14,7 +14,7 @@ import { currencyFormatter } from "@root/utils/currencyFormatter";
|
||||
|
||||
|
||||
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",
|
||||
headerName: "Изменение",
|
||||
|
@ -28,6 +28,7 @@ describe("Cart calculations", () => {
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
price: 100 * 100,
|
||||
amount: 100,
|
||||
appliedPrivilegeDiscount: null,
|
||||
},
|
||||
],
|
||||
@ -66,6 +67,7 @@ describe("Cart calculations", () => {
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
price: 100 * 100,
|
||||
amount: 100,
|
||||
appliedPrivilegeDiscount: null,
|
||||
},
|
||||
],
|
||||
@ -88,6 +90,7 @@ describe("Cart calculations", () => {
|
||||
price: 200 * 200,
|
||||
privilegeId: "p2",
|
||||
serviceKey: "squiz",
|
||||
amount: 100,
|
||||
appliedPrivilegeDiscount: null,
|
||||
},
|
||||
],
|
||||
@ -107,6 +110,7 @@ describe("Cart calculations", () => {
|
||||
privileges: [
|
||||
{
|
||||
description: "d3",
|
||||
amount: 100,
|
||||
price: 300 * 300,
|
||||
privilegeId: "p3",
|
||||
serviceKey: "reducer",
|
||||
@ -145,6 +149,7 @@ describe("Cart calculations", () => {
|
||||
privileges: [
|
||||
{
|
||||
privilegeId: "p1",
|
||||
amount: 100,
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
price: 100 * 100,
|
||||
@ -159,6 +164,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
description: "d5",
|
||||
price: 600 * 600,
|
||||
privilegeId: "p5",
|
||||
@ -181,6 +187,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
description: "d3",
|
||||
price: 300 * 300,
|
||||
privilegeId: "p3",
|
||||
@ -242,6 +249,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -280,6 +288,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
description: "d3",
|
||||
price: 300 * 300 * 0.95,
|
||||
privilegeId: "p3",
|
||||
@ -319,6 +328,7 @@ describe("Cart calculations", () => {
|
||||
privileges: [
|
||||
{
|
||||
privilegeId: "p1",
|
||||
amount: 100,
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
price: 100 * 100 * 0.8,
|
||||
@ -334,6 +344,7 @@ describe("Cart calculations", () => {
|
||||
privileges: [
|
||||
{
|
||||
description: "d5",
|
||||
amount: 100,
|
||||
price: 600 * 600 * 0.8,
|
||||
privilegeId: "p5",
|
||||
serviceKey: "templategen",
|
||||
@ -371,6 +382,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -388,6 +400,7 @@ describe("Cart calculations", () => {
|
||||
{
|
||||
description: "d5",
|
||||
price: 600 * 600,
|
||||
amount: 100,
|
||||
privilegeId: "p5",
|
||||
serviceKey: "templategen",
|
||||
appliedPrivilegeDiscount: null,
|
||||
@ -424,6 +437,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -462,6 +476,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -500,6 +515,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -538,6 +554,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -578,6 +595,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -620,6 +638,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -662,6 +681,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -684,6 +704,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
description: "d3",
|
||||
price: 300 * 300 * 0.95,
|
||||
privilegeId: "p3",
|
||||
@ -726,6 +747,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
privilegeId: "p1",
|
||||
serviceKey: "templategen",
|
||||
description: "d1",
|
||||
@ -741,6 +763,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
description: "d5",
|
||||
price: 600 * 600 * 0.8,
|
||||
privilegeId: "p5",
|
||||
@ -763,6 +786,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
description: "d2",
|
||||
price: 200 * 200,
|
||||
privilegeId: "p2",
|
||||
@ -785,6 +809,7 @@ describe("Cart calculations", () => {
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
amount: 100,
|
||||
description: "d3",
|
||||
price: 300 * 300 * 0.95,
|
||||
privilegeId: "p3",
|
||||
@ -810,6 +835,7 @@ const templategenTariff1: Tariff = {
|
||||
_id: "t1",
|
||||
name: "templategenTariff1",
|
||||
price: 0,
|
||||
description: "test",
|
||||
isCustom: false,
|
||||
privileges: [
|
||||
{
|
||||
@ -830,6 +856,7 @@ const templategenTariff1: Tariff = {
|
||||
};
|
||||
|
||||
const templategenTariff2: Tariff = {
|
||||
description: "test",
|
||||
_id: "t5",
|
||||
name: "templategenTariff2",
|
||||
price: 0,
|
||||
@ -853,6 +880,7 @@ const templategenTariff2: Tariff = {
|
||||
};
|
||||
|
||||
const customTemplategenTariff: Tariff = {
|
||||
description: "test",
|
||||
_id: "t1",
|
||||
name: "templategenTariff3",
|
||||
price: 0,
|
||||
@ -876,6 +904,7 @@ const customTemplategenTariff: Tariff = {
|
||||
};
|
||||
|
||||
const squizTariff: Tariff = {
|
||||
description: "test",
|
||||
_id: "t2",
|
||||
name: "squizTariff",
|
||||
price: 0,
|
||||
@ -899,6 +928,7 @@ const squizTariff: Tariff = {
|
||||
};
|
||||
|
||||
const reducerTariff: Tariff = {
|
||||
description: "test",
|
||||
_id: "t3",
|
||||
name: "reducerTariff",
|
||||
price: 0,
|
||||
|
@ -51,6 +51,7 @@ export function calcCart(
|
||||
|
||||
const privilegeCartData: PrivilegeCartData = {
|
||||
serviceKey: privilege.serviceKey,
|
||||
amount: privilege.amount,
|
||||
privilegeId: privilege.privilegeId,
|
||||
description: privilege.description,
|
||||
price: privilegePrice,
|
||||
|
@ -1433,10 +1433,10 @@
|
||||
lodash.isundefined "^3.0.1"
|
||||
lodash.uniq "^4.5.0"
|
||||
|
||||
"@frontend/kitui@^1.0.54":
|
||||
version "1.0.54"
|
||||
resolved "https://penahub.gitlab.yandexcloud.net/api/v4/projects/21/packages/npm/@frontend/kitui/-/@frontend/kitui-1.0.54.tgz#0235d5a8effb9b92351471c3c7775f28cb2839f6"
|
||||
integrity sha1-AjXVqO/7m5I1FHHDx3dfKMsoOfY=
|
||||
"@frontend/kitui@^1.0.59":
|
||||
version "1.0.59"
|
||||
resolved "https://penahub.gitlab.yandexcloud.net/api/v4/projects/21/packages/npm/@frontend/kitui/-/@frontend/kitui-1.0.59.tgz#c4584506bb5cab4fc1df35f5b1d0d66ec379a9a1"
|
||||
integrity sha1-xFhFBrtcq0/B3zX1sdDWbsN5qaE=
|
||||
dependencies:
|
||||
immer "^10.0.2"
|
||||
reconnecting-eventsource "^1.6.2"
|
||||
|
Loading…
Reference in New Issue
Block a user