Skip to content

Commit

Permalink
refactor(Contracts): merchant contract list & language resources (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
ertugrulcan-ays authored Oct 21, 2024
2 parents eb25448 + 91f6014 commit 62a9fe6
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
"use client";
import type { UniRefund_ContractService_ContractsForMerchant_ContractHeaders_ContractHeaderDetailForMerchantDto as ContractHeaderDetailForMerchantDto } from "@ayasofyazilim/saas/ContractService";
import { $UniRefund_ContractService_ContractsForMerchant_ContractHeaders_ContractHeaderDetailForMerchantDto as $ContractHeaderDetailForMerchantDto } from "@ayasofyazilim/saas/ContractService";
import { createZodObject } from "@repo/ayasofyazilim-ui/lib/create-zod-object";
import AutoForm from "@repo/ayasofyazilim-ui/organisms/auto-form";
import {
SectionLayout,
SectionLayoutContent,
} from "@repo/ayasofyazilim-ui/templates/section-layout-v2";
import type { ContractServiceResource } from "src/language-data/ContractService";

interface DetailsProp {
contractHeaderDetails: ContractHeaderDetailForMerchantDto;
partyName: "merchants";
partyId: string;
languageData: ContractServiceResource;
}
export default function Details({ ...props }: DetailsProp) {
const { languageData } = props;
return (
<SectionLayout
defaultActiveSectionId="contract"
sections={[
{
id: "contract",
name: languageData["Contracts.Create.ContractHeader"],
},
{
id: "rebate-setting",
name: languageData["Contracts.Create.RebateSettings"],
disabled: false,
},
{
id: "contract-settings",
name: languageData["Contracts.Create.ContractSettings"],
disabled: false,
},
]}
vertical
>
<ContractSection {...props} />
<RebateSettingsSection {...props} />
{/* <StoresSection {...props} /> */}
<ContractSettingsSection {...props} />
</SectionLayout>
);
}

function ContractSection({ ...props }: DetailsProp) {
const $DetailsSchema = createZodObject(
$ContractHeaderDetailForMerchantDto,
[
"name",
"webSite",
"merchantClassification",
"status",
"isDraft",
"addressCommonData",
"contractHeaderRefundTableHeaders",
],
undefined,
{
merchantBasicInformationDto: ["name", "numberOfStores"],
addressCommonData: [
"countryId",
"regionId",
"cityId",
"districtId",
"neighborhoodId",
"addressLine",
"type",
],
},
);

return (
<SectionLayoutContent sectionId="contract">
<AutoForm
className="grid gap-2 space-y-0 md:grid-cols-2"
fieldConfig={{
isDraft: {
fieldType: "switch",
},
merchantBasicInformationDto: {
className:
"md:col-span-2 md:grid md:grid-cols-2 md:space-y-0 md:gap-2",
},
addressCommonData: {
className: "md:col-span-2",
},
contractHeaderRefundTableHeaders: {
className: "md:col-span-2",
},
}}
formSchema={$DetailsSchema}
values={props.contractHeaderDetails}
/>
</SectionLayoutContent>
);
}

function ContractSettingsSection({ languageData }: DetailsProp) {
return (
<SectionLayoutContent sectionId="contract-settings">
<>{languageData["Contracts.Create.ContractSettings"]}</>
</SectionLayoutContent>
);
}

function RebateSettingsSection({ languageData }: DetailsProp) {
return (
<SectionLayoutContent sectionId="rebate-setting">
<>{languageData["Contracts.Create.RebateSettings"]}</>
</SectionLayoutContent>
);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
import { getResourceData } from "src/language-data/ContractService";
import { getBaseLink } from "src/utils";
import { getMerchantContractHeaderByIdApi } from "src/app/[lang]/app/actions/ContractService/action";
import Details from "./details";

export default function Page({
export default async function Page({
params,
}: {
params: { contractId: string; partyName: string; partyId: string };
}): JSX.Element {
params: {
contractId: string;
partyName: "merchants";
partyId: string;
lang: string;
};
}) {
const contractHeaderDetails = await getMerchantContractHeaderByIdApi(
params.contractId,
);
if (contractHeaderDetails.type !== "success") {
return <>XS</>;
}

const { languageData } = await getResourceData(params.lang);
return (
<>
<div>{params.contractId}</div>
<Details
contractHeaderDetails={contractHeaderDetails.data}
languageData={languageData}
partyId={params.partyId}
partyName={params.partyName}
/>
<div className="hidden" id="page-title">
Edit Contract - {params.contractId}
{languageData["Contracts.Edit.Title"]} - (
{contractHeaderDetails.data.name})
</div>
<div className="hidden" id="page-description">
You can edit contract from here.
{languageData["Contracts.Edit.Description"]}
</div>
<div className="hidden" id="page-back-link">
{getBaseLink(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import DataTable from "@repo/ayasofyazilim-ui/molecules/tables";
import { SectionLayoutContent } from "@repo/ayasofyazilim-ui/templates/section-layout-v2";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { getMerchantContractHeadersByMerchantIdApi } from "src/app/[lang]/app/actions/ContractService/action";
import type { CRMServiceServiceResource } from "src/language-data/CRMService";
import { getBaseLink } from "src/utils";
import { getContractHeadersByMerchantId } from "./action";

export default function Contracts({
languageData,
Expand All @@ -28,7 +28,7 @@ export default function Contracts({
async function getContractsOfMerchant() {
setLoading(true);
try {
const response = await getContractHeadersByMerchantId({
const response = await getMerchantContractHeadersByMerchantIdApi({
id: partyId,
});
if (response.type === "error" || response.type === "api-error") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import type { Dispatch, SetStateAction } from "react";
import { useEffect, useState } from "react";
import Rebate from "src/app/[lang]/app/[type]/settings/templates/rebate/rebate";
import { getRefundTableHeaders } from "src/app/[lang]/app/[type]/settings/templates/refund/action";
import type { ContractServiceResource } from "src/language-data/ContractService";
import {
getContractHeaderMissingStepsById,
postContractHeadersByMerchantId,
} from "../action";
getMerchantContractHeaderMissingStepsByIdApi,
postMerchantContractHeadersByMerchantIdApi,
} from "src/app/[lang]/app/actions/ContractService/action";
import type { ContractServiceResource } from "src/language-data/ContractService";

export default function ContractHeaderForm({
params,
Expand Down Expand Up @@ -92,7 +92,7 @@ export default function ContractHeaderForm({
loading={loading}
setLoading={setLoading}
/>
{/* TODO IMPLEMENT STORES HERE */}
{/* <StoresSection /> */}
<RebateSettingsSection
languageData={languageData}
loading={loading}
Expand Down Expand Up @@ -127,9 +127,10 @@ function ContractSection({
async function fetchContractMissingSteps(): Promise<void> {
setLoading(true);
try {
const missingStepsResponse = await getContractHeaderMissingStepsById({
id: partyId,
});
const missingStepsResponse =
await getMerchantContractHeaderMissingStepsByIdApi({
id: partyId,
});
if (missingStepsResponse.type === "success") {
setMissingSteps(missingStepsResponse.data);
} else {
Expand All @@ -148,14 +149,12 @@ function ContractSection({
): Promise<void> {
toastOnSubmit(data);

const postResponse = await postContractHeadersByMerchantId({
const postResponse = await postMerchantContractHeadersByMerchantIdApi({
id: partyId,
requestBody: data,
});
if (postResponse.type !== "success") {
if (postResponse.type === "api-error") {
toast.error(postResponse.data);
}
if (postResponse.type === "error" || postResponse.type === "api-error") {
toast.error(postResponse.message);
}
toast.success(postResponse.message || postResponse.status);
void fetchContractMissingSteps();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { getBaseLink } from "src/utils";
import { getApiRequests } from "src/app/[lang]/app/actions/api-requests";
import { notFound } from "next/navigation";
import {
getAdressesApi,
getBasicInformationApi,
} from "src/app/[lang]/app/actions/CrmService/actions";
import type { ContractServiceResource } from "src/language-data/ContractService";
import { getResourceData } from "src/language-data/ContractService";
import { getBaseLink } from "src/utils";
import ContractHeaderForm from "./form";

export default async function Page({
Expand All @@ -13,26 +17,27 @@ export default async function Page({
lang: string;
};
}) {
const req = await getApiRequests();
const basicInformation = await req[params.partyName].getBasicInformation({
id: params.partyId,
});
const addresses = await req[params.partyName].getAdresses({
id: params.partyId,
});
const basicInformation = await getBasicInformationApi(
params.partyId,
params.partyName,
);
const addresses = await getAdressesApi(params.partyId, params.partyName);
if (basicInformation.type !== "success" || addresses.type !== "success") {
return notFound();
}
const { languageData } = await getResourceData(params.lang);
return (
<>
<ContractHeaderForm
languageData={languageData}
params={params}
addresses={addresses}
addresses={addresses.data}
// basicInformation={basicInformation}
/>
<PageHeader
languageData={languageData}
params={params}
title={basicInformation.name || params.partyId}
title={basicInformation.data.name || params.partyId}
/>
</>
);
Expand Down
Loading

0 comments on commit 62a9fe6

Please sign in to comment.