diff --git a/apps/web/src/app/user/register-coffee/page.tsx b/apps/web/src/app/user/register-coffee/page.tsx index 88efa5f..dc2184e 100644 --- a/apps/web/src/app/user/register-coffee/page.tsx +++ b/apps/web/src/app/user/register-coffee/page.tsx @@ -4,296 +4,181 @@ import { ArrowPathRoundedSquareIcon, CameraIcon, } from "@heroicons/react/24/outline"; -import { ClockIcon } from "@heroicons/react/24/solid"; import { zodResolver } from "@hookform/resolvers/zod"; import Button from "@repo/ui/button"; -import RadioButton from "@repo/ui/form/radioButton"; +import { useContract } from "@starknet-react/core"; import Image from "next/image"; +import { useState } from "react"; import { useForm } from "react-hook-form"; -import { useTranslation } from "react-i18next"; import { z } from "zod"; import { ProfileOptionLayout } from "~/app/_components/features/ProfileOptionLayout"; +import { + abiMarketPlace, + marketplaceAddress, +} from "~/contracts/abi/MarketPlace"; import { RoastLevel } from "~/types"; const schema = z.object({ roast: z.string().min(1, "Roast level is required"), - price: z.string().min(1, "Price is required"), - bagsAvailable: z.number().min(0, "Available bags must be a positive number"), + price: z + .string() + .regex(/^\d+(\.\d{1,2})?$/, "Invalid price format") + .min(1, "Price is required"), + bagsAvailable: z.number().min(1, "Available bags must be at least 1"), description: z.string().min(1, "Description is required"), variety: z.string().min(1, "Variety is required"), - coffeeScore: z - .number() - .min(0, "Coffee score must be a positive number") - .max(100, "Coffee score must be at most 100") - .optional(), - image: z.string().optional(), }); type FormData = z.infer; + export default function RegisterCoffee() { - const { t } = useTranslation(); + const [isLoading, setIsLoading] = useState(false); + const [transactionHash, setTransactionHash] = useState(null); + const [error, setError] = useState(null); + + const { contract } = useContract({ + abi: abiMarketPlace, + address: marketplaceAddress, + }); + + const { register, handleSubmit } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + roast: RoastLevel.LIGHT, + bagsAvailable: 1, + }, + }); + const handleImageUpload = () => { - alert(t("implement_image_upload")); + alert("Implement image upload"); }; - const { register, handleSubmit, control, getValues, setValue } = - useForm({ - resolver: zodResolver(schema), - defaultValues: { - roast: RoastLevel.LIGHT, - bagsAvailable: 1, - }, - }); - const onSubmit = async (data: FormData) => { - const submissionData = { - ...data, - price: Number.parseFloat(data.price), - }; - // TODO: Implement coffee registration logic - console.log(submissionData); - }; + if (!contract) { + setError("Error with the contract connection"); + return; + } - return ( - -
-
-
- Coffee - -
-
- - -
-
- -