Closed jayhubb4 closed 8 months ago
Please, provide a reproductable example so we are able to help you
Please remove all commented code and ensure the code blocks are formatted correctly. Code without indentation is impossible to read on mobile.
Hi Shadcn-Ui/Ui,
I figured it out. It was a validation issue.
On Thu, Dec 7, 2023 at 5:31 PM Joe @.***> wrote:
Please remove all commented code and ensure the code blocks are formatted correctly. Code without indentation is impossible to read on mobile.
— Reply to this email directly, view it on GitHub https://github.com/shadcn-ui/ui/issues/2031#issuecomment-1846210008, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYGIQ3KPKF6F33QIPYYXICLYII7UPAVCNFSM6AAAAABADXGIUOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBWGIYTAMBQHA . You are receiving this because you authored the thread.Message ID: @.***>
You gotta use the form HTML Component Without that No scene of the onSubmit action working.
This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.
`"use client";
import { useState, useEffect } from 'react'; import * as z from 'zod'; import { zodResolver } from '@hookform/resolvers/zod' import { UserValidation } from '@/lib/validations/user'; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { useForm } from 'react-hook-form'; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import Image from "next/image"; import { ChangeEvent } from 'react'; import { isBase64Image } from '@/lib/utils'; import { useUploadThing } from '@/lib/uploadthing'; import { updateUserProfile } from '@/lib/actions/user.actions'; import { usePathname, useRouter } from 'next/navigation'; import { UserData } from '@/lib/types/user'; import { doc, setDoc, getDoc, collection, serverTimestamp, GeoPoint } from 'firebase/firestore'; import { db } from '@/lib/firebase'; import { currentUser } from '@clerk/nextjs'; import { pmtMethods } from '@/lib/validations/user'; import { revalidatePath } from 'next/cache'; // import { userInfoArr } from '@/lib/actions/user.actions';
// These props are specifically from the form // interface Props { // user: { // id: string; // objectId: string; // username: string; // name: string; // bio: string; // image: string; // zipcode: string; // }; // btnTitle: string; // }
// * The optional fields should probably be in the new local interface for the pilot onboarding. interface UserProfile { user: { id: string; objectId: string; username: string; name: string; bio: string; image: string; zipcode: string; onboarded: boolean; path: string; memberSince: string; media?: string; specialty1?: string; specialty2?: string; specialty3?: string; specialty4?: string; specialty5?: string; pmtMethods?: typeof pmtMethods; prices?: string; facebook?: string; instagram?: string; tiktok?: string; linkedin?: string; isPilot: boolean; }; btnTitle: string; }
// export const onboardArray: { // c_id: string; // name: string; // profile_photo: string; // username: string; // bio: string; // zipCode: string; // isPilot: boolean; // }[] = [ // { // c_id: '', // name: '', // profile_photo: '', // username: '', // bio: '', // zipCode: '', // isPilot: false, // } // ];
const CreateAccount = ({ user, btnTitle }: UserProfile) => { const [files, setFiles] = useState<File[]>([]); const { startUpload } = useUploadThing('media'); const router = useRouter(); const pathname = usePathname(); const [showPilotOnboarding, setShowPilotOnboarding] = useState(false); const [isPilot, setIsPilot] = useState(false); const [onboardArray, setOnboardArray] = useState([ { c_id: '', name: '', profile_photo: '', username: '', bio: '', zipCode: '', isPilot: false, } ]);
const methods = useForm(); const { watch } = methods;
const watchIsPilot = watch('isPilot');
// // * Function to record the state of the checkbox and push its value into the array // const handleCheckboxChange = (checked: boolean) => { // setOnboardArray((prevOnboardArray) => [ // { // ...prevOnboardArray[0], // isPilot: checked, // }, // ]); // };
// Initialize variables to store location data let userLatitude: any = null; let userLongitude: any = null;
// Request the user's location using the Geolocation API if (typeof window !== 'undefined' && navigator.geolocation) { navigator.geolocation.getCurrentPosition((position) => { // Extract and store the latitude and longitude userLatitude = position.coords.latitude; userLongitude = position.coords.longitude;
} else { console.error('Geolocation is not available in this browser.'); }
const form = useForm({ resolver: zodResolver(UserValidation), defaultValues: { profile_photo: '', name:'', username:'', bio:'', zipCode:'', isPilot: false, media: '', // * This is for uploading media to their profile initially. Editing their profile is still needed specialty1: '', specialty2: '', specialty3: '', specialty4: '', specialty5: '', pmtMethods: ["Zelle", "Cash"], prices: '', // businessHrs: user?.businessHrs || '', facebook: '', instagram: '', tiktok: '', linkedin: '', } });
const { handleSubmit } = useForm({ resolver: zodResolver(UserValidation) });
const handleImage = (e: ChangeEvent, fieldChange: (value: string) => void) => {
e.preventDefault();
};
const onSubmit = async (values: z.infer) => {
const blob = values.profile_photo;
// Adds user's info to database via onboarding form submission & creates Doc in Firestore database // First (below) is for regular users only
const user = await currentUser(); const addUserRef = doc(db, 'customer-profiles', user?.id || userIdPath); const addPilotRef = doc(db, 'pilot-profiles', user?.id || userIdPath); const location = new GeoPoint(userLatitude, userLongitude);
}
return ( <Form {...form}> <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8 flex flex-col justify-start gap-10"
) }
// {onboardArray[0].isPilot ? ( //
Additional content for pilots
//Thank you!
//export default CreateAccount; `