cleanup: ckflow, order, checkout page
This commit is contained in:
4
apps/frontend/src/lib/domains/checkout/sid.store.ts
Normal file
4
apps/frontend/src/lib/domains/checkout/sid.store.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { nanoid } from "nanoid/non-secure";
|
||||
import { writable } from "svelte/store";
|
||||
|
||||
export const checkoutSessionIdStore = writable(nanoid());
|
||||
@@ -435,7 +435,7 @@ export class CheckoutFlowRepository {
|
||||
.where(eq(checkoutFlowSession.flowId, flowId))
|
||||
.execute();
|
||||
|
||||
// If shadow passenger info is provided, sync it
|
||||
// If shadow info is provided, sync it
|
||||
if (payload.personalInfo) {
|
||||
await this.syncPersonalInfo(flowId, payload.personalInfo);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ import {
|
||||
type PendingActions,
|
||||
} from "$lib/domains/ckflow/data/entities";
|
||||
import type { CustomerInfoModel } from "$lib/domains/customerinfo/data";
|
||||
import { customerInfoModel } from "$lib/domains/customerinfo/data";
|
||||
import { customerInfoVM } from "$lib/domains/customerinfo/view/customerinfo.vm.svelte";
|
||||
import {
|
||||
CheckoutStep,
|
||||
type OrderPriceDetailsModel,
|
||||
} from "$lib/domains/order/data/entities";
|
||||
import { customerInfoModel } from "$lib/domains/passengerinfo/data/entities";
|
||||
import { passengerInfoVM } from "$lib/domains/passengerinfo/view/passenger.info.vm.svelte";
|
||||
import type { PaymentInfoPayload } from "$lib/domains/paymentinfo/data/entities";
|
||||
import { PaymentMethod } from "$lib/domains/paymentinfo/data/entities";
|
||||
import { productStore } from "$lib/domains/product/store";
|
||||
@@ -529,17 +529,19 @@ export class CKFlowViewModel {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get primary passenger's PII
|
||||
const primaryPassengerInfo =
|
||||
passengerInfoVM.passengerInfos.length > 0
|
||||
? passengerInfoVM.passengerInfos[0].passengerPii
|
||||
: undefined;
|
||||
const personalInfo = customerInfoVM.customerInfo;
|
||||
if (!personalInfo) {
|
||||
toast.error("Could not find customer info", {
|
||||
description: "Please try again later or contact support",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const out = await api.ckflow.executePrePaymentStep.mutate({
|
||||
flowId: this.flowId!,
|
||||
payload: {
|
||||
initialUrl: "",
|
||||
personalInfo: primaryPassengerInfo,
|
||||
personalInfo: personalInfo,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ export const orderRouter = createTRPCRouter({
|
||||
return { error: out.error };
|
||||
}
|
||||
|
||||
Logger.info(`Creating passenger infos with oid: ${out.data}`);
|
||||
Logger.info(`Creating customer infos with oid: ${out.data}`);
|
||||
const pOut = await pc.createPassengerInfos(
|
||||
input.passengerInfos,
|
||||
out.data.id,
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
import { billingDetailsVM } from "$lib/domains/checkout/payment-info-section/billing.details.vm.svelte";
|
||||
import { ckFlowVM } from "$lib/domains/ckflow/view/ckflow.vm.svelte";
|
||||
import { customerInfoVM } from "$lib/domains/customerinfo/view/customerinfo.vm.svelte";
|
||||
import {
|
||||
createOrderPayloadModel,
|
||||
OrderCreationStep,
|
||||
} from "$lib/domains/order/data/entities";
|
||||
import { passengerInfoVM } from "$lib/domains/passengerinfo/view/passenger.info.vm.svelte";
|
||||
import type { FlightTicket } from "$lib/domains/ticket/data/entities";
|
||||
import { productStore } from "$lib/domains/product/store";
|
||||
import { trpcApiStore } from "$lib/stores/api";
|
||||
import type { EmailAccountPayload } from "@pkg/logic/domains/account/data/entities";
|
||||
import { toast } from "svelte-sonner";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
export class CreateOrderViewModel {
|
||||
orderStep = $state(OrderCreationStep.ACCOUNT_SELECTION);
|
||||
|
||||
accountInfo = $state<EmailAccountPayload>({ email: "", password: "" });
|
||||
accountInfoOk = $state(false);
|
||||
|
||||
passengerInfosOk = $state(false);
|
||||
|
||||
ticketInfo = $state<FlightTicket | undefined>(undefined);
|
||||
ticketInfoOk = $state(false);
|
||||
|
||||
loading = $state(true);
|
||||
|
||||
setStep(step: OrderCreationStep) {
|
||||
@@ -74,6 +68,10 @@ export class CreateOrderViewModel {
|
||||
}
|
||||
|
||||
const parsed = createOrderPayloadModel.safeParse({
|
||||
product: get(productStore),
|
||||
productId: get(productStore)?.id,
|
||||
customerInfo: customerInfoVM.customerInfo,
|
||||
paymentInfo: billingDetailsVM.billingDetails,
|
||||
orderModel: {
|
||||
basePrice,
|
||||
displayPrice,
|
||||
@@ -81,9 +79,6 @@ export class CreateOrderViewModel {
|
||||
flightTicketInfoId: 0,
|
||||
emailAccountId: 0,
|
||||
},
|
||||
emailAccountInfo: this.accountInfo,
|
||||
flightTicketInfo: this.ticketInfo!,
|
||||
passengerInfos: passengerInfoVM.passengerInfos,
|
||||
flowId: ckFlowVM.flowId,
|
||||
});
|
||||
if (parsed.error) {
|
||||
|
||||
Reference in New Issue
Block a user