Skip to content

Commit

Permalink
feat: add update merchant base to parties (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusualhashash authored Oct 14, 2024
2 parents c4a3fc6 + 121a9bc commit 1f98f24
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { PartyNameType } from "../../types";
import type {
PutAddress,
PutEmail,
PutMerchantBase,
PutMerchantOrganization,
PutName,
PutOrganization,
Expand Down Expand Up @@ -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"]) => {
Expand Down Expand Up @@ -129,6 +136,9 @@ export async function putPartyRequests(
putPersonalSummaries: () => {
//need for type definition
},
putMerchantBase: () => {
//need for type definition
},
},
customs: {
putOrganization: async (form: PutOrganization["data"]) => {
Expand Down Expand Up @@ -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"]) => {
Expand Down Expand Up @@ -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"]) => {
Expand Down Expand Up @@ -271,6 +287,9 @@ export async function putPartyRequests(
putPersonalSummaries: () => {
//need for type definition
},
putMerchantBase: () => {
//need for type definition
},
},
};
return partyRequests[partyType];
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<SectionLayoutContent sectionId="merchant-base">
<AutoForm
formClassName="pb-40"
formSchema={schema}
onSubmit={(values: PutMerchantBase["data"]["requestBody"]) => {
void handleUpdateSubmit(
partyName,
{
action: "merchant-base",
data: {
requestBody: {
...values,
taxOfficeId: getEnumId(
taxOfficesEnum,
values?.taxOfficeId || "",
),
},
id: partyId,
},
},
router,
);
}}
values={{
...individualData,
taxOfficeId: getEnumName(
taxOfficesEnum,
individualData?.taxOfficeId || "",
),
}}
>
<AutoFormSubmit className="float-right">
{languageData.Save}
</AutoFormSubmit>
</AutoForm>
</SectionLayoutContent>
);
}

export default MerchantForm;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 <></>;
Expand All @@ -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</>;
}
Expand Down Expand Up @@ -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 (
<>
<div className="h-full overflow-hidden">
<SectionLayout sections={sections} vertical>
{params.partyName === "merchants" &&
"taxOfficeId" in partyDetailData && (
<MerchantForm
languageData={languageData}
merchantData={partyDetailData}
partyId={params.partyId}
partyName={params.partyName}
taxOfficesEnum={taxOfficesEnum}
/>
)}

{organizationData ? (
<OrganizationForm
languageData={languageData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function SubCompany({
action.unshift(
TableAction_CREATE_ROW_ON_NEW_PAGE(
languageData,
formData,
{ ...formData, translationKey: formData.subEntityName },
`/app/admin/parties/${partyName}/new?parentId=${partyId}`,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
PutApiCrmServiceCustomsByIdEmailsByEmailIdData,
PutApiCrmServiceCustomsByIdOrganizationsByOrganizationIdData,
PutApiCrmServiceCustomsByIdTelephonesByTelephoneIdData,
PutApiCrmServiceMerchantsByIdData,
PutApiCrmServiceMerchantsByIdEmailsByEmailIdData,
PutApiCrmServiceMerchantsByIdIndividualByIndividualIdNameByNameIdData,
PutApiCrmServiceMerchantsByIdIndividualByIndividualIdPersonalSummaryByPersonalSummaryIdData,
Expand Down Expand Up @@ -124,6 +125,10 @@ export interface PutPersonalSummaries {
action: "personal-summaries";
data: PutApiCrmServiceMerchantsByIdIndividualByIndividualIdPersonalSummaryByPersonalSummaryIdData;
}
export interface PutMerchantBase {
action: "merchant-base";
data: PutApiCrmServiceMerchantsByIdData;
}

export type GetPartiesDetailResult =
| UniRefund_CRMService_RefundPoints_RefundPointDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { putParty } from "./action";
import type {
PutAddress,
PutEmail,
PutMerchantBase,
PutName,
PutOrganization,
PutPersonalSummaries,
Expand All @@ -21,7 +22,8 @@ export async function handleUpdateSubmit(
| PutAddress
| PutEmail
| PutName
| PutPersonalSummaries,
| PutPersonalSummaries
| PutMerchantBase,
router: AppRouterInstance,
) {
const response = await putParty(partyName, putData);
Expand Down

0 comments on commit 1f98f24

Please sign in to comment.