Merge branch 'dev' into 'staging'
Dev See merge request frontend/admin!64
This commit is contained in:
commit
5a31cb5fde
@ -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 }) => (
|
||||
|
Loading…
Reference in New Issue
Block a user