Skip to content

Commit

Permalink
#3060-default logo showing
Browse files Browse the repository at this point in the history
  • Loading branch information
caiodasilva2005 committed Dec 14, 2024
1 parent ed36d21 commit 3ffe659
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/frontend/src/hooks/organizations.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
setOrganizationFeaturedProjects
} from '../apis/organizations.api';
import { downloadGoogleImage } from '../apis/finance.api';
import { getDefaultImageData } from '../utils/image.utils';

interface OrganizationProvider {
organizationId: string;
Expand Down Expand Up @@ -98,11 +99,13 @@ export const useSetOrganizationLogo = () => {
};

export const useOrganizationLogo = () => {
return useQuery<{ url: string; blob: Blob }, Error>(['organizations', 'logo'], async () => {
const { data: fileId } = await getOrganizationLogo();

const imageBlob = await downloadGoogleImage(fileId);

return { url: URL.createObjectURL(imageBlob), blob: imageBlob };
return useQuery<Blob, Error>(['organizations', 'logo'], async () => {
try {
const { data: fileId } = await getOrganizationLogo();
return await downloadGoogleImage(fileId);
} catch {
// return default logo if fileId was not found
return getDefaultImageData();
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ const EditLogo = () => {
<EditLogoForm
onSubmit={onSubmit}
onHide={handleClose}
orgLogo={new File([imageData.blob], imageData.blob.name, { type: imageData.blob.type })}
orgLogo={new File([imageData], imageData.name, { type: imageData.type })}
/>
) : (
<>
<Box sx={{ display: 'flex', flexDirection: 'column', height: 350, width: 300 }}>
<LogoDisplay imageUrl={imageData.url} />
<LogoDisplay imageUrl={URL.createObjectURL(imageData)} />
<Box
sx={{
display: 'flex',
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/pages/HomePage/components/LogoDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Box, useTheme, Card } from '@mui/material';
import React from 'react';

interface LogoDisplayProps {
imageUrl?: string;
imageUrl: string;
}

const LogoDisplay: React.FC<LogoDisplayProps> = ({ imageUrl = './default-logo.png' }) => {
const LogoDisplay: React.FC<LogoDisplayProps> = ({ imageUrl }) => {
const theme = useTheme();
return (
<Card
Expand Down
8 changes: 8 additions & 0 deletions src/frontend/src/utils/image.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import axios from 'axios';

export const getDefaultImageData = async () => {
const { data } = await axios.get('/default-logo.png', {
responseType: 'blob'
});
return data;
};

0 comments on commit 3ffe659

Please sign in to comment.