mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- Remove nested git repository from bugulma/frontend/.git - Add all frontend files to main repository tracking - Convert from separate frontend/backend repos to unified monorepo - Preserve all frontend code and development history as tracked files - Eliminate nested repository complexity for simpler development workflow This creates a proper monorepo structure with frontend and backend coexisting in the same repository for easier development and deployment.
80 lines
1.9 KiB
TypeScript
80 lines
1.9 KiB
TypeScript
/**
|
|
* Organization form management hook
|
|
* Handles form state, validation, and submission
|
|
* Separated from wizard logic for better SRP
|
|
*/
|
|
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import { useCallback } from 'react';
|
|
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
import { getOrganizationFormSchema } from '@/schemas/organization.ts';
|
|
import { OrganizationFormData } from '@/types.ts';
|
|
import { useTranslation } from '@/hooks/useI18n.tsx';
|
|
|
|
interface UseOrganizationFormProps {
|
|
onSuccess: (data: OrganizationFormData) => void;
|
|
}
|
|
|
|
export const useOrganizationForm = ({ onSuccess }: UseOrganizationFormProps) => {
|
|
const { t } = useTranslation();
|
|
|
|
const form = useForm<OrganizationFormData>({
|
|
resolver: zodResolver(getOrganizationFormSchema(t)),
|
|
mode: 'onChange',
|
|
defaultValues: {
|
|
name: '',
|
|
sector: '',
|
|
description: '',
|
|
legal_form: 'LLC',
|
|
website: '',
|
|
primary_contact: { name: '', role: '', email: '', phone: '' },
|
|
business_focus: [],
|
|
industries: [],
|
|
tags: [],
|
|
needs: [],
|
|
offers: [],
|
|
logoUrl: '',
|
|
company_size: 1,
|
|
founding_year: new Date().getFullYear(),
|
|
address: {
|
|
street: '',
|
|
city: 'Бугульма',
|
|
state: 'Татарстан',
|
|
zip: '',
|
|
},
|
|
location: {
|
|
lat: 54.53,
|
|
lng: 52.79,
|
|
},
|
|
},
|
|
});
|
|
|
|
const onSubmit: SubmitHandler<OrganizationFormData> = useCallback(
|
|
(data) => {
|
|
onSuccess(data);
|
|
},
|
|
[onSuccess]
|
|
);
|
|
|
|
const resetForm = useCallback(() => {
|
|
form.reset();
|
|
}, [form]);
|
|
|
|
const validateFields = useCallback(
|
|
async (fields: (keyof OrganizationFormData | 'location.lat' | 'location.lng')[]) => {
|
|
return await form.trigger(fields);
|
|
},
|
|
[form]
|
|
);
|
|
|
|
return {
|
|
form,
|
|
onSubmit,
|
|
resetForm,
|
|
validateFields,
|
|
watch: form.watch,
|
|
setValue: form.setValue,
|
|
getValues: form.getValues,
|
|
};
|
|
};
|