diff --git a/src/components/shared/profileUpdate/ProfileUpdate.jsx b/src/components/shared/profileUpdate/ProfileUpdate.jsx index 4b47a175..70f7cd31 100644 --- a/src/components/shared/profileUpdate/ProfileUpdate.jsx +++ b/src/components/shared/profileUpdate/ProfileUpdate.jsx @@ -1,6 +1,6 @@ /* eslint-disable no-unused-vars */ import { STATUSCODE } from "@/static/Constants"; -import { completeProfileApiCall } from "@service/MilanApi"; +import { updateUserProfile } from "@service/MilanApi"; import { showSuccessToast } from "@utils/Toasts"; import clsx from "clsx"; import { useState } from "react"; @@ -29,8 +29,8 @@ const ProfileUpdate = ({ setOpenModal, refreshProfileData, profileData }) => { const handleChange = (field) => (event) => { const updatedCredentials = { ...credentials }; - if (field === "description") { - updatedCredentials.description = event.target.value; + if (field === "description" || field === "name") { + updatedCredentials[field] = event.target.value; } else { // For address fields, update the address object inside the credentials updatedCredentials.address[field] = event.target.value; @@ -66,16 +66,13 @@ const ProfileUpdate = ({ setOpenModal, refreshProfileData, profileData }) => { }); }; - const validateForm = async (updatedCredentials) => { + const validateForm = async () => { const newErrors = {}; // Check required fields for top-level fields - const requiredFields = ["description"]; + const requiredFields = ["description", "name"]; requiredFields.forEach((field) => { - if ( - !updatedCredentials[field] || - updatedCredentials[field].trim() === "" - ) { + if (!credentials[field] || credentials[field].trim() === "") { newErrors[field] = `${field} is required.`; } }); @@ -91,62 +88,43 @@ const ProfileUpdate = ({ setOpenModal, refreshProfileData, profileData }) => { ]; addressFields.forEach((field) => { if ( - !updatedCredentials.address[field] || - updatedCredentials.address[field].trim() === "" + !credentials.address[field] || + credentials.address[field].trim() === "" ) { newErrors[`address.${field}`] = `${field} is required.`; } }); // Description length validation - if ( - updatedCredentials.description && - updatedCredentials.description.length > 500 - ) { + if (credentials.description && credentials.description.length > 500) { newErrors.description = "Description cannot be more than 500 characters."; } - if ( - updatedCredentials.description && - updatedCredentials.description.length < 100 - ) { + if (credentials.description && credentials.description.length < 100) { newErrors.description = "Description cannot be less than 100 characters."; } // Pincode validation - if ( - updatedCredentials.address.pincode && - isNaN(updatedCredentials.address.pincode) - ) { + if (credentials.address.pincode && isNaN(credentials.address.pincode)) { newErrors["address.pincode"] = "Pincode must be a valid number."; } setErrors(newErrors); - const data = await completeProfileApiCall({ - credentials: { - ...updatedCredentials, - config: { - hasCompletedProfile: true, - }, - }, + const data = await updateUserProfile({ + credentials, }); if (data.status === STATUSCODE.OK) { showSuccessToast(data?.data?.message); + refreshProfileData(); + setOpenModal(false); return; } return Object.keys(newErrors).length === 0; }; - const clearError = (field) => { - setErrors((prevErrors) => { - const { [field]: ignored, ...rest } = prevErrors; - return rest; - }); - }; - return (
@@ -161,6 +139,10 @@ const ProfileUpdate = ({ setOpenModal, refreshProfileData, profileData }) => {

Edit profile

-
{ - e.preventDefault(); - validateForm(credentials); - }} - > +

Cover Image

diff --git a/src/integrations/ApiEndpoints.js b/src/integrations/ApiEndpoints.js index 004e39d0..9d55b02c 100644 --- a/src/integrations/ApiEndpoints.js +++ b/src/integrations/ApiEndpoints.js @@ -5,7 +5,8 @@ const userEndpoints = { profile: `${API}/user/profile`, update: `${API}/user/update/profile`, report: `${API}/user/report`, - completeProfile: `${API}/user/completeprofile`, + completeProfile: `${API}/user/complete`, + updateProfile: `${API}/user/update`, }; const clubEndpoints = { diff --git a/src/service/MilanApi.js b/src/service/MilanApi.js index 08bcdb24..50c200d6 100644 --- a/src/service/MilanApi.js +++ b/src/service/MilanApi.js @@ -61,7 +61,7 @@ export const ReportProblem = async (credentials) => { } }; -// UPDATE USER +// Complete User Profile export const completeProfileApiCall = async ({ credentials }) => { try { const response = await Axios.patch( @@ -78,6 +78,23 @@ export const completeProfileApiCall = async ({ credentials }) => { } }; +// Update User Profile +export const updateUserProfile = async ({ credentials }) => { + try { + const response = await Axios.patch( + userEndpoints.updateProfile, + credentials, + { + withCredentials: true, + }, + ); + + return response; + } catch (error) { + return error.response; + } +}; + // Google Auth screen export const GoogleAuth = async () => { try {