From cb5391ec766995f67ee9cb0737b97b6e7202b065 Mon Sep 17 00:00:00 2001 From: yusualhashash Date: Mon, 25 Nov 2024 09:54:45 +0300 Subject: [PATCH 1/5] feat: add create identification button --- .../parties/traveller/[travellerId]/form.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/form.tsx b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/form.tsx index 9f58b0fb2..644c25fce 100644 --- a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/form.tsx +++ b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/form.tsx @@ -12,6 +12,7 @@ import { $UniRefund_TravellerService_PersonalSummaries_UpsertPersonalSummaryDto, } from "@ayasofyazilim/saas/TravellerService"; import { createZodObject } from "@repo/ayasofyazilim-ui/lib/create-zod-object"; +import jsonToCsv from "@repo/ayasofyazilim-ui/lib/json-to-csv"; import DataTable from "@repo/ayasofyazilim-ui/molecules/tables"; import AutoForm, { AutoFormSubmit, @@ -31,6 +32,7 @@ import { putTravellerPersonalSummaryApi, } from "src/app/[lang]/app/actions/TravellerService/put-actions"; import type { TravellerServiceResource } from "src/language-data/TravellerService"; +import { getBaseLink } from "src/utils"; export default function Page({ languageData, @@ -120,6 +122,25 @@ export default function Page({ > { + jsonToCsv( + travellerData.personalIdentifications, + "Identifications", + ); + }, + type: "Action", + }, + ]} columnsData={{ type: "Auto", data: { @@ -160,7 +181,7 @@ export default function Page({ "Travellers.Identifications.Delete.Success" ], ); - router.back(); + router.refresh(); } }, ); From 92f7d36beba2cbd9906f38110e851229b757c441 Mon Sep 17 00:00:00 2001 From: yusualhashash Date: Mon, 25 Nov 2024 09:55:37 +0300 Subject: [PATCH 2/5] feat: add frm of create new identification --- .../[travellerId]/identification/new/form.tsx | 128 ++++++++++++++++++ .../[travellerId]/identification/new/page.tsx | 44 ++++++ 2 files changed, 172 insertions(+) create mode 100644 apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/form.tsx create mode 100644 apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/page.tsx diff --git a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/form.tsx b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/form.tsx new file mode 100644 index 000000000..21d9ea263 --- /dev/null +++ b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/form.tsx @@ -0,0 +1,128 @@ +"use client"; + +import { toast } from "@/components/ui/sonner"; +import type { UniRefund_TravellerService_PersonalIdentificationCommonDatas_UpsertPersonalIdentificationDto } from "@ayasofyazilim/saas/TravellerService"; +import { $UniRefund_TravellerService_PersonalIdentificationCommonDatas_UpsertPersonalIdentificationDto } from "@ayasofyazilim/saas/TravellerService"; +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 type { CountryDto } from "src/app/[lang]/app/actions/LocationService/types"; +import { putTravellerPersonalIdentificationApi } from "src/app/[lang]/app/actions/TravellerService/put-actions"; +import type { TravellerServiceResource } from "src/language-data/TravellerService"; + +const updateBillingSchema = createZodObject( + $UniRefund_TravellerService_PersonalIdentificationCommonDatas_UpsertPersonalIdentificationDto, + [ + "travelDocumentNumber", + "firstName", + "lastName", + "middleName", + "issueDate", + "expirationDate", + "birthDate", + "nationalityCountryCode2", + "residenceCountryCode2", + "identificationType", + ], +); + +export default function Form({ + languageData, + travellerId, + countryList, +}: { + languageData: TravellerServiceResource; + travellerId: string; + countryList: { data: CountryDto[]; success: boolean }; +}) { + const router = useRouter(); + async function putTravellerPersonalIdentification( + data: UniRefund_TravellerService_PersonalIdentificationCommonDatas_UpsertPersonalIdentificationDto, + ) { + const response = await putTravellerPersonalIdentificationApi({ + id: travellerId, + requestBody: data, + }); + if (response.type === "success") { + toast.success( + response.message || + languageData["Travellers.Identifications.Update.Success"], + ); + router.back(); + router.refresh(); + } else { + toast.error( + `${response.status}: ${ + response.message || + languageData["Travellers.Identifications.Update.Error"] + }`, + ); + } + } + + const translatedForm = createFieldConfigWithResource({ + schema: + $UniRefund_TravellerService_PersonalIdentificationCommonDatas_UpsertPersonalIdentificationDto, + resources: languageData, + name: "Form.personalIdentification", + extend: { + nationalityCountryCode2: { + renderer: (props) => ( + + childrenProps={props} + disabled={!countryList.success} + emptyValue={ + countryList.success + ? languageData["Country.Select"] + : languageData["Country.Fetch.Fail"] + } + list={countryList.data} + searchPlaceholder={languageData["Select.Placeholder"]} + searchResultLabel={languageData["Select.ResultLabel"]} + selectIdentifier="code2" + selectLabel="name" + /> + ), + }, + residenceCountryCode2: { + renderer: (props) => ( + + childrenProps={props} + disabled={!countryList.success} + emptyValue={ + countryList.success + ? languageData["Country.Select"] + : languageData["Country.Fetch.Fail"] + } + list={countryList.data} + searchPlaceholder={languageData["Select.Placeholder"]} + searchResultLabel={languageData["Select.ResultLabel"]} + selectIdentifier="code2" + selectLabel="name" + /> + ), + }, + }, + }); + + return ( + { + void putTravellerPersonalIdentification( + values as UniRefund_TravellerService_PersonalIdentificationCommonDatas_UpsertPersonalIdentificationDto, + ); + }} + > + + {languageData.Save} + + + ); +} diff --git a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/page.tsx b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/page.tsx new file mode 100644 index 000000000..af67181e6 --- /dev/null +++ b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/page.tsx @@ -0,0 +1,44 @@ +"use server"; + +import type { UniRefund_TravellerService_Travellers_TravellerDetailProfileDto } from "@ayasofyazilim/saas/TravellerService"; +import { getResourceData } from "src/language-data/TravellerService"; +import { getTravellersDetailsApi } from "src/app/[lang]/app/actions/TravellerService/actions"; +import { getCountriesApi } from "src/app/[lang]/app/actions/LocationService/actions"; +import { getBaseLink } from "src/utils"; +import Form from "./form"; + +export default async function Page({ + params, +}: { + params: { travellerId: string; lang: string }; +}) { + const { languageData } = await getResourceData(params.lang); + const Traveller = await getTravellersDetailsApi(params.travellerId); + const countries = await getCountriesApi(); + const countryList = + (countries.type === "success" && countries.data.items) || []; + const travellerData = + Traveller.data as UniRefund_TravellerService_Travellers_TravellerDetailProfileDto; + + return ( + <> +
+
+ {`${languageData.Traveller} (${travellerData.personalIdentifications[0].fullName})`} +
+
+ {languageData["Travellers.Create.Identification.Description"]} +
+ + + ); +} From 40b3c1418b4a24b0e67ecc6d7c2f3c515ad63559 Mon Sep 17 00:00:00 2001 From: yusualhashash Date: Mon, 25 Nov 2024 09:56:21 +0300 Subject: [PATCH 3/5] chore: add translation --- apps/web/src/language-data/TravellerService/resources/en.json | 2 ++ apps/web/src/language-data/TravellerService/resources/tr.json | 2 ++ 2 files changed, 4 insertions(+) diff --git a/apps/web/src/language-data/TravellerService/resources/en.json b/apps/web/src/language-data/TravellerService/resources/en.json index e4fe9a583..cb761d33c 100644 --- a/apps/web/src/language-data/TravellerService/resources/en.json +++ b/apps/web/src/language-data/TravellerService/resources/en.json @@ -1,6 +1,7 @@ { "Travellers": "Travellers", "Traveller": "Traveller", + "Travellers.New.Identification": "New identification", "Travellers.Edit.Description": "You can update the traveller's details from here.", "Travellers.Identifications.Edit.Description": "You can update the traveller's personal identification from here.", "Travellers.Personal.Identifications": "Personal Identifications", @@ -21,6 +22,7 @@ "Travellers.Identifications.Delete.Success": "Personal identification deleted successfully", "Travellers.Identifications.Update.Success": "personal identification Updated successfully", "Travellers.Identifications.Update.Error": "Failed to update personal identification", + "Travellers.Create.Identification.Description": "You can add a new personal identification from here.", "Form.personalIdentification": "Personal Information", "Form.personalIdentification.firstName": "First Name", diff --git a/apps/web/src/language-data/TravellerService/resources/tr.json b/apps/web/src/language-data/TravellerService/resources/tr.json index e6c1653a0..b820918fc 100644 --- a/apps/web/src/language-data/TravellerService/resources/tr.json +++ b/apps/web/src/language-data/TravellerService/resources/tr.json @@ -1,6 +1,7 @@ { "Travellers": "Yolcular", "Traveller": "Yolcu", + "Travellers.New.Identification": "Yeni kimlik", "Travellers.Edit.Description": "Yolcu bilgilerini buradan güncelleyebilirsiniz.", "Travellers.Identifications.Edit.Description": "Yolcu kişisel bilgilerini buradan güncelleyebilirsiniz.", "Travellers.Personal.Identifications": "Kişisel Kimlikler", @@ -21,6 +22,7 @@ "Travellers.Identifications.Delete.Success": "Kişisel kimlik basarılıyla silindi", "Travellers.Identifications.Update.Success": "Kişisel kimlik başarıyla güncellendi", "Travellers.Identifications.Update.Error": "Kişisel kimlik güncellenirken bir hata oluştu.", + "Travellers.Create.Identification.Description": "Buradan yeni bir kişisel kimlik ekleyebilirsiniz.", "Form.personalIdentification": "Kişisel Bilgiler", "Form.personalIdentification.firstName": "Ad", From 5caa968170eca42f302223a1483ff148bf103367 Mon Sep 17 00:00:00 2001 From: yusualhashash Date: Mon, 25 Nov 2024 10:08:12 +0300 Subject: [PATCH 4/5] chore: review requested --- .../identification/[identificationId]/page.tsx | 4 ++-- .../traveller/[travellerId]/identification/new/page.tsx | 4 ++-- .../app/[type]/parties/traveller/[travellerId]/page.tsx | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/[identificationId]/page.tsx b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/[identificationId]/page.tsx index 44369ccca..74b616b76 100644 --- a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/[identificationId]/page.tsx +++ b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/[identificationId]/page.tsx @@ -13,10 +13,10 @@ export default async function Page({ params: { travellerId: string; lang: string }; }) { const { languageData } = await getResourceData(params.lang); - const Traveller = await getTravellersDetailsApi(params.travellerId); + const traveller = await getTravellersDetailsApi(params.travellerId); const countries = await getCountriesApi(); const travellerData = - Traveller.data as UniRefund_TravellerService_Travellers_TravellerDetailProfileDto; + traveller.data as UniRefund_TravellerService_Travellers_TravellerDetailProfileDto; const countryList = (countries.type === "success" && countries.data.items) || []; diff --git a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/page.tsx b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/page.tsx index af67181e6..21920f91e 100644 --- a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/page.tsx +++ b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/page.tsx @@ -13,12 +13,12 @@ export default async function Page({ params: { travellerId: string; lang: string }; }) { const { languageData } = await getResourceData(params.lang); - const Traveller = await getTravellersDetailsApi(params.travellerId); + const traveller = await getTravellersDetailsApi(params.travellerId); const countries = await getCountriesApi(); const countryList = (countries.type === "success" && countries.data.items) || []; const travellerData = - Traveller.data as UniRefund_TravellerService_Travellers_TravellerDetailProfileDto; + traveller.data as UniRefund_TravellerService_Travellers_TravellerDetailProfileDto; return ( <> diff --git a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/page.tsx b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/page.tsx index 98b893ee8..dd693471d 100644 --- a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/page.tsx +++ b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/page.tsx @@ -10,17 +10,17 @@ export default async function Page({ params: { travellerId: string; lang: string }; }) { const { languageData } = await getResourceData(params.lang); - const Traveller = await getTravellersDetailsApi(params.travellerId); + const traveller = await getTravellersDetailsApi(params.travellerId); - if (Traveller.type !== "success") { + if (traveller.type !== "success") { return (
- {Traveller.type + Traveller.message || + {traveller.type + traveller.message || languageData["Travellers.Fetch.Fail"]}
); } - const travellerData = Traveller.data; + const travellerData = traveller.data; return ( <> From 6467c2880a2d1020b4f34c63fad3264938f2e041 Mon Sep 17 00:00:00 2001 From: yusualhashash Date: Mon, 25 Nov 2024 10:28:13 +0300 Subject: [PATCH 5/5] chore: review requested --- .../[travellerId]/identification/[identificationId]/form.tsx | 3 +++ .../traveller/[travellerId]/identification/new/form.tsx | 2 ++ 2 files changed, 5 insertions(+) diff --git a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/[identificationId]/form.tsx b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/[identificationId]/form.tsx index 5cade8a93..9b3e17c70 100644 --- a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/[identificationId]/form.tsx +++ b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/[identificationId]/form.tsx @@ -72,6 +72,7 @@ export default function Form({ name: "Form.personalIdentification", extend: { nationalityCountryCode2: { + containerClassName: "gap-2", renderer: (props) => ( childrenProps={props} @@ -90,6 +91,7 @@ export default function Form({ ), }, residenceCountryCode2: { + containerClassName: "gap-2", renderer: (props) => ( childrenProps={props} @@ -114,6 +116,7 @@ export default function Form({ { void putTravellerPersonalIdentification( diff --git a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/form.tsx b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/form.tsx index 21d9ea263..8f494698f 100644 --- a/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/form.tsx +++ b/apps/web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/new/form.tsx @@ -71,6 +71,7 @@ export default function Form({ name: "Form.personalIdentification", extend: { nationalityCountryCode2: { + containerClassName: "gap-2", renderer: (props) => ( childrenProps={props} @@ -89,6 +90,7 @@ export default function Form({ ), }, residenceCountryCode2: { + containerClassName: "gap-2", renderer: (props) => ( childrenProps={props}