big boi refactor to customer inof from passenger info

This commit is contained in:
user
2025-10-20 21:46:26 +03:00
parent 2cc0ca4c51
commit 2fdb934ec9
53 changed files with 702 additions and 2068 deletions

View File

@@ -1,14 +1,13 @@
<script lang="ts">
import LabelWrapper from "$lib/components/atoms/label-wrapper.svelte";
import Title from "$lib/components/atoms/title.svelte";
import Input from "$lib/components/ui/input/input.svelte";
import * as Select from "$lib/components/ui/select";
import { COUNTRIES_SELECT } from "$lib/core/countries";
import { capitalize } from "$lib/core/string.utils";
import type { PassengerPII } from "$lib/domains/ticket/data/entities/create.entities";
import type { CustomerInfo } from "$lib/domains/ticket/data/entities/create.entities";
import { billingDetailsVM } from "./billing.details.vm.svelte";
let { info = $bindable() }: { info: PassengerPII } = $props();
let { info = $bindable() }: { info: CustomerInfo } = $props();
function onSubmit(e: SubmitEvent) {
e.preventDefault();

View File

@@ -1,15 +1,15 @@
import { Gender } from "$lib/domains/ticket/data/entities/index";
import {
passengerPIIModel,
type PassengerPII,
customerInfoModel,
type CustomerInfo,
} from "$lib/domains/ticket/data/entities/create.entities";
import { Gender } from "$lib/domains/ticket/data/entities/index";
import { z } from "zod";
export class BillingDetailsViewModel {
// @ts-ignore
billingDetails = $state<PassengerPII>(undefined);
billingDetails = $state<CustomerInfo>(undefined);
piiErrors = $state<Partial<Record<keyof PassengerPII, string>>>({});
piiErrors = $state<Partial<Record<keyof CustomerInfo, string>>>({});
constructor() {
this.reset();
@@ -34,28 +34,28 @@ export class BillingDetailsViewModel {
zipCode: "",
address: "",
address2: "",
} as PassengerPII;
} as CustomerInfo;
this.piiErrors = {};
}
setPII(info: PassengerPII) {
setPII(info: CustomerInfo) {
this.billingDetails = info;
}
validatePII(info: PassengerPII) {
validatePII(info: CustomerInfo) {
try {
const result = passengerPIIModel.parse(info);
const result = customerInfoModel.parse(info);
this.piiErrors = {};
return result;
} catch (error) {
if (error instanceof z.ZodError) {
this.piiErrors = error.errors.reduce(
(acc, curr) => {
const path = curr.path[0] as keyof PassengerPII;
const path = curr.path[0] as keyof CustomerInfo;
acc[path] = curr.message;
return acc;
},
{} as Record<keyof PassengerPII, string>,
{} as Record<keyof CustomerInfo, string>,
);
}
return null;