frontend:chg:generalized form field serialization
This commit is contained in:
@@ -22,10 +22,15 @@ export const actions = {
|
|||||||
*/
|
*/
|
||||||
updateUser: async ({ request, fetch, cookies, locals }) => {
|
updateUser: async ({ request, fetch, cookies, locals }) => {
|
||||||
const formData = await request.formData();
|
const formData = await request.formData();
|
||||||
const firstName = String(formData.get("first_name"));
|
/** @type {Record<string, string>} */
|
||||||
const lastName = String(formData.get("last_name"));
|
const updateData = {};
|
||||||
const phone = String(formData.get("phone"));
|
|
||||||
const birthDate = String(formData.get("birth_date"));
|
// Convert FormData to a plain object
|
||||||
|
formData.forEach((value, key) => {
|
||||||
|
if (typeof value === "string" && value !== "") {
|
||||||
|
updateData[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const apiURL = `${BASE_API_URI}/backend/users/update/`;
|
const apiURL = `${BASE_API_URI}/backend/users/update/`;
|
||||||
|
|
||||||
@@ -36,12 +41,7 @@ export const actions = {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Cookie: `jwt=${cookies.get("jwt")}`,
|
Cookie: `jwt=${cookies.get("jwt")}`,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(updateData),
|
||||||
first_name: firstName,
|
|
||||||
last_name: lastName,
|
|
||||||
phone: phone,
|
|
||||||
birth_date: birthDate,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
@@ -57,7 +57,14 @@ export const actions = {
|
|||||||
if (locals.user.date_of_birth) {
|
if (locals.user.date_of_birth) {
|
||||||
locals.user.date_of_birth = response["date_of_birth"].split("T")[0];
|
locals.user.date_of_birth = response["date_of_birth"].split("T")[0];
|
||||||
}
|
}
|
||||||
|
if (locals.user.membership?.start_date) {
|
||||||
|
locals.user.membership.start_date =
|
||||||
|
locals.user.membership.start_date.split("T")[0];
|
||||||
|
}
|
||||||
|
if (locals.user.membership?.end_date) {
|
||||||
|
locals.user.membership.end_date =
|
||||||
|
locals.user.membership.end_date.split("T")[0];
|
||||||
|
}
|
||||||
throw redirect(303, `/auth/about/${response.id}`);
|
throw redirect(303, `/auth/about/${response.id}`);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user