-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Contract): convert sections to page (#904)
- Loading branch information
Showing
13 changed files
with
395 additions
and
333 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...]/[partyId]/contracts/[contractId]/[section]/contract-settings/contract-settings-page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { UniRefund_ContractService_ContractsForMerchant_ContractHeaders_ContractHeaderDetailForMerchantDto as ContractHeaderDetailForMerchantDto } from "@ayasofyazilim/saas/ContractService"; | ||
import { notFound } from "next/navigation"; | ||
import type { UniRefund_LocationService_AddressCommonDatas_AddressCommonDataDto as AddressCommonDataDto } from "@ayasofyazilim/saas/LocationService"; | ||
import { getResourceData } from "src/language-data/ContractService"; | ||
import { getMerchantContractHeaderContractSettingsByHeaderIdApi } from "src/app/[lang]/app/actions/ContractService/action"; | ||
import { ContractSettings } from "./contract-settings"; | ||
|
||
export default async function ContractSettingsPage({ | ||
lang, | ||
contractId, | ||
contractHeaderDetails, | ||
addressList, | ||
}: { | ||
lang: string; | ||
contractId: string; | ||
contractHeaderDetails: ContractHeaderDetailForMerchantDto; | ||
addressList: AddressCommonDataDto[]; | ||
}) { | ||
const { languageData } = await getResourceData(lang); | ||
const contractSettings = | ||
await getMerchantContractHeaderContractSettingsByHeaderIdApi({ | ||
id: contractId, | ||
}); | ||
if (contractSettings.type !== "success") return notFound(); | ||
return ( | ||
<ContractSettings | ||
addressList={addressList} | ||
contractHeaderDetails={contractHeaderDetails} | ||
contractSettings={contractSettings.data} | ||
lang={lang} | ||
languageData={languageData} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...rties/[partyName]/[partyId]/contracts/[contractId]/[section]/contract/contract-header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use client"; | ||
|
||
import type { | ||
UniRefund_ContractService_ContractsForMerchant_ContractHeaders_ContractHeaderDetailForMerchantDto as ContractHeaderDetailForMerchantDto, | ||
UniRefund_ContractService_ContractsForMerchant_ContractHeaders_ContractHeaderForMerchantUpdateDto as ContractHeaderForMerchantUpdateDto, | ||
} from "@ayasofyazilim/saas/ContractService"; | ||
import type { UniRefund_LocationService_AddressCommonDatas_AddressCommonDataDto as AddressCommonDataDto } from "@ayasofyazilim/saas/LocationService"; | ||
import type { ContractServiceResource } from "src/language-data/ContractService"; | ||
import ContractHeaderForm from "../../../contract-header-form"; | ||
|
||
export function ContractHeader({ | ||
contractHeaderDetails, | ||
partyName, | ||
partyId, | ||
addressList, | ||
languageData, | ||
}: { | ||
contractHeaderDetails: ContractHeaderDetailForMerchantDto; | ||
partyName: "merchants"; | ||
partyId: string; | ||
addressList: AddressCommonDataDto[]; | ||
languageData: ContractServiceResource; | ||
}) { | ||
const refundTableHeaders = | ||
contractHeaderDetails.contractHeaderRefundTableHeaders.map((header) => { | ||
return { | ||
refundTableHeaderId: header.refundTableHeader.id, | ||
validFrom: header.validFrom, | ||
validTo: header.validTo, | ||
isDefault: header.isDefault, | ||
}; | ||
}); | ||
return ( | ||
<ContractHeaderForm<ContractHeaderForMerchantUpdateDto> | ||
addresses={addressList} | ||
formData={{ | ||
...contractHeaderDetails, | ||
status: contractHeaderDetails.status || "None", | ||
addressCommonDataId: contractHeaderDetails.addressCommonData.id, | ||
refundTableHeaders, | ||
}} | ||
formType="Update" | ||
languageData={languageData} | ||
partyId={partyId} | ||
partyName={partyName} | ||
/> | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
...parties/[partyName]/[partyId]/contracts/[contractId]/[section]/contract/contract-page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { UniRefund_ContractService_ContractsForMerchant_ContractHeaders_ContractHeaderDetailForMerchantDto as ContractHeaderDetailForMerchantDto } from "@ayasofyazilim/saas/ContractService"; | ||
import type { UniRefund_LocationService_AddressCommonDatas_AddressCommonDataDto as AddressCommonDataDto } from "@ayasofyazilim/saas/LocationService"; | ||
import { getResourceData } from "src/language-data/ContractService"; | ||
import { ContractHeader } from "./contract-header"; | ||
|
||
export default async function ContractPage({ | ||
lang, | ||
partyName, | ||
partyId, | ||
contractHeaderDetails, | ||
addressList, | ||
}: { | ||
lang: string; | ||
partyName: "merchants"; | ||
partyId: string; | ||
contractHeaderDetails: ContractHeaderDetailForMerchantDto; | ||
addressList: AddressCommonDataDto[]; | ||
}) { | ||
const { languageData } = await getResourceData(lang); | ||
return ( | ||
<ContractHeader | ||
addressList={addressList} | ||
contractHeaderDetails={contractHeaderDetails} | ||
languageData={languageData} | ||
partyId={partyId} | ||
partyName={partyName} | ||
/> | ||
); | ||
} |
161 changes: 161 additions & 0 deletions
161
...[lang]/app/[type]/parties/[partyName]/[partyId]/contracts/[contractId]/[section]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipTrigger, | ||
} from "@/components/ui/tooltip"; | ||
import { | ||
SectionLayout, | ||
SectionLayoutContent, | ||
} from "@repo/ayasofyazilim-ui/templates/section-layout-v2"; | ||
import { Circle } from "lucide-react"; | ||
import Link from "next/link"; | ||
import { notFound } from "next/navigation"; | ||
import { | ||
getMerchantContractHeaderByIdApi, | ||
getMerchantContractHeaderMissingStepsByIdApi, | ||
} from "src/app/[lang]/app/actions/ContractService/action"; | ||
import { | ||
getResourceData, | ||
type ContractServiceResource, | ||
} from "src/language-data/ContractService"; | ||
import { getBaseLink } from "src/utils"; | ||
import { getAdressesApi } from "src/app/[lang]/app/actions/CrmService/actions"; | ||
import ContractPage from "./contract/contract-page"; | ||
import ContractSettingsPage from "./contract-settings/contract-settings-page"; | ||
import RebateSettingsPage from "./rebate-settings/rebate-settings-page"; | ||
|
||
export default async function Page({ | ||
params, | ||
}: { | ||
params: { | ||
lang: string; | ||
contractId: string; | ||
partyName: "merchants"; | ||
partyId: string; | ||
section: string; | ||
}; | ||
}) { | ||
const { lang, contractId, partyId, partyName, section } = params; | ||
const { languageData } = await getResourceData(lang); | ||
const missingSteps = await getMerchantContractHeaderMissingStepsByIdApi({ | ||
id: contractId, | ||
}); | ||
const contractHeaderDetails = | ||
await getMerchantContractHeaderByIdApi(contractId); | ||
|
||
const addressList = await getAdressesApi(partyId, partyName); | ||
|
||
if ( | ||
missingSteps.type !== "success" || | ||
contractHeaderDetails.type !== "success" || | ||
addressList.type !== "success" | ||
) { | ||
return notFound(); | ||
} | ||
return ( | ||
<> | ||
<SectionLayout | ||
defaultActiveSectionId={section} | ||
linkElement={Link} | ||
sections={[ | ||
{ | ||
id: "contract", | ||
link: "contract", | ||
name: languageData["Contracts.Create.ContractHeader"], | ||
disabled: false, | ||
}, | ||
{ | ||
id: "rebate-settings", | ||
link: "rebate-settings", | ||
disabled: false, | ||
...setSectionOptions( | ||
"RebateSettings", | ||
languageData["Contracts.Create.RebateSettings"], | ||
languageData, | ||
missingSteps.data, | ||
), | ||
}, | ||
{ | ||
id: "contract-settings", | ||
link: "contract-settings", | ||
disabled: false, | ||
...setSectionOptions( | ||
"ContractSetting", | ||
languageData["Contracts.Create.ContractSettings"], | ||
languageData, | ||
missingSteps.data, | ||
), | ||
}, | ||
]} | ||
vertical | ||
> | ||
<SectionLayoutContent sectionId={section}> | ||
{section === "contract" && ( | ||
<ContractPage | ||
{...params} | ||
addressList={addressList.data} | ||
contractHeaderDetails={contractHeaderDetails.data} | ||
/> | ||
)} | ||
{section === "contract-settings" && ( | ||
<ContractSettingsPage | ||
{...params} | ||
addressList={addressList.data} | ||
contractHeaderDetails={contractHeaderDetails.data} | ||
/> | ||
)} | ||
{section === "rebate-settings" && <RebateSettingsPage {...params} />} | ||
</SectionLayoutContent> | ||
</SectionLayout> | ||
<div className="hidden" id="page-title"> | ||
{languageData["Contracts.Edit.Title"]} - ( | ||
{contractHeaderDetails.data.name}) | ||
</div> | ||
<div className="hidden" id="page-description"> | ||
{languageData["Contracts.Edit.Description"]} | ||
</div> | ||
<div className="hidden" id="page-back-link"> | ||
{getBaseLink(`/app/admin/parties/${partyName}/${partyId}`)} | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
function BadgeWithTooltip({ | ||
label, | ||
languageData, | ||
}: { | ||
label: string; | ||
languageData: ContractServiceResource; | ||
}) { | ||
return ( | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<div className="flex items-center gap-2"> | ||
<Circle className="text-destructive w-3" /> | ||
<span>{label}</span> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
{languageData["Contracts.MissingSteps.Missing"]} | ||
</TooltipContent> | ||
</Tooltip> | ||
); | ||
} | ||
function setSectionOptions( | ||
key: string, | ||
label: string, | ||
languageData: ContractServiceResource, | ||
missingSteps: string[] = [], | ||
) { | ||
const isMissingStep = missingSteps.includes(key); | ||
const options = { | ||
name: label, | ||
className: isMissingStep ? "data-[active=false]:text-xs" : "", | ||
}; | ||
if (isMissingStep) | ||
Object.assign(options, { | ||
children: <BadgeWithTooltip label={label} languageData={languageData} />, | ||
}); | ||
return options; | ||
} |
Oops, something went wrong.