import Combobox from '@/components/combobox'; import InputError from '@/components/input-error'; import LoadingButton from '@/components/loading-button'; import TagInput from '@/components/tag-input'; import { Card } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import DashboardLayout from '@/layouts/dashboard/layout'; import { onHandleChange } from '@/lib/inertia'; import { SharedData } from '@/types/global'; import { useForm } from '@inertiajs/react'; import { ReactNode } from 'react'; interface Props extends SharedData { users: User[]; instructor?: Instructor; } const CreateUpdate = ({ instructor, users, translate }: Props) => { // Parse the options and answers if they're strings const initialOptions = instructor?.skills ? (typeof instructor.skills === 'string' ? JSON.parse(instructor.skills) : instructor.skills) : []; const { dashboard, input, button } = translate; const { data, setData, post, processing, errors, reset } = useForm({ user_id: '', designation: instructor?.designation || '', skills: initialOptions, biography: instructor?.biography || '', resume: null, }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (instructor) { post(route('become-instructor.update', { id: instructor.id })); } else { post(route('become-instructor.store'), { onSuccess: () => { reset(); }, }); } }; const transformedUsers = users.map((user) => ({ value: user.id.toString(), label: user.name, })); return (
setData('user_id', selected.value)} />
onHandleChange(e, setData)} placeholder={input.designation_placeholder} />
onHandleChange(e, setData)} />
setData('skills', values)} />