From 27ec6d8c3fc4ccd231f67700c6e8dba2ec5f4d77 Mon Sep 17 00:00:00 2001 From: Disura Randunu Date: Tue, 14 Jan 2025 22:39:45 +0530 Subject: [PATCH] Admins - Mentor profile image update feature added --- .../MentorApplication.component.tsx | 76 +++++++++++++++++-- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/src/components/MentorApplication/MentorApplication.component.tsx b/src/components/MentorApplication/MentorApplication.component.tsx index 49c63542..4b56eb4a 100644 --- a/src/components/MentorApplication/MentorApplication.component.tsx +++ b/src/components/MentorApplication/MentorApplication.component.tsx @@ -1,11 +1,12 @@ -import React from 'react'; +import React, { useState } from 'react'; import { getStateColor } from '../../utils'; import { useParams } from 'react-router-dom'; import useMentor from '../../hooks/admin/useMentor'; import Toast from '../Toast'; -import ProfilePic from '../ProfilePic'; import ActionButtons from '../ActionButtons'; import { ApplicationStatus } from '../../enums'; +import axios from 'axios'; +import { API_URL } from '../../constants'; const MentorApplication: React.FC = () => { const { mentorId } = useParams(); @@ -19,6 +20,38 @@ const MentorApplication: React.FC = () => { const handleStateChange = async (newState: string) => { await changeState(newState); }; + const [profilePic, setProfilePic] = useState( + mentor?.profile.image_url ?? '' + ); + + const handleImageClick = () => { + document.getElementById('profilePic')?.click(); + }; + + const handleProfilePicChange = async ( + event: React.ChangeEvent + ) => { + const file = event.target.files?.[0]; + if (file && mentorId) { + const formData = new FormData(); + formData.append('profile_image', file); + try { + const response = await axios.put( + `${API_URL}/admin/mentors/${mentorId}`, + formData, + { + headers: { + 'Content-Type': 'multipart/form-data', + }, + withCredentials: true, + } + ); + setProfilePic(response.data.mentor.profile.image_url); + } catch (error) { + console.error('Error uploading profile picture:', error); + } + } + }; return ( <> @@ -33,11 +66,40 @@ const MentorApplication: React.FC = () => { ) : (
- +
+ +
+ {profilePic ? ( + Profile + ) : ( +
+
+ + +
+
+ )} +
+ + Change Photo + +
+
+