Skip to content

Commit

Permalink
Merge pull request #628 from idurar/dev
Browse files Browse the repository at this point in the history
🐛 fix photo profile bugs
  • Loading branch information
salahlalami authored Oct 31, 2023
2 parents 133aeab + 64ddd7d commit 2bc25b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 13 additions & 1 deletion frontend/src/apps/components/HeaderContent.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState, useEffect } from 'react';
import { useSelector } from 'react-redux';
import { Link } from 'react-router-dom';
import { Avatar, Dropdown, Layout } from 'antd';
Expand All @@ -23,7 +24,18 @@ export default function HeaderContent() {

const translate = useLanguage();

const hasPhotoprofile = checkImage(BASE_URL + currentAdmin?.photo);
const [hasPhotoprofile, setHasPhotoprofile] = useState(false);

useEffect(() => {
async function fetchData() {
const result = await checkImage(BASE_URL + currentAdmin?.photo);
setHasPhotoprofile(result);
}
fetchData();
return () => {
return false;
};
}, []);

const srcImgProfile = hasPhotoprofile ? BASE_URL + currentAdmin?.photo : null;

Expand Down
9 changes: 6 additions & 3 deletions frontend/src/request/checkImage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import axios from 'axios';
export default async function checkImage(path) {
axios
const result = await axios
.get(path)
.then(() => {
return true;
.then((response) => {
if (response.status === 200) return true;
else return false;
})
.catch(() => {
return false;
});

return result;
}

0 comments on commit 2bc25b4

Please sign in to comment.