diff --git a/actions/addNewProject.ts b/actions/addNewProject.ts new file mode 100644 index 00000000..a346147b --- /dev/null +++ b/actions/addNewProject.ts @@ -0,0 +1,7 @@ +'use server'; + +import { IAddProjectForm } from '@/types/forms'; + +export const addNewProject = async (data: IAddProjectForm) => { + console.log(data); +}; diff --git a/components/BeOurFriends/BeOurFriends.tsx b/components/BeOurFriends/BeOurFriends.tsx index 3d842883..d5876012 100644 --- a/components/BeOurFriends/BeOurFriends.tsx +++ b/components/BeOurFriends/BeOurFriends.tsx @@ -21,7 +21,7 @@ const variants = { }; const BeOurFriends = () => { - const t = useTranslations('components.home.beOurFriends'); + const t = useTranslations('Components.home.beOurFriends'); const localLang = useLocale(); const direction = localLang == 'he' ? 'rtl' : 'ltr'; diff --git a/components/Common/Inputs/FormTextInput.tsx b/components/Common/Inputs/FormTextInput.tsx index 1b7c5944..68f6b7c9 100644 --- a/components/Common/Inputs/FormTextInput.tsx +++ b/components/Common/Inputs/FormTextInput.tsx @@ -1,30 +1,34 @@ +import { FormFieldRegistration } from '@/types/forms'; import React from 'react'; -type FormTextInputProps = { +interface FormTextInputProps extends FormFieldRegistration { placeholder: string; - value: string; - onChange: (e: React.ChangeEvent) => void; - error?: string; + name: string; +} + +const getErrorMessage = (errors: any, name: string) => { + return errors?.[name]?.message || ''; }; export const FormTextInput: React.FC = ({ placeholder, - value, - onChange, - error, + errors, + name, + register, }) => { + const errorMessage = getErrorMessage(errors, name); return (
- {error &&

{error}

} + {errorMessage &&

{errorMessage}

}
); }; diff --git a/components/Common/Modals/AddProjectmodal/AddProjectModal.tsx b/components/Common/Modals/AddProjectmodal/AddProjectModal.tsx index f8cc161d..66ffca88 100644 --- a/components/Common/Modals/AddProjectmodal/AddProjectModal.tsx +++ b/components/Common/Modals/AddProjectmodal/AddProjectModal.tsx @@ -1,11 +1,6 @@ -import React, { useState } from 'react'; +import React from 'react'; import Modal from '../Modal'; -import { z, ZodError } from 'zod'; -import { FormTextInput } from '../../Inputs/FormTextInput'; -import { FileUploader } from './FileUploader'; -import { ProjectDescription } from './ProjectDescription'; -import { TermsAndConditions } from './TermsAndConditions'; -import { MustIncludeMessage } from './MustIncludeMessage'; +import { ModalContent } from './ModalContent'; interface AddProjectModalProps { isOpen: boolean; @@ -25,121 +20,3 @@ export const AddProjectModal = ({ ); }; -const schema = z.object({ - name: z.string().min(2), - projectName: z.string().min(4), - email: z.string().email(), -}); - -interface ModalContentProps { - closeModal: any; -} - -const ModalContent = ({ closeModal }: ModalContentProps) => { - type FormErrors = { - name?: string; - projectName?: string; - email?: string; - }; - - const [projectName, setProjectName] = useState(''); - const [name, setName] = useState(''); - const [email, setEmail] = useState(''); - const [repoLink, setRepoLink] = useState(''); - const [projectIcon, setProjectIcon] = useState(''); - const [projectDescription, setProjectDescription] = useState(''); - const [errors, setErrors] = useState({}); - - const handleNameChange = (e: React.ChangeEvent) => { - setName(e.target.value); - }; - - const handleProjectNameChange = (e: React.ChangeEvent) => { - setProjectName(e.target.value); - }; - - const handleEmailChange = (e: React.ChangeEvent) => { - setEmail(e.target.value); - }; - - const handleRepoLinkChange = (e: React.ChangeEvent) => { - setRepoLink(e.target.value); - }; - - const handleProjectDescriptionChange = ( - e: React.ChangeEvent - ) => { - setProjectDescription(e.target.value); - }; - - const handleFileChange = (file: File) => { - const reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = () => { - setProjectIcon(reader.result as string); - }; - }; - - const handleSubmit = () => { - try { - schema.parse({ name, projectName, email }); - setErrors({}); - //TODO Add logic behind this later - } catch (error: any) { - if (error instanceof ZodError) { - const parsedErrors: { [key: string]: string } = {}; - - for (const { path, message } of error.errors) { - parsedErrors[path[0]] = message; - } - setErrors(parsedErrors); - } - } - }; - - return ( -
-
-

- בקשה להוספת פרויקט -

- -
- -
- - - - - - -
- - - - -
- ); -}; diff --git a/components/Common/Modals/AddProjectmodal/FileUploader.tsx b/components/Common/Modals/AddProjectmodal/FileUploader.tsx index a2f37601..cfee28eb 100644 --- a/components/Common/Modals/AddProjectmodal/FileUploader.tsx +++ b/components/Common/Modals/AddProjectmodal/FileUploader.tsx @@ -1,28 +1,31 @@ import React from 'react'; import { UploadIcon } from './UploadIcon'; +import { UseFormRegister, FieldValues } from 'react-hook-form'; +import { FormFieldRegistration } from '@/types/forms'; +import { useTranslations } from 'next-intl'; -interface FileUploaderProps { - onChange: (file: File) => void; +interface FileUploaderProps extends FormFieldRegistration { + register: UseFormRegister; + name: string; } -export const FileUploader: React.FC = ({ onChange }) => { - const handleFileChange = (e: React.ChangeEvent) => { - const file = e.target.files?.[0]; - if (file) { - onChange(file); - } - }; +export const FileUploader: React.FC = ({ + register, + name, +}) => { + const t = useTranslations('Maintainers.maintainerForm'); return (
-

לוגו (אם יש)

+

{t('logo')}