-
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(traveller): add form of create new identification (#880)
- Loading branch information
Showing
8 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
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
130 changes: 130 additions & 0 deletions
130
...web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/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,130 @@ | ||
"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: { | ||
containerClassName: "gap-2", | ||
renderer: (props) => ( | ||
<CustomCombobox<CountryDto> | ||
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: { | ||
containerClassName: "gap-2", | ||
renderer: (props) => ( | ||
<CustomCombobox<CountryDto> | ||
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 ( | ||
<AutoForm | ||
className="grid gap-4 space-y-0 pb-4 md:grid-cols-1 lg:grid-cols-2 " | ||
fieldConfig={translatedForm} | ||
formSchema={updateBillingSchema} | ||
onSubmit={(values) => { | ||
void putTravellerPersonalIdentification( | ||
values as UniRefund_TravellerService_PersonalIdentificationCommonDatas_UpsertPersonalIdentificationDto, | ||
); | ||
}} | ||
> | ||
<AutoFormSubmit className="float-right"> | ||
{languageData.Save} | ||
</AutoFormSubmit> | ||
</AutoForm> | ||
); | ||
} |
44 changes: 44 additions & 0 deletions
44
...web/src/app/[lang]/app/[type]/parties/traveller/[travellerId]/identification/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,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 ( | ||
<> | ||
<Form | ||
countryList={{ | ||
data: countryList, | ||
success: countries.type === "success", | ||
}} | ||
languageData={languageData} | ||
travellerId={params.travellerId} | ||
/> | ||
<div className="hidden" id="page-title"> | ||
{`${languageData.Traveller} (${travellerData.personalIdentifications[0].fullName})`} | ||
</div> | ||
<div className="hidden" id="page-description"> | ||
{languageData["Travellers.Create.Identification.Description"]} | ||
</div> | ||
<div className="hidden" id="page-back-link"> | ||
{getBaseLink(`/app/admin/parties/traveller/${params.travellerId}`)} | ||
</div> | ||
</> | ||
); | ||
} |
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