From 51b7d3be2445f2364704652629d788bd69df3249 Mon Sep 17 00:00:00 2001 From: Eren Date: Mon, 14 Oct 2024 13:55:06 +0300 Subject: [PATCH] feat: add update merchant base to parties --- .../parties/[partyName]/[partyId]/action.ts | 26 +++++- .../[partyName]/[partyId]/merchant/form.tsx | 81 +++++++++++++++++++ .../parties/[partyName]/[partyId]/page.tsx | 35 ++++++-- .../[partyId]/subcompanies-table/form.tsx | 2 +- .../parties/[partyName]/[partyId]/types.ts | 5 ++ .../parties/[partyName]/[partyId]/utils.tsx | 4 +- 6 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/merchant/form.tsx diff --git a/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/action.ts b/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/action.ts index 2e0d2d8be..2a40abef6 100644 --- a/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/action.ts +++ b/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/action.ts @@ -4,6 +4,7 @@ import type { PartyNameType } from "../../types"; import type { PutAddress, PutEmail, + PutMerchantBase, PutMerchantOrganization, PutName, PutOrganization, @@ -81,6 +82,12 @@ export async function putPartyRequests( }, ); }, + putMerchantBase: async (form: PutMerchantBase["data"]) => { + return await client.merchant.putApiCrmServiceMerchantsById({ + requestBody: form.requestBody, + id: form.id, + }); + }, }, "refund-points": { putOrganization: async (form: PutOrganization["data"]) => { @@ -129,6 +136,9 @@ export async function putPartyRequests( putPersonalSummaries: () => { //need for type definition }, + putMerchantBase: () => { + //need for type definition + }, }, customs: { putOrganization: async (form: PutOrganization["data"]) => { @@ -175,6 +185,9 @@ export async function putPartyRequests( putPersonalSummaries: () => { //need for type definition }, + putMerchantBase: () => { + //need for type definition + }, }, "tax-free": { putOrganization: async (form: PutOrganization["data"]) => { @@ -223,6 +236,9 @@ export async function putPartyRequests( putPersonalSummaries: () => { //need for type definition }, + putMerchantBase: () => { + //need for type definition + }, }, "tax-offices": { putOrganization: async (form: PutOrganization["data"]) => { @@ -271,6 +287,9 @@ export async function putPartyRequests( putPersonalSummaries: () => { //need for type definition }, + putMerchantBase: () => { + //need for type definition + }, }, }; return partyRequests[partyType]; @@ -284,12 +303,15 @@ export async function putParty( | PutAddress | PutEmail | PutName - | PutPersonalSummaries, + | PutPersonalSummaries + | PutMerchantBase, ) { const client = await putPartyRequests(partyType); try { let response; - if (params.action === "organization") { + if (params.action === "merchant-base") { + response = await client.putMerchantBase(params.data); + } else if (params.action === "organization") { response = await client.putOrganization(params.data); } else if (params.action === "name") { response = await client.putName(params.data); diff --git a/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/merchant/form.tsx b/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/merchant/form.tsx new file mode 100644 index 000000000..4c3b12c17 --- /dev/null +++ b/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/merchant/form.tsx @@ -0,0 +1,81 @@ +"use client"; + +import type { UniRefund_CRMService_Merchants_UpdateMerchantDto } from "@ayasofyazilim/saas/CRMService"; +import { $UniRefund_CRMService_Merchants_MerchantBaseDto } from "@ayasofyazilim/saas/CRMService"; +import { createZodObject } from "@repo/ayasofyazilim-ui/lib/create-zod-object"; +import AutoForm, { + AutoFormSubmit, +} from "@repo/ayasofyazilim-ui/organisms/auto-form"; +import { SectionLayoutContent } from "@repo/ayasofyazilim-ui/templates/section-layout-v2"; +import { getEnumId, getEnumName } from "@repo/ui/utils/table/table-utils"; +import { useRouter } from "next/navigation"; +import type { CRMServiceServiceResource } from "src/language-data/CRMService"; +import type { PutMerchantBase } from "../types"; +import { handleUpdateSubmit } from "../utils"; + +function MerchantForm({ + languageData, + partyName, + partyId, + taxOfficesEnum, + merchantData: individualData, +}: { + languageData: CRMServiceServiceResource; + partyName: "merchants"; + partyId: string; + taxOfficesEnum: { name: string; id: string }[]; + merchantData: UniRefund_CRMService_Merchants_UpdateMerchantDto | undefined; +}) { + const router = useRouter(); + + const schema = createZodObject( + $UniRefund_CRMService_Merchants_MerchantBaseDto, + ["typeCode", "taxOfficeId"], + { + taxOfficeId: { + type: "enum", + data: taxOfficesEnum.map((i) => i.name), + }, + }, + ); + return ( + + { + void handleUpdateSubmit( + partyName, + { + action: "merchant-base", + data: { + requestBody: { + ...values, + taxOfficeId: getEnumId( + taxOfficesEnum, + values?.taxOfficeId || "", + ), + }, + id: partyId, + }, + }, + router, + ); + }} + values={{ + ...individualData, + taxOfficeId: getEnumName( + taxOfficesEnum, + individualData?.taxOfficeId || "", + ), + }} + > + + {languageData.Save} + + + + ); +} + +export default MerchantForm; diff --git a/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/page.tsx b/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/page.tsx index 2fa287684..b53c5ed31 100644 --- a/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/page.tsx +++ b/apps/web/src/app/[lang]/app/[type]/parties/[partyName]/[partyId]/page.tsx @@ -5,15 +5,16 @@ import { getResourceData } from "src/language-data/CRMService"; import { getCities } from "../../../action"; import { dataConfigOfParties } from "../../table-data"; import type { PartyNameType } from "../../types"; -import { getPartyDetail } from "../action"; +import { getPartyDetail, getPartyTableData } from "../action"; import Address from "./address/form"; import Email from "./email/form"; +import Individual from "./individuals-table/form"; +import MerchantForm from "./merchant/form"; import NameForm from "./name/form"; import OrganizationForm from "./organization/form"; -import Telephone from "./telephone/form"; -import SubCompany from "./subcompanies-table/form"; -import Individual from "./individuals-table/form"; import PersonalSummariesForm from "./personal-summaries/form"; +import SubCompany from "./subcompanies-table/form"; +import Telephone from "./telephone/form"; export default async function Page({ params, @@ -26,6 +27,7 @@ export default async function Page({ }) { const { languageData } = await getResourceData(params.lang); const formData = dataConfigOfParties[params.partyName]; + const taxOffices = await getPartyTableData("tax-offices", 0, 100); if (params.partyName === "individuals") { return <>; @@ -38,7 +40,8 @@ export default async function Page({ partyDetail.type !== "success" || !partyDetail.data || cities.type !== "success" || - !("entityInformations" in partyDetail.data) + !("entityInformations" in partyDetail.data) || + taxOffices.type !== "success" ) { return <>Not found; } @@ -75,17 +78,39 @@ export default async function Page({ }); sections.unshift({ name: languageData.Name, id: "name" }); } + if (params.partyName === "merchants") { + sections.unshift({ + name: languageData.Merchants, + id: "merchant-base", + }); + } const citiesEnum = cities.data.items?.map((item) => ({ name: item.name || "", id: item.id || "", })) || []; + const taxOfficesEnum = + taxOffices.data.items?.map((item) => ({ + name: item.name || "", + id: item.id || "", + })) || []; return ( <>
+ {params.partyName === "merchants" && + "taxOfficeId" in partyDetailData && ( + + )} + {organizationData ? (