Skip to content

Admins - Mentor profile image update feature added #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 69 additions & 7 deletions src/components/MentorApplication/MentorApplication.component.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -19,6 +20,38 @@ const MentorApplication: React.FC = () => {
const handleStateChange = async (newState: string) => {
await changeState(newState);
};
const [profilePic, setProfilePic] = useState<string | null>(
mentor?.profile.image_url ?? ''
);

const handleImageClick = () => {
document.getElementById('profilePic')?.click();
};

const handleProfilePicChange = async (
event: React.ChangeEvent<HTMLInputElement>
) => {
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 (
<>
Expand All @@ -33,11 +66,40 @@ const MentorApplication: React.FC = () => {
) : (
<div className="w-full space-y-8">
<div className="flex items-center">
<ProfilePic
src={mentor?.profile.image_url}
alt="Mentee Avatar"
size="6rem"
/>
<div className="relative">
<input
type="file"
id="profilePic"
accept="image/*"
className="hidden"
onChange={handleProfilePicChange}
name="profilePic"
/>
<div
onClick={handleImageClick}
className="cursor-pointer relative group mb-4"
>
{profilePic ? (
<img
src={profilePic}
alt="Profile"
className="w-[90px] h-[90px] rounded-full object-cover"
referrerPolicy="no-referrer"
/>
) : (
<div className="w-[90px] h-[90px] rounded-full bg-gray-200 flex items-center justify-center">
<div className="w-24 h-24 bg-gray-200 rounded-full mx-auto flex items-center justify-center">
<span className="text-gray-400">+</span>
</div>
</div>
)}
<div className="absolute bottom-0 w-[90px] h-1/2 bg-black bg-opacity-40 rounded-b-full flex items-center p-5 justify-center">
<span className="text-white text-center text-xs">
Change Photo
</span>
</div>
</div>
</div>
<div className="ml-5">
Comment on lines +69 to +102
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a separate component for this cuz we duplicating the code here and the settings page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anjula-sack looked into it again. Seems the settings page is handling the image upload after a button is beging clicked since other fields such as firstName & lastName can be changed through that as well.

in the change I did, it handles the image uplaod when a file is being selected since there are no buttons within the page to update other data of mentors.

<div className="flex items-center space-x-3">
<span className="text-2xl font-semibold">
Expand Down
Loading