From ecc3cf1b554304c829f1736b3a28e0097c2be87e Mon Sep 17 00:00:00 2001 From: Asis Ferrer Date: Tue, 16 Jun 2026 11:26:21 +0200 Subject: [PATCH] refactor: rename recipients route to people, update all frontend references --- src/actions/import.actions.ts | 4 +- src/actions/person.actions.ts | 2 +- src/actions/person.messages.ts | 2 +- src/app/(dashboard)/(home)/page.tsx | 12 +- .../assignments/[assignmentId]/edit/page.tsx | 6 +- .../_components/edit.assignment.form.tsx | 4 +- .../_components/new.assignment.form.tsx | 4 +- src/app/(dashboard)/assignments/new/page.tsx | 6 +- src/app/(dashboard)/assignments/page.tsx | 2 +- .../inventory/assets/[assetId]/edit/page.tsx | 6 +- .../assets/_components/edit.asset.form.tsx | 4 +- .../assets/_components/new.asset.form.tsx | 4 +- .../(dashboard)/inventory/assets/new/page.tsx | 6 +- .../[personId]}/edit/page.tsx | 20 +-- .../[personId]}/page.tsx | 36 ++-- .../people/_components/person.copy.ts | 22 +++ .../_components/person.form.tsx} | 87 ++++------ .../{recipients => people}/new/page.tsx | 8 +- .../{recipients => people}/page.tsx | 53 +++--- .../recipients/_components/recipient.copy.ts | 24 --- src/components/layout/addMenu.tsx | 4 +- src/components/layout/sidebar.tsx | 4 +- src/i18n/dictionaries/en.ts | 8 +- src/i18n/dictionaries/es.ts | 8 +- src/schemas/person.schema.ts | 2 +- src/services/assignment.service.ts | 2 +- src/services/person.service.ts | 4 +- src/types/assignment.ts | 2 +- src/types/person.ts | 2 +- src/use-cases/person.use-cases.ts | 6 +- tests/integration/helpers/factories.ts | 4 +- .../use-cases/person.use-cases.test.ts | 2 +- .../assignments/assignment-form-pages.test.ts | 4 +- .../unit/app/people/person-form-pages.test.ts | 127 ++++++++++++++ .../app/people/person-form-wiring.test.ts | 81 +++++++++ tests/unit/app/people/person-pages.test.ts | 163 ++++++++++++++++++ tests/unit/i18n/dictionaries.test.ts | 12 ++ 37 files changed, 553 insertions(+), 194 deletions(-) rename src/app/(dashboard)/{recipients/[recipientId] => people/[personId]}/edit/page.tsx (57%) rename src/app/(dashboard)/{recipients/[recipientId] => people/[personId]}/page.tsx (67%) create mode 100644 src/app/(dashboard)/people/_components/person.copy.ts rename src/app/(dashboard)/{recipients/_components/recipient.form.tsx => people/_components/person.form.tsx} (68%) rename src/app/(dashboard)/{recipients => people}/new/page.tsx (74%) rename src/app/(dashboard)/{recipients => people}/page.tsx (66%) delete mode 100644 src/app/(dashboard)/recipients/_components/recipient.copy.ts create mode 100644 tests/unit/app/people/person-form-pages.test.ts create mode 100644 tests/unit/app/people/person-form-wiring.test.ts create mode 100644 tests/unit/app/people/person-pages.test.ts diff --git a/src/actions/import.actions.ts b/src/actions/import.actions.ts index cdad538..c073b8f 100644 --- a/src/actions/import.actions.ts +++ b/src/actions/import.actions.ts @@ -123,7 +123,7 @@ export async function importItems(formData: ImportFormType) { file: [ "Only one of category or categoryId is allowed, you must select one of them", ], - } + }, } } @@ -342,4 +342,4 @@ export async function importItems(formData: ImportFormType) { success: true, message: "Items imported successfully!", } -} \ No newline at end of file +} diff --git a/src/actions/person.actions.ts b/src/actions/person.actions.ts index 5c5b553..6b074c1 100644 --- a/src/actions/person.actions.ts +++ b/src/actions/person.actions.ts @@ -94,4 +94,4 @@ export async function updatePerson(formData: UpdatePersonFormType) { message: copy.actions.updateFailure, } } -} \ No newline at end of file +} diff --git a/src/actions/person.messages.ts b/src/actions/person.messages.ts index a1f5e8f..fc60ab6 100644 --- a/src/actions/person.messages.ts +++ b/src/actions/person.messages.ts @@ -35,4 +35,4 @@ export function localizePersonFieldErrors( messages.map((message) => localizePersonMessage(message, copy)), ]), ) -} \ No newline at end of file +} diff --git a/src/app/(dashboard)/(home)/page.tsx b/src/app/(dashboard)/(home)/page.tsx index a40ed19..2208fd0 100644 --- a/src/app/(dashboard)/(home)/page.tsx +++ b/src/app/(dashboard)/(home)/page.tsx @@ -1,7 +1,7 @@ import { getI18n } from "@/i18n/server" import { AssetService } from "@/services/asset.service" import { ItemService } from "@/services/item.service" -import { RecipientService } from "@/services/recipient.service" +import { PersonService } from "@/services/person.service" import Card from "./_components/card" @@ -10,7 +10,7 @@ export default async function Home() { const copy = dictionary.dashboardHome const totalItems = await ItemService.findAllItemsCount() const totalAssets = await AssetService.findAllAssetsCount() - const totalRecipients = await RecipientService.findAllRecipientsCount() + const totalPeople = await PersonService.findAllPeopleCount() return (
@@ -65,10 +65,10 @@ export default async function Home() { } /> {copy.edit.title}
{copy.new.title} {assignment?.recipient?.firstName}{" "} diff --git a/src/app/(dashboard)/inventory/assets/[assetId]/edit/page.tsx b/src/app/(dashboard)/inventory/assets/[assetId]/edit/page.tsx index ec94198..6e8746d 100644 --- a/src/app/(dashboard)/inventory/assets/[assetId]/edit/page.tsx +++ b/src/app/(dashboard)/inventory/assets/[assetId]/edit/page.tsx @@ -3,7 +3,7 @@ import { getI18n } from "@/i18n/server" import { AssetService } from "@/services/asset.service" import { ItemService } from "@/services/item.service" -import { RecipientService } from "@/services/recipient.service" +import { PersonService } from "@/services/person.service" import type { AssetWithAssignment } from "@/types" import EditAssetForm from "../../_components/edit.asset.form" @@ -15,7 +15,7 @@ export default async function EditAssetPage({ }) { const { assetId } = await params const items = await ItemService.findAll() - const recipients = await RecipientService.findAll() + const people = await PersonService.findAll() const asset = await AssetService.findById(assetId) const { dictionary } = await getI18n() const copy = dictionary.inventory.assets @@ -31,7 +31,7 @@ export default async function EditAssetPage({ + params: Promise<{ personId: string }> }) { - const { recipientId } = await params + const { personId } = await params const { dictionary } = await getI18n() - const copy = dictionary.inventory.recipients - const recipient = await RecipientService.findById(recipientId) + const copy = dictionary.inventory.people + const person = await PersonService.findById(personId) - if (!recipient) { + if (!person) { return
{copy.edit.notFound}
} @@ -22,8 +22,8 @@ export default async function RecipientEditPage({

{copy.edit.title}

- + params: Promise<{ personId: string }> }) { - const { recipientId } = await params + const { personId } = await params const { dictionary } = await getI18n() - const copy = dictionary.inventory.recipients + const copy = dictionary.inventory.people const assignmentCopy = dictionary.inventory.assignments - const recipient = await RecipientService.findById(recipientId) - const assignments = await AssignmentService.findAllByRecipient(recipientId) + const person = await PersonService.findById(personId) + const assignments = await AssignmentService.findAllByPerson(personId) - if (!recipient) { + if (!person) { return
{copy.detail.notFound}
} @@ -25,33 +25,25 @@ export default async function RecipientInfoPage({
- - {`${recipient.firstName} ${recipient.lastName}`} - + {`${person.firstName} ${person.lastName}`}
-
- - {copy.detail.labels.username} - - {recipient.username} -
{copy.detail.labels.email} - {recipient.email} + {person.email}
{copy.detail.labels.phone} - {recipient.phone} + {person.phone}
{copy.detail.labels.department} - {formatRecipientDepartment( - recipient.department, + {formatPersonDepartment( + person.department, copy.departments, copy.fallback, )} diff --git a/src/app/(dashboard)/people/_components/person.copy.ts b/src/app/(dashboard)/people/_components/person.copy.ts new file mode 100644 index 0000000..be84458 --- /dev/null +++ b/src/app/(dashboard)/people/_components/person.copy.ts @@ -0,0 +1,22 @@ +import type { Dictionary } from "@/i18n/dictionaries" + +export type PersonListCopy = Dictionary["inventory"]["people"]["list"] +export type PersonDetailCopy = Dictionary["inventory"]["people"]["detail"] +export type PersonFormCopy = Dictionary["inventory"]["people"]["form"] +export type PersonDepartmentCopy = + Dictionary["inventory"]["people"]["departments"] +export type PersonFallbackCopy = Dictionary["inventory"]["people"]["fallback"] + +export function formatPersonDepartment( + department: string | null | undefined, + departmentCopy: PersonDepartmentCopy, + fallbackCopy: PersonFallbackCopy, +) { + if (!department) { + return fallbackCopy.unknownDepartment + } + + return department in departmentCopy + ? departmentCopy[department as keyof PersonDepartmentCopy] + : fallbackCopy.unknownDepartment +} diff --git a/src/app/(dashboard)/recipients/_components/recipient.form.tsx b/src/app/(dashboard)/people/_components/person.form.tsx similarity index 68% rename from src/app/(dashboard)/recipients/_components/recipient.form.tsx rename to src/app/(dashboard)/people/_components/person.form.tsx index e79fbfe..2a450c8 100644 --- a/src/app/(dashboard)/recipients/_components/recipient.form.tsx +++ b/src/app/(dashboard)/people/_components/person.form.tsx @@ -5,42 +5,39 @@ import { useRouter } from "next/navigation" import { useMemo } from "react" import { useForm } from "react-hook-form" import { toast } from "sonner" -import { - createNewRecipient, - updateRecipient, -} from "@/actions/recipient.actions" +import { createNewPerson, updatePerson } from "@/actions/person.actions" import { SubmitButton, type SubmitButtonCopy, } from "@/components/forms/submitButton" -import { RECIPIENT_DEPARTMENTS } from "@/lib/constants" +import { PERSON_DEPARTMENTS } from "@/lib/constants" import { - buildCreateRecipientSchema, - buildUpdateRecipientSchema, - type CreateRecipientFormType, - type RecipientSchemaCopy, - type UpdateRecipientFormType, -} from "@/schemas/recipient.schema" -import type { Recipient } from "@/types" + buildCreatePersonSchema, + buildUpdatePersonSchema, + type CreatePersonFormType, + type PersonSchemaCopy, + type UpdatePersonFormType, +} from "@/schemas/person.schema" +import type { Person } from "@/types" import { - formatRecipientDepartment, - type RecipientDepartmentCopy, - type RecipientFallbackCopy, - type RecipientFormCopy, -} from "./recipient.copy" + formatPersonDepartment, + type PersonDepartmentCopy, + type PersonFallbackCopy, + type PersonFormCopy, +} from "./person.copy" -interface RecipientFormProps { - initialData?: Recipient +interface PersonFormProps { + initialData?: Person mode?: "create" | "edit" - formCopy: RecipientFormCopy - schemaCopy: RecipientSchemaCopy - departmentCopy: RecipientDepartmentCopy - fallbackCopy: RecipientFallbackCopy + formCopy: PersonFormCopy + schemaCopy: PersonSchemaCopy + departmentCopy: PersonDepartmentCopy + fallbackCopy: PersonFallbackCopy submitButtonCopy: SubmitButtonCopy } -export default function RecipientForm({ +export default function PersonForm({ initialData, mode = "create", formCopy, @@ -48,13 +45,13 @@ export default function RecipientForm({ departmentCopy, fallbackCopy, submitButtonCopy, -}: RecipientFormProps) { +}: PersonFormProps) { const router = useRouter() const schema = useMemo( () => mode === "create" - ? buildCreateRecipientSchema(schemaCopy) - : buildUpdateRecipientSchema(schemaCopy), + ? buildCreatePersonSchema(schemaCopy) + : buildUpdatePersonSchema(schemaCopy), [mode, schemaCopy], ) @@ -63,11 +60,10 @@ export default function RecipientForm({ handleSubmit, setError, formState: { errors, isSubmitting, isSubmitSuccessful }, - } = useForm({ + } = useForm({ resolver: zodResolver(schema), defaultValues: { id: initialData?.id || "", - username: initialData?.username || "", firstName: initialData?.firstName || "", lastName: initialData?.lastName || "", department: initialData?.department || "OTHER", @@ -76,16 +72,16 @@ export default function RecipientForm({ }, }) - const onSubmit = async (formData: CreateRecipientFormType) => { + const onSubmit = async (formData: CreatePersonFormType) => { const response = mode === "create" - ? await createNewRecipient(formData) - : await updateRecipient(formData as UpdateRecipientFormType) + ? await createNewPerson(formData) + : await updatePerson(formData as UpdatePersonFormType) if (response?.errors) { Object.entries(response.errors).forEach(([fieldName, messages]) => { messages.forEach((msg: string) => { - setError(fieldName as keyof CreateRecipientFormType, { + setError(fieldName as keyof CreatePersonFormType, { type: "server", message: msg, }) @@ -97,28 +93,13 @@ export default function RecipientForm({ if (response?.success) { toast.success(response.message) - router.push("/recipients") + router.push("/people") } } return (
-
- - - {errors?.username && ( -

{errors.username.message}

- )} -