| Fixed price and add button to upload own content
This commit is contained in:
parent
1e7e773cb1
commit
9cef81a3c1
|
|
@ -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<FormValues>({
|
||||
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 (
|
||||
<section className={"mt-4 px-4 pb-8"}>
|
||||
<BackButton onClick={prevStep} />
|
||||
|
||||
<div className={"mb-[30px] flex flex-col text-sm"}>
|
||||
<span className={"ml-4"}>/Укажите цену</span>
|
||||
<div>
|
||||
4/<span className={"text-[#7B7B7B]"}>5</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={"flex flex-col gap-[20px]"}>
|
||||
<FormLabel label={"Цена продажи TON"}>
|
||||
<div className={"my-2 flex flex-col gap-1.5"}>
|
||||
<p className={"text-xs"}>Минимальная стоимость {MIN_PRICE} TON.</p>
|
||||
<p className={"text-xs"}>
|
||||
Рекомендуемая стоимость {RECOMMENDED_PRICE} TON.
|
||||
</p>
|
||||
<section className={"mt-4 px-4 pb-8"}>
|
||||
<BackButton onClick={prevStep} />
|
||||
<div className={"mb-[30px] flex flex-col text-sm"}>
|
||||
<span className={"ml-4"}>/Укажите цену</span>
|
||||
<div>
|
||||
4/<span className={"text-[#7B7B7B]"}>5</span>
|
||||
</div>
|
||||
|
||||
<Input
|
||||
error={form.formState.errors?.price}
|
||||
placeholder={"[ Введите цену ]"}
|
||||
{...form.register("price")}
|
||||
/>
|
||||
</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>
|
||||
|
||||
<Button
|
||||
className={"mt-[30px]"}
|
||||
onClick={handleSubmit}
|
||||
includeArrows={true}
|
||||
label={"Далее"}
|
||||
disabled={!form.formState.isValid}
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
<div className={"flex flex-col gap-[20px]"}>
|
||||
<FormLabel label={"Цена продажи TON"}>
|
||||
<div className={"my-2 flex flex-col gap-1.5"}>
|
||||
<p className={"text-xs"}>Минимальная стоимость {MIN_PRICE} TON.</p>
|
||||
<p className={"text-xs"}>Рекомендуемая стоимость {RECOMMENDED_PRICE} TON.</p>
|
||||
</div>
|
||||
<Input
|
||||
error={form.formState.errors?.price}
|
||||
placeholder={"[ Введите цену ]"}
|
||||
{...form.register("price")}
|
||||
/>
|
||||
</FormLabel>
|
||||
</div>
|
||||
<Button
|
||||
className={"mt-[30px]"}
|
||||
onClick={handleSubmit}
|
||||
includeArrows={true}
|
||||
label={"Далее"}
|
||||
disabled={!form.formState.isValid}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
|
@ -91,6 +91,14 @@ export const ViewContentPage = () => {
|
|||
label={`Купить за ${fromNanoTON(content?.data?.encrypted?.license?.resale?.price)} ТОН`}
|
||||
includeArrows={true}
|
||||
/>
|
||||
|
||||
<Button
|
||||
onClick={() => {
|
||||
WebApp.openTelegramLink(`https://t.me/MY_UploaderRobot`);
|
||||
}}
|
||||
className={"mb-4 mt-[30px] h-[48px]"}
|
||||
label={`Загрузить свой контент`}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue