Merge branch 'create-promocode-privilege' into 'dev'

feat: privilegeId

See merge request frontend/admin!63
This commit is contained in:
Nastya 2024-04-10 14:55:43 +00:00
commit 4f11fb0215
2 changed files with 358 additions and 329 deletions

@ -8,6 +8,7 @@ export type CreatePromocodeBody = {
privilege: {
privilegeID: string;
amount: number;
serviceKey: string;
};
discount: {
layer: number;

@ -36,6 +36,14 @@ type FormValues = {
factor: number;
target: string;
threshold: number;
serviceKey: string;
};
type SelectChangeProps = {
target: {
name: string;
value: string;
};
};
const initialValues: FormValues = {
@ -50,6 +58,7 @@ const initialValues: FormValues = {
factor: 0,
target: "",
threshold: 0,
serviceKey: "",
};
type Props = {
@ -79,7 +88,11 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
dueTo: body.dueTo,
activationCount: body.activationCount,
bonus: {
privilege: { privilegeID: body.privilegeId, amount: body.amount },
privilege: {
privilegeID: body.privilegeId,
amount: body.amount,
serviceKey: body.serviceKey,
},
discount: {
layer: body.layer,
factor: factorFromDiscountValue,
@ -230,6 +243,20 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
name="target"
as={Select}
label={values.layer === 1 ? "Привилегия" : "Сервис"}
onChange={({ target }: SelectChangeProps) => {
if (values.layer === 1) {
const currentPrivilege = privileges.find(
(item) => item.privilegeId === target.value
);
setFieldValue("serviceKey", currentPrivilege?.serviceKey);
setFieldValue("privilegeId", currentPrivilege?.privilegeId);
return;
}
setFieldValue("privilegeId", target.value);
}}
sx={{
width: "100%",
border: "2px solid",
@ -240,6 +267,7 @@ export const CreatePromocodeForm = ({ createPromocode }: Props) => {
},
".MuiSvgIcon-root ": { fill: theme.palette.secondary.main },
}}
value={values.privilegeId}
children={
values.layer === 1
? privileges.map(({ name, privilegeId }) => (