-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(finance/billing): add new and update forms for billing page (#853)
- Loading branch information
Showing
12 changed files
with
305 additions
and
6 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
apps/web/src/app/[lang]/app/[type]/finance/billing/[billingId]/form.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,65 @@ | ||
"use client"; | ||
|
||
import { toast } from "@/components/ui/sonner"; | ||
import type { | ||
UniRefund_FinanceService_Billings_BillingDto, | ||
UniRefund_FinanceService_Billings_UpdateBillingDto, | ||
} from "@ayasofyazilim/saas/FinanceService"; | ||
import { $UniRefund_FinanceService_Billings_UpdateBillingDto } from "@ayasofyazilim/saas/FinanceService"; | ||
import { createZodObject } from "@repo/ayasofyazilim-ui/lib/create-zod-object"; | ||
import AutoForm, { | ||
AutoFormSubmit, | ||
createFieldConfigWithResource, | ||
} from "@repo/ayasofyazilim-ui/organisms/auto-form"; | ||
import { putBillingApi } from "src/app/[lang]/app/actions/FinanceService/put-actions"; | ||
import type { FinanceServiceResource } from "src/language-data/FinanceService"; | ||
|
||
const updateBillingSchema = createZodObject( | ||
$UniRefund_FinanceService_Billings_UpdateBillingDto, | ||
); | ||
|
||
export default function Form({ | ||
billingId, | ||
languageData, | ||
billingData, | ||
}: { | ||
billingId: string; | ||
languageData: FinanceServiceResource; | ||
billingData: UniRefund_FinanceService_Billings_BillingDto; | ||
}) { | ||
async function updateBilling( | ||
data: UniRefund_FinanceService_Billings_UpdateBillingDto, | ||
) { | ||
const response = await putBillingApi({ | ||
id: billingId, | ||
requestBody: data, | ||
}); | ||
if (response.type === "success") { | ||
toast.success(languageData["Billing.Update.Success"]); | ||
} else { | ||
toast.error(response.type + response.message || ["Billing.Update.Fail"]); | ||
} | ||
} | ||
|
||
const translatedForm = createFieldConfigWithResource({ | ||
schema: $UniRefund_FinanceService_Billings_UpdateBillingDto, | ||
resources: languageData, | ||
}); | ||
|
||
return ( | ||
<AutoForm | ||
fieldConfig={translatedForm} | ||
formSchema={updateBillingSchema} | ||
onSubmit={(formdata) => { | ||
void updateBilling( | ||
formdata as UniRefund_FinanceService_Billings_UpdateBillingDto, | ||
); | ||
}} | ||
values={billingData} | ||
> | ||
<AutoFormSubmit className="float-right"> | ||
{languageData["Edit.Save"]} | ||
</AutoFormSubmit> | ||
</AutoForm> | ||
); | ||
} |
31 changes: 31 additions & 0 deletions
31
apps/web/src/app/[lang]/app/[type]/finance/billing/[billingId]/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,31 @@ | ||
"use server"; | ||
import { getBillingDetailApi } from "src/app/[lang]/app/actions/FinanceService/actions"; | ||
import { getResourceData } from "src/language-data/FinanceService"; | ||
import Form from "./form"; | ||
|
||
export default async function Page({ | ||
params, | ||
}: { | ||
params: { lang: string; billingId: string }; | ||
}) { | ||
const { languageData } = await getResourceData(params.lang); | ||
const billing = await getBillingDetailApi(params.billingId); | ||
|
||
if (billing.type !== "success") { | ||
return ( | ||
<div className="error-message"> | ||
{billing.type + billing.message || languageData["Billing.Fetch.Fail"]} | ||
</div> | ||
); | ||
} | ||
|
||
const billingList = billing.data; | ||
|
||
return ( | ||
<Form | ||
billingData={billingList} | ||
billingId={params.billingId} | ||
languageData={languageData} | ||
/> | ||
); | ||
} |
95 changes: 95 additions & 0 deletions
95
apps/web/src/app/[lang]/app/[type]/finance/billing/new/form.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,95 @@ | ||
"use client"; | ||
import { toast } from "@/components/ui/sonner"; | ||
import type { UniRefund_CRMService_Merchants_MerchantProfileDto } from "@ayasofyazilim/saas/CRMService"; | ||
import type { UniRefund_FinanceService_Billings_CreateBillingDto } from "@ayasofyazilim/saas/FinanceService"; | ||
import { $UniRefund_FinanceService_Billings_CreateBillingDto } from "@ayasofyazilim/saas/FinanceService"; | ||
import { createZodObject } from "@repo/ayasofyazilim-ui/lib/create-zod-object"; | ||
import AutoForm, { | ||
AutoFormSubmit, | ||
createFieldConfigWithResource, | ||
CustomCombobox, | ||
} from "@repo/ayasofyazilim-ui/organisms/auto-form"; | ||
import { useRouter } from "next/navigation"; | ||
import { postBillingApi } from "src/app/[lang]/app/actions/FinanceService/post-actions"; | ||
import type { CRMServiceServiceResource } from "src/language-data/CRMService"; | ||
import type { FinanceServiceResource } from "src/language-data/FinanceService"; | ||
import { getBaseLink } from "src/utils"; | ||
|
||
const billingSchema = createZodObject( | ||
$UniRefund_FinanceService_Billings_CreateBillingDto, | ||
); | ||
|
||
export default function Page({ | ||
languageData, | ||
merchants, | ||
}: { | ||
languageData: { | ||
crm: CRMServiceServiceResource; | ||
finance: FinanceServiceResource; | ||
}; | ||
merchants: { | ||
success: boolean; | ||
data: UniRefund_CRMService_Merchants_MerchantProfileDto[]; | ||
}; | ||
}) { | ||
const router = useRouter(); | ||
|
||
async function createBilling( | ||
data: UniRefund_FinanceService_Billings_CreateBillingDto, | ||
) { | ||
const response = await postBillingApi({ requestBody: data }); | ||
if (response.type === "error" || response.type === "api-error") { | ||
toast.error( | ||
response.type + | ||
(response.message || languageData.finance["Billing.New.Error"]), | ||
); | ||
} else { | ||
toast.success([languageData.finance["Billing.New.Success"]]); | ||
router.push(getBaseLink(`/app/admin/finance/billing`)); | ||
} | ||
} | ||
|
||
const translatedForm = createFieldConfigWithResource({ | ||
schema: $UniRefund_FinanceService_Billings_CreateBillingDto, | ||
resources: languageData.finance, | ||
extend: { | ||
merchantId: { | ||
renderer: (props) => { | ||
return ( | ||
<CustomCombobox<UniRefund_CRMService_Merchants_MerchantProfileDto> | ||
childrenProps={props} | ||
disabled={!merchants.success} | ||
emptyValue={ | ||
merchants.success | ||
? languageData.crm["Merchant.Select"] | ||
: languageData.crm["Merchants.Fetch.Fail"] | ||
} | ||
list={merchants.data} | ||
searchPlaceholder={languageData.finance["Select.Placeholder"]} | ||
searchResultLabel={languageData.finance["Select.ResultLabel"]} | ||
selectIdentifier="id" | ||
selectLabel="name" | ||
/> | ||
); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
return ( | ||
<AutoForm | ||
fieldConfig={translatedForm} | ||
formSchema={billingSchema} | ||
onSubmit={(val) => { | ||
void createBilling( | ||
val as UniRefund_FinanceService_Billings_CreateBillingDto, | ||
); | ||
}} | ||
stickyChildren | ||
> | ||
<AutoFormSubmit className="float-right px-8 py-4"> | ||
{languageData.finance.Save} | ||
</AutoFormSubmit> | ||
</AutoForm> | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
apps/web/src/app/[lang]/app/[type]/finance/billing/new/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 @@ | ||
"use server"; | ||
|
||
import { getMerchantsApi } from "src/app/[lang]/app/actions/CrmService/actions"; | ||
import { getResourceData as getFinanceResources } from "src/language-data/FinanceService"; | ||
import { getResourceData as getCRMResources } from "src/language-data/CRMService"; | ||
import Form from "./form"; | ||
|
||
export default async function Page({ params }: { params: { lang: string } }) { | ||
const { languageData: financeLanguageData } = await getFinanceResources( | ||
params.lang, | ||
); | ||
const { languageData: crmLanguageData } = await getCRMResources(params.lang); | ||
const merchant = await getMerchantsApi(); | ||
const merchantsList = | ||
(merchant.type === "success" && merchant.data.items) || []; | ||
|
||
return ( | ||
<Form | ||
languageData={{ | ||
finance: financeLanguageData, | ||
crm: crmLanguageData, | ||
}} | ||
merchants={{ | ||
data: merchantsList, | ||
success: merchant.type === "success", | ||
}} | ||
/> | ||
); | ||
} |
5 changes: 2 additions & 3 deletions
5
apps/web/src/app/[lang]/app/actions/FinanceService/actions.ts
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
14 changes: 14 additions & 0 deletions
14
apps/web/src/app/[lang]/app/actions/FinanceService/post-actions.ts
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,14 @@ | ||
"use server"; | ||
import type { PostApiFinanceServiceBillingsData } from "@ayasofyazilim/saas/FinanceService"; | ||
import { structuredError, structuredResponse } from "src/lib"; | ||
import { getApiRequests } from "../api-requests"; | ||
|
||
export async function postBillingApi(data: PostApiFinanceServiceBillingsData) { | ||
try { | ||
const requests = await getApiRequests(); | ||
const dataResponse = await requests.billing.post(data); | ||
return structuredResponse(dataResponse); | ||
} catch (error) { | ||
return structuredError(error); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
apps/web/src/app/[lang]/app/actions/FinanceService/put-actions.ts
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,16 @@ | ||
"use server"; | ||
import type { PutApiFinanceServiceBillingsByIdData } from "@ayasofyazilim/saas/FinanceService"; | ||
import { structuredError, structuredResponse } from "src/lib"; | ||
import { getApiRequests } from "../api-requests"; | ||
|
||
export async function putBillingApi( | ||
data: PutApiFinanceServiceBillingsByIdData, | ||
) { | ||
try { | ||
const requests = await getApiRequests(); | ||
const dataResponse = await requests.billing.put(data); | ||
return structuredResponse(dataResponse); | ||
} catch (error) { | ||
return structuredError(error); | ||
} | ||
} |
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
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
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
17 changes: 16 additions & 1 deletion
17
apps/web/src/language-data/FinanceService/resources/en.json
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 |
---|---|---|
@@ -1,3 +1,18 @@ | ||
{ | ||
"Billing.New": "New Billing" | ||
"Billing.New": "New Billing", | ||
"Billing.New.Error": "Failed to add Billing", | ||
"Billing.New.Success": " Billing Added Successfully", | ||
"Billing.Update.Success": "Billing Updated Successfully", | ||
"Billing.Update.Fail": "Failed to update Billing", | ||
"Billing.Fetch.Fail": "An error occurred while fetching the billing data. Please try again later.", | ||
|
||
"Form.merchantId": "Merchant Name", | ||
"Form.date": "Date", | ||
"Form.number": "Number", | ||
"Form.dueDate": "Due Date", | ||
"Form.total": "Total", | ||
"Form.unpaid": "Unpaid", | ||
"Form.status": "Status", | ||
"Form.period": "Period", | ||
"Form.paymentStatus": "Payment Status" | ||
} |
17 changes: 16 additions & 1 deletion
17
apps/web/src/language-data/FinanceService/resources/tr.json
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 |
---|---|---|
@@ -1,3 +1,18 @@ | ||
{ | ||
"Billing.New": "Yeni fatura" | ||
"Billing.New": "Yeni fatura", | ||
"Billing.New.Error": "Fatura eklenirken bir hata oluştu", | ||
"Billing.New.Success": "Fatura başarıyla eklendi", | ||
"Billing.Update.Success": "Fatura basarıyla guncellendi", | ||
"Billing.Update.Fail": "Fatura guncellenirken bir hata olustu", | ||
"Billing.Fetch.Fail": "Fatura verileri getirilirken bir hata oluştu. Lütfen daha sonra tekrar deneyin.", | ||
|
||
"Form.merchantId": "Mağaza Adı", | ||
"Form.date": "Tarih", | ||
"Form.number": "Numara", | ||
"Form.dueDate": "Vade Tarihi", | ||
"Form.total": "Toplam", | ||
"Form.unpaid": "Ödenmemiş", | ||
"Form.status": "Durum", | ||
"Form.period": "Dönem", | ||
"Form.paymentStatus": "Ödeme Durumu" | ||
} |