diff --git a/src/pages/root/steps/price-step/index.tsx b/src/pages/root/steps/price-step/index.tsx index 0fdff9f..b361a77 100644 --- a/src/pages/root/steps/price-step/index.tsx +++ b/src/pages/root/steps/price-step/index.tsx @@ -24,48 +24,31 @@ export const PriceStep = ({ nextStep, prevStep }: PriceStepProps) => { const rootStore = useRootStore(); const formSchema = useMemo(() => { + const parsePrice = (value: unknown) => { + if (typeof value === "string") { + // Replace commas with dots and parse the value + const parsedValue = parseFloat(value.replace(",", ".")); + return isNaN(parsedValue) ? undefined : parsedValue; + } + return undefined; + }; + if (rootStore.allowResale) { return z.object({ price: z.preprocess( - (value) => { - const parsed = parseFloat(value as string); - - return isNaN(parsed) ? undefined : parsed; - }, - z - .number() - .min(MIN_PRICE, `Цена должна быть минимум ${MIN_PRICE} TON.`), + parsePrice, + z.number().min(MIN_PRICE, `Цена должна быть минимум ${MIN_PRICE} TON.`) ), - resaleLicensePrice: z - .preprocess( - (value) => { - if (value === undefined || value === "" || value === 0) - return undefined; - - const parsed = parseFloat(value as string); - return isNaN(parsed) ? undefined : parsed; - }, - - z - .number() - .min( - MIN_RESALE_PRICE, - `Цена копии должна быть минимум ${MIN_RESALE_PRICE} TON.`, - ), - ) - .optional(), + .preprocess(parsePrice, z.number().min(MIN_RESALE_PRICE, `Цена копии должна быть минимум ${MIN_RESALE_PRICE} TON.`)) + .optional(), }); } return z.object({ price: z.preprocess( - (value) => { - const parsed = parseFloat(value as string); - - return isNaN(parsed) ? undefined : parsed; - }, - z.number().min(MIN_PRICE, `Цена должна быть минимум ${MIN_PRICE} TON.`), + parsePrice, + z.number().min(MIN_PRICE, `Цена должна быть минимум ${MIN_PRICE} TON.`) ), }); }, [rootStore.allowResale]); @@ -75,10 +58,8 @@ export const PriceStep = ({ nextStep, prevStep }: PriceStepProps) => { const form = useForm({ resolver: zodResolver(formSchema), mode: "onChange", - defaultValues: { price: rootStore.price, - //@ts-expect-error Fix typings resaleLicensePrice: rootStore?.licenseResalePrice, }, @@ -92,13 +73,11 @@ export const PriceStep = ({ nextStep, prevStep }: PriceStepProps) => { form.handleSubmit(async (values: FormValues) => { try { rootStore.setPrice(values.price); - //@ts-expect-error Fix typings if (values?.resaleLicensePrice) { //@ts-expect-error Fix typings rootStore.setLicenseResalePrice(values?.resaleLicensePrice); } - nextStep(); } catch (error) { console.error("Error: ", error); @@ -107,81 +86,34 @@ export const PriceStep = ({ nextStep, prevStep }: PriceStepProps) => { }; return ( -
- - -
- /Укажите цену -
- 4/5 -
-
- -
- -
-

Минимальная стоимость {MIN_PRICE} TON.

-

- Рекомендуемая стоимость {RECOMMENDED_PRICE} TON. -

+
+ +
+ /Укажите цену +
+ 4/5
- - - - - {/*
*/} - {/* {*/} - {/* rootStore.setAllowResale(!rootStore.allowResale);*/} - {/* }}*/} - {/* />*/} - {/* }*/} - {/* />*/} - - {/* {rootStore.allowResale && (*/} - {/* */} - {/*
*/} - {/*

*/} - {/* Это цена, по которой пользователи будут покупать и*/} - {/* перепродавать ваш контент.*/} - {/*

*/} - - {/*

*/} - {/* Минимальная стоимость {MIN_RESALE_PRICE} TON.*/} - {/*

*/} - {/*

*/} - {/* Рекомендуемая стоимость {RECOMMENDED_RESALE_PRICE} TON.*/} - {/*

*/} - {/*
*/} - - {/* */} - {/*
*/} - {/* )}*/} - {/*
*/} -
- -
+
+
+ +
+

Минимальная стоимость {MIN_PRICE} TON.

+

Рекомендуемая стоимость {RECOMMENDED_PRICE} TON.

+
+ +
+
+
); -}; +}; \ No newline at end of file diff --git a/src/pages/view-content/index.tsx b/src/pages/view-content/index.tsx index cc44e5a..3d39c80 100644 --- a/src/pages/view-content/index.tsx +++ b/src/pages/view-content/index.tsx @@ -91,6 +91,14 @@ export const ViewContentPage = () => { label={`Купить за ${fromNanoTON(content?.data?.encrypted?.license?.resale?.price)} ТОН`} includeArrows={true} /> + +