frontend:chg:generalized form field serialization
This commit is contained in:
@@ -22,10 +22,15 @@ export const actions = {
|
||||
*/
|
||||
updateUser: async ({ request, fetch, cookies, locals }) => {
|
||||
const formData = await request.formData();
|
||||
const firstName = String(formData.get("first_name"));
|
||||
const lastName = String(formData.get("last_name"));
|
||||
const phone = String(formData.get("phone"));
|
||||
const birthDate = String(formData.get("birth_date"));
|
||||
/** @type {Record<string, string>} */
|
||||
const updateData = {};
|
||||
|
||||
// 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/`;
|
||||
|
||||
@@ -36,12 +41,7 @@ export const actions = {
|
||||
"Content-Type": "application/json",
|
||||
Cookie: `jwt=${cookies.get("jwt")}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
phone: phone,
|
||||
birth_date: birthDate,
|
||||
}),
|
||||
body: JSON.stringify(updateData),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
@@ -57,7 +57,14 @@ export const actions = {
|
||||
if (locals.user.date_of_birth) {
|
||||
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}`);
|
||||
},
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user