feat: add conditional signup values
This commit is contained in:
67
actions/registerUserBookingFlow.ts
Normal file
67
actions/registerUserBookingFlow.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
"use server"
|
||||
|
||||
import { parsePhoneNumber } from "libphonenumber-js"
|
||||
import { z } from "zod"
|
||||
|
||||
import { serviceServerActionProcedure } from "@/server/trpc"
|
||||
|
||||
import { phoneValidator } from "@/utils/phoneValidator"
|
||||
|
||||
const registerUserPayload = z.object({
|
||||
firstName: z.string(),
|
||||
lastName: z.string(),
|
||||
dateOfBirth: z.string(),
|
||||
address: z.object({
|
||||
countryCode: z.string(),
|
||||
zipCode: z.string(),
|
||||
}),
|
||||
email: z.string(),
|
||||
phoneNumber: phoneValidator("Phone is required"),
|
||||
})
|
||||
|
||||
export const registerUserBookingFlow = serviceServerActionProcedure
|
||||
.input(registerUserPayload)
|
||||
.mutation(async function ({ ctx, input }) {
|
||||
const payload = {
|
||||
...input,
|
||||
language: ctx.lang,
|
||||
phoneNumber: parsePhoneNumber(input.phoneNumber)
|
||||
.formatNational()
|
||||
.replace(/\s+/g, ""),
|
||||
}
|
||||
|
||||
// TODO: Consume the API to register the user as soon as passwordless signup is enabled.
|
||||
// let apiResponse
|
||||
// try {
|
||||
// apiResponse = await api.post(api.endpoints.v1.profile, {
|
||||
// body: payload,
|
||||
// headers: {
|
||||
// Authorization: `Bearer ${ctx.serviceToken}`,
|
||||
// },
|
||||
// })
|
||||
// } catch (error) {
|
||||
// console.error("Unexpected error", error)
|
||||
// return { success: false, error: "Unexpected error" }
|
||||
// }
|
||||
|
||||
// if (!apiResponse.ok) {
|
||||
// const text = await apiResponse.text()
|
||||
// console.error(text)
|
||||
// console.error(
|
||||
// "registerUserBookingFlow api error",
|
||||
// JSON.stringify({
|
||||
// query: input,
|
||||
// error: {
|
||||
// status: apiResponse.status,
|
||||
// statusText: apiResponse.statusText,
|
||||
// error: text,
|
||||
// },
|
||||
// })
|
||||
// )
|
||||
// return { success: false, error: "API error" }
|
||||
// }
|
||||
// const json = await apiResponse.json()
|
||||
// console.log("registerUserBookingFlow: json", json)
|
||||
|
||||
return { success: true, data: payload }
|
||||
})
|
||||
Reference in New Issue
Block a user