feat(WEB-163): edit profile field validation
This commit is contained in:
+24
-8
@@ -1,25 +1,41 @@
|
||||
"use server"
|
||||
|
||||
// import { editProfileSchema } from "@/components/Forms/Edit/Profile/schema"
|
||||
import { ZodError } from "zod"
|
||||
|
||||
import { editProfileSchema } from "@/components/Forms/Edit/Profile/schema"
|
||||
|
||||
import { type State, Status } from "@/types/components/myPages/myProfile/edit"
|
||||
|
||||
export async function editProfile(_prevState: State, values: FormData) {
|
||||
try {
|
||||
const data = Object.fromEntries(values.entries())
|
||||
const data: Record<string, any> = Object.fromEntries(values.entries())
|
||||
|
||||
/**
|
||||
* TODO: Update profile data when endpoint from
|
||||
* API team is ready
|
||||
*/
|
||||
|
||||
console.info(`EditProfileSchema.Parse Data`)
|
||||
console.info(`Raw Data`)
|
||||
console.log(data)
|
||||
|
||||
return {
|
||||
message: "All good!",
|
||||
status: Status.success,
|
||||
data.address = {
|
||||
city: data["address.city"],
|
||||
countryCode: data["address.countryCode"],
|
||||
streetAddress: data["address.streetAddress"],
|
||||
zipCode: data["address.zipCode"],
|
||||
}
|
||||
const parsedData = editProfileSchema.safeParse(data)
|
||||
if (parsedData.success) {
|
||||
console.info(`Success`)
|
||||
console.log(parsedData.data)
|
||||
return {
|
||||
message: "All good!",
|
||||
status: Status.success,
|
||||
}
|
||||
} else {
|
||||
console.error(parsedData.error)
|
||||
return {
|
||||
message: "Invalid data, parse failed!",
|
||||
status: Status.error,
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof ZodError) {
|
||||
|
||||
Reference in New Issue
Block a user