feat(companies): Enhance company forms with additional fields
This commit expands the company profile by adding several new fields to the create and edit forms. This allows for the collection of more detailed and comprehensive company information. Key changes include: - Added new fields: Establishment Date, Company Type, Business Nature, Industry, Country, State, and City. - Introduced a new reusable `DatePicker` component, utilizing `react-datepicker`, for date input. - Created a new `CalendarIcon` for use in the date picker. - Updated the company Zod schema, API services, and data types to support the new fields. Additionally, this commit includes a refactor to standardize the `MultiSelect` component by renaming the `text` prop to `label` for better consistency across form elements. Form labels are now capitalized for a uniform UI.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
"use client";
|
||||
import {
|
||||
NotificationChannels,
|
||||
NotificationPriorities,
|
||||
NotificationTargetGroups,
|
||||
NotificationTypes,
|
||||
} from "@/constants/enums";
|
||||
import {
|
||||
useCompanyFullList,
|
||||
useGetAllCustomers,
|
||||
useGetUsersQuery,
|
||||
} from "@/hooks/queries";
|
||||
import { useCreateNotificationQuery } from "@/hooks/queries/useNotificationQueries";
|
||||
import { TCreateNotificationCredentials } from "@/lib/api/types/NotificationHistory";
|
||||
import { ILabelValue } from "@/types/shared";
|
||||
import { getEnumAsArray } from "@/utils/shared";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { ChangeEvent, useState } from "react";
|
||||
import { SubmitHandler, useForm } from "react-hook-form";
|
||||
|
||||
const useCreateNotificationFormPresenter = () => {
|
||||
const [recipient, setRecipient] = useState<ILabelValue[] | null>(null);
|
||||
const {
|
||||
register,
|
||||
formState: { errors },
|
||||
handleSubmit,
|
||||
watch,
|
||||
setValue,
|
||||
reset,
|
||||
control,
|
||||
} = useForm<TCreateNotificationCredentials>();
|
||||
const router = useRouter();
|
||||
const { data: companies } = useCompanyFullList();
|
||||
const { data: users } = useGetUsersQuery();
|
||||
const { data: customers } = useGetAllCustomers();
|
||||
const { mutate } = useCreateNotificationQuery(() => {
|
||||
router.back();
|
||||
reset();
|
||||
});
|
||||
const onSubmit: SubmitHandler<TCreateNotificationCredentials> = (data) => {
|
||||
mutate({ credentials: data });
|
||||
};
|
||||
const handleCancel = () => {
|
||||
reset();
|
||||
router.back();
|
||||
};
|
||||
|
||||
const onSelectTarget = (event: ChangeEvent<HTMLSelectElement>): void => {
|
||||
const type = event.target.value as NotificationTargetGroups;
|
||||
|
||||
const recipientMaps: Partial<
|
||||
Record<NotificationTargetGroups, Array<ILabelValue> | null>
|
||||
> = {
|
||||
[NotificationTargetGroups.SPECIFIC_COMPANY]:
|
||||
companies?.data.companies?.map((company) => ({
|
||||
label: company.name,
|
||||
value: company.id,
|
||||
})) ?? null,
|
||||
[NotificationTargetGroups.SPECIFIC_ROLE]: [
|
||||
{ label: "Admin", value: "admin" },
|
||||
{ label: "Analyst", value: "analyst" },
|
||||
],
|
||||
[NotificationTargetGroups.SPECIFIC_USERS]:
|
||||
users?.data.users?.map((user) => ({
|
||||
label: user.full_name,
|
||||
value: user.id,
|
||||
})) ?? null,
|
||||
[NotificationTargetGroups.SPECIFIC_CUSTOMER]:
|
||||
customers?.data.customers?.map((customer) => ({
|
||||
label: customer.full_name,
|
||||
value: customer.id,
|
||||
})) ?? null,
|
||||
};
|
||||
|
||||
setRecipient(recipientMaps[type] ?? null);
|
||||
};
|
||||
return {
|
||||
handleSubmit,
|
||||
watch,
|
||||
priorities: getEnumAsArray(NotificationPriorities),
|
||||
handleCancel,
|
||||
router,
|
||||
setValue,
|
||||
reset,
|
||||
register,
|
||||
errors,
|
||||
onSelectTarget,
|
||||
onSubmit,
|
||||
control,
|
||||
recipient,
|
||||
targets: getEnumAsArray(NotificationTargetGroups),
|
||||
types: getEnumAsArray(NotificationTypes),
|
||||
channels: getEnumAsArray(NotificationChannels),
|
||||
};
|
||||
};
|
||||
|
||||
export default useCreateNotificationFormPresenter;
|
||||
Reference in New Issue
Block a user