| Fixed price and add button to upload own content

This commit is contained in:
rakhimovkamran 2024-08-31 02:36:21 +05:00
parent 1e7e773cb1
commit 9cef81a3c1
2 changed files with 52 additions and 112 deletions

View File

@ -24,48 +24,31 @@ export const PriceStep = ({ nextStep, prevStep }: PriceStepProps) => {
const rootStore = useRootStore(); const rootStore = useRootStore();
const formSchema = useMemo(() => { 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) { if (rootStore.allowResale) {
return z.object({ return z.object({
price: z.preprocess( price: z.preprocess(
(value) => { parsePrice,
const parsed = parseFloat(value as string); z.number().min(MIN_PRICE, `Цена должна быть минимум ${MIN_PRICE} TON.`)
return isNaN(parsed) ? undefined : parsed;
},
z
.number()
.min(MIN_PRICE, `Цена должна быть минимум ${MIN_PRICE} TON.`),
), ),
resaleLicensePrice: z resaleLicensePrice: z
.preprocess( .preprocess(parsePrice, z.number().min(MIN_RESALE_PRICE, `Цена копии должна быть минимум ${MIN_RESALE_PRICE} TON.`))
(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(), .optional(),
}); });
} }
return z.object({ return z.object({
price: z.preprocess( price: z.preprocess(
(value) => { parsePrice,
const parsed = parseFloat(value as string); z.number().min(MIN_PRICE, `Цена должна быть минимум ${MIN_PRICE} TON.`)
return isNaN(parsed) ? undefined : parsed;
},
z.number().min(MIN_PRICE, `Цена должна быть минимум ${MIN_PRICE} TON.`),
), ),
}); });
}, [rootStore.allowResale]); }, [rootStore.allowResale]);
@ -75,10 +58,8 @@ export const PriceStep = ({ nextStep, prevStep }: PriceStepProps) => {
const form = useForm<FormValues>({ const form = useForm<FormValues>({
resolver: zodResolver(formSchema), resolver: zodResolver(formSchema),
mode: "onChange", mode: "onChange",
defaultValues: { defaultValues: {
price: rootStore.price, price: rootStore.price,
//@ts-expect-error Fix typings //@ts-expect-error Fix typings
resaleLicensePrice: rootStore?.licenseResalePrice, resaleLicensePrice: rootStore?.licenseResalePrice,
}, },
@ -92,13 +73,11 @@ export const PriceStep = ({ nextStep, prevStep }: PriceStepProps) => {
form.handleSubmit(async (values: FormValues) => { form.handleSubmit(async (values: FormValues) => {
try { try {
rootStore.setPrice(values.price); rootStore.setPrice(values.price);
//@ts-expect-error Fix typings //@ts-expect-error Fix typings
if (values?.resaleLicensePrice) { if (values?.resaleLicensePrice) {
//@ts-expect-error Fix typings //@ts-expect-error Fix typings
rootStore.setLicenseResalePrice(values?.resaleLicensePrice); rootStore.setLicenseResalePrice(values?.resaleLicensePrice);
} }
nextStep(); nextStep();
} catch (error) { } catch (error) {
console.error("Error: ", error); console.error("Error: ", error);
@ -109,72 +88,25 @@ export const PriceStep = ({ nextStep, prevStep }: PriceStepProps) => {
return ( return (
<section className={"mt-4 px-4 pb-8"}> <section className={"mt-4 px-4 pb-8"}>
<BackButton onClick={prevStep} /> <BackButton onClick={prevStep} />
<div className={"mb-[30px] flex flex-col text-sm"}> <div className={"mb-[30px] flex flex-col text-sm"}>
<span className={"ml-4"}>/Укажите цену</span> <span className={"ml-4"}>/Укажите цену</span>
<div> <div>
4/<span className={"text-[#7B7B7B]"}>5</span> 4/<span className={"text-[#7B7B7B]"}>5</span>
</div> </div>
</div> </div>
<div className={"flex flex-col gap-[20px]"}> <div className={"flex flex-col gap-[20px]"}>
<FormLabel label={"Цена продажи TON"}> <FormLabel label={"Цена продажи TON"}>
<div className={"my-2 flex flex-col gap-1.5"}> <div className={"my-2 flex flex-col gap-1.5"}>
<p className={"text-xs"}>Минимальная стоимость {MIN_PRICE} TON.</p> <p className={"text-xs"}>Минимальная стоимость {MIN_PRICE} TON.</p>
<p className={"text-xs"}> <p className={"text-xs"}>Рекомендуемая стоимость {RECOMMENDED_PRICE} TON.</p>
Рекомендуемая стоимость {RECOMMENDED_PRICE} TON.
</p>
</div> </div>
<Input <Input
error={form.formState.errors?.price} error={form.formState.errors?.price}
placeholder={"[ Введите цену ]"} placeholder={"[ Введите цену ]"}
{...form.register("price")} {...form.register("price")}
/> />
</FormLabel> </FormLabel>
{/*<div className={"flex flex-col gap-2"}>*/}
{/* <FormLabel*/}
{/* labelClassName={"flex"}*/}
{/* label={"Разрешить копии"}*/}
{/* formLabelAddon={*/}
{/* <Checkbox*/}
{/* checked={rootStore.allowResale}*/}
{/* onClick={() => {*/}
{/* rootStore.setAllowResale(!rootStore.allowResale);*/}
{/* }}*/}
{/* />*/}
{/* }*/}
{/* />*/}
{/* {rootStore.allowResale && (*/}
{/* <FormLabel label={"Цена копии TON"}>*/}
{/* <div className={"my-2 flex flex-col gap-1.5"}>*/}
{/* <p className={"text-xs"}>*/}
{/* Это цена, по которой пользователи будут покупать и*/}
{/* перепродавать ваш контент.*/}
{/* </p>*/}
{/* <p className={"text-xs"}>*/}
{/* Минимальная стоимость {MIN_RESALE_PRICE} TON.*/}
{/* </p>*/}
{/* <p className={"text-xs"}>*/}
{/* Рекомендуемая стоимость {RECOMMENDED_RESALE_PRICE} TON.*/}
{/* </p>*/}
{/* </div>*/}
{/* <Input*/}
{/* //@ts-expect-error Fix typings*/}
{/* error={form.formState.errors?.resaleLicensePrice}*/}
{/* placeholder={"[ Введите цену копии ]"}*/}
{/* //@ts-expect-error Fix typings*/}
{/* {...form.register("resaleLicensePrice")}*/}
{/* />*/}
{/* </FormLabel>*/}
{/* )}*/}
{/*</div>*/}
</div> </div>
<Button <Button
className={"mt-[30px]"} className={"mt-[30px]"}
onClick={handleSubmit} onClick={handleSubmit}

View File

@ -91,6 +91,14 @@ export const ViewContentPage = () => {
label={`Купить за ${fromNanoTON(content?.data?.encrypted?.license?.resale?.price)} ТОН`} label={`Купить за ${fromNanoTON(content?.data?.encrypted?.license?.resale?.price)} ТОН`}
includeArrows={true} includeArrows={true}
/> />
<Button
onClick={() => {
WebApp.openTelegramLink(`https://t.me/MY_UploaderRobot`);
}}
className={"mb-4 mt-[30px] h-[48px]"}
label={`Загрузить свой контент`}
/>
</main> </main>
); );
}; };