diff --git a/src/component/settings/ProfileForm.jsx b/src/component/settings/ProfileForm.jsx
index 7645a25..b45be14 100644
--- a/src/component/settings/ProfileForm.jsx
+++ b/src/component/settings/ProfileForm.jsx
@@ -52,7 +52,7 @@ export default function ProfileForm({data}) {
},
onSuccess: (res) => {
if(res.data.resultCode != '0'){
- throw({message: res?.data?.resultDescription ? res?.data?.resultDescription : 'En error occured'})
+ throw({message: res?.data?.resultDescription ? res?.data?.resultDescription : 'An error occured'})
}
const account_name = res?.data?.personal_data?.account_name
dispatch(updateUserDetails({ account_name }));
diff --git a/src/component/settings/ProfileImage.jsx b/src/component/settings/ProfileImage.jsx
new file mode 100644
index 0000000..114c5a2
--- /dev/null
+++ b/src/component/settings/ProfileImage.jsx
@@ -0,0 +1,117 @@
+import React, { memo, useRef, useState } from 'react'
+// import { useSelector } from 'react-redux';
+import getImage from '../../utils/getImage';
+import { useMutation, useQueryClient } from '@tanstack/react-query';
+import { uploadProfileImg } from '../../services/services';
+import queryKeys from '../../services/queryKeys';
+
+const ProfileImage = memo(({intialData}) => {
+
+ const queryClient = useQueryClient()
+
+ const [selectedImg, setSelectedImg] = useState(null)
+
+ // const {userDetails} = useSelector((state) => state?.userDetails); // CHECKS FOR ACTIVE USER DETAILS
+ const avtarImage = "avtar/merms-user.png";
+
+ // browser profile img
+ const browserImg = useRef(null);
+ const browseProfileImg = () => {
+ browserImg.current.click();
+ };
+
+ const profileImgChangeHandler = (event) => {
+ setSelectedImg(event.target.files[0])
+ }
+
+ const uploadProfileMutation = useMutation({
+ mutationFn: (fields) => {
+ if(!fields.img){
+ throw new Error('Please, select an image')
+ }
+ return uploadProfileImg(fields)
+ },
+ onSuccess: (res) => {
+ if(res.data.resultCode != '0'){
+ throw({message: res?.data?.resultDescription ? res?.data?.resultDescription : 'An error occured'})
+ }
+ // const account_name = res?.data?.personal_data?.account_name
+ // dispatch(updateUserDetails({ account_name }));
+ },
+ onSettled: ()=>{
+ setTimeout(() => {
+ queryClient.refetchQueries({
+ queryKey: [...queryKeys.profile_data], // type: 'active', // exact: true,
+ })
+ uploadProfileMutation.reset()
+ }, 3000);
+ }
+ })
+
+ const proceedToUpload = () => {
+ let reqData = {
+ token: localStorage.getItem('token'), // USER TOKEN
+ uid: localStorage.getItem('uid'), // USER UID
+ img: selectedImg
+ }
+ // console.log('reqData', reqData)
+ uploadProfileMutation.mutate(reqData)
+ }
+
+ return (
+
+
+
+
+
+

+
profileImgChangeHandler(e)}
+ id='profile-image'
+ />
+
+
+
{intialData?.personal_data?.lastname} {intialData?.personal_data?.firstname}
+
+
+
+
+
+
+
+
+
+
+
+ {selectedImg &&
+
+
+
+ }
+ {/* success or error message */}
+ {(uploadProfileMutation.isSuccess || uploadProfileMutation.isError) &&
+
+
+ {uploadProfileMutation.isSuccess ? 'Uploaded successfully' : uploadProfileMutation.error.message}
+
+
+ }
+
+
+
+ )
+ }
+)
+
+export default ProfileImage
diff --git a/src/component/settings/Settings.jsx b/src/component/settings/Settings.jsx
index c7b4bb7..4f69dc9 100644
--- a/src/component/settings/Settings.jsx
+++ b/src/component/settings/Settings.jsx
@@ -6,9 +6,9 @@ import { useQuery } from "@tanstack/react-query";
import { profileDetails } from "../../services/services";
import ProfileForm from "./ProfileForm";
import LinksForm from "./LinksForm";
+import ProfileImage from "./ProfileImage";
export default function Settings() {
- const avtarImage = "avtar/merms-user.png";
const [intialData, setInitialData] = useState({
external_links: {},
@@ -59,36 +59,7 @@ export default function Settings() {
-
-
-
-
-
- {/*

*/}
-
})
-
-
-
{intialData?.personal_data?.lastname} {intialData?.personal_data?.firstname}
-
-
-
-
-
-
-
-
-
-
-
- {/*
*/}
- {/* */}
- {/*
*/}
-
-
-
+
diff --git a/src/services/services.js b/src/services/services.js
index bd6919d..9b4616c 100644
--- a/src/services/services.js
+++ b/src/services/services.js
@@ -23,7 +23,16 @@ axios.interceptors.request.use(
const postAuxEnd = (path, postData, media=false) => {
const basePath = media ? process.env.REACT_APP_MAIN_API : process.env.REACT_APP_MAIN_API
- return axios.post(`${basePath}${path}`, postData).then(res => {
+ let newPostData = {}
+ if(!media){
+ newPostData = {...postData}
+ }else{
+ newPostData = new FormData();
+ for (let data in postData) {
+ newPostData.append(data, postData[data]);
+ }
+ }
+ return axios.post(`${basePath}${path}`, newPostData).then(res => {
return res
}).catch(err => {
// throw new Error(err.response.data.error_message);
@@ -284,6 +293,15 @@ export const setExternalURL = (reqData) => {
return postAuxEnd('/panel/myproduct/external-url', postData, false)
}
+// FUNCTION TO UPLOAD PROFILE IMAGE
+export const uploadProfileImg = (reqData) => {
+ let postData = {
+ ...reqData,
+ }
+ throw new Error('Opps')
+ // return postAuxEnd(`/panel/account/profile-update`, postData, true)
+}
+