-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-EditOrgLogo #3060-Edit Organization Logo
- Loading branch information
Showing
17 changed files
with
379 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NextFunction, Request, Response } from 'express'; | ||
import OnboardingServices from '../services/onboarding.services'; | ||
|
||
export default class OnboardingController { | ||
static async downloadImage(req: Request, res: Response, next: NextFunction) { | ||
try { | ||
const { fileId } = req.params; | ||
|
||
const imageData = await OnboardingServices.downloadImage(fileId); | ||
|
||
// Set the appropriate headers for the HTTP response | ||
res.setHeader('content-type', String(imageData.type)); | ||
res.setHeader('content-length', imageData.buffer.length); | ||
|
||
// Send the Buffer as the response body | ||
res.send(imageData.buffer); | ||
} catch (error: unknown) { | ||
return next(error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import express from 'express'; | ||
import OnboardingController from '../controllers/onboarding.controller'; | ||
|
||
const onboardingRouter = express.Router(); | ||
|
||
onboardingRouter.get('/image/:fileId', OnboardingController.downloadImage); | ||
|
||
export default onboardingRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NotFoundException } from '../utils/errors.utils'; | ||
import { downloadImageFile } from '../utils/google-integration.utils'; | ||
|
||
export default class OnboardingServices { | ||
static async downloadImage(fileId: string) { | ||
const fileData = await downloadImageFile(fileId); | ||
console.log('FILE DATA RECEIVED'); | ||
|
||
if (!fileData) throw new NotFoundException('Image File', fileId); | ||
return fileData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import axios from 'axios'; | ||
import { apiUrls } from '../utils/urls'; | ||
|
||
/** | ||
* API Call to download a google image | ||
* @param fileId file id to be downloaded | ||
* @returns an image blob | ||
*/ | ||
export const downloadGoogleImage = async (fileId: string): Promise<Blob> => { | ||
const response = await axios.get(apiUrls.imageById(fileId), { | ||
responseType: 'arraybuffer' // Set the response type to 'arraybuffer' to receive the image as a Buffer | ||
}); | ||
const imageBuffer = new Uint8Array(response.data); | ||
const imageBlob = new Blob([imageBuffer], { type: response.headers['content-type'] }); | ||
return imageBlob; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/frontend/src/pages/AdminToolsPage/EditGuestView/EditLogo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React, { useState } from 'react'; | ||
import { useCurrentOrganization, useOrganizationLogo, useSetOrganizationLogo } from '../../../hooks/organizations.hooks'; | ||
import LoadingIndicator from '../../../components/LoadingIndicator'; | ||
import EditLogoForm, { EditLogoInput } from './EditLogoForm'; | ||
import { useToast } from '../../../hooks/toasts.hooks'; | ||
import { Box, Card, Typography, useTheme } from '@mui/material'; | ||
import LogoDisplay from '../../HomePage/components/LogoDisplay'; | ||
import { NERButton } from '../../../components/NERButton'; | ||
import ErrorPage from '../../ErrorPage'; | ||
|
||
const EditLogo = () => { | ||
const { | ||
data: organization, | ||
isLoading: organizationIsLoading, | ||
isError: organizationIsError, | ||
error: organizationError | ||
} = useCurrentOrganization(); | ||
const { data: imageData, isLoading: imageDataIsLoading, isError: imageIsError, error: imageError } = useOrganizationLogo(); | ||
const { mutateAsync, isLoading } = useSetOrganizationLogo(); | ||
const toast = useToast(); | ||
const [isEditMode, setIsEditMode] = useState(false); | ||
const theme = useTheme(); | ||
|
||
if (isLoading || !mutateAsync || organizationIsLoading || !organization || imageDataIsLoading) return <LoadingIndicator />; | ||
if (organizationIsError) return <ErrorPage message={organizationError.message} />; | ||
if (imageIsError) return <ErrorPage message={imageError.message} />; | ||
|
||
const handleClose = () => { | ||
setIsEditMode(false); | ||
}; | ||
|
||
const onSubmit = async (logoInput: EditLogoInput) => { | ||
try { | ||
if (!logoInput.logoImage) { | ||
toast.error('No logo image submitted.'); | ||
handleClose(); | ||
return; | ||
} | ||
await mutateAsync(logoInput.logoImage); | ||
toast.success('Logo updated successfully!'); | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
toast.error(e.message); | ||
} | ||
} | ||
handleClose(); | ||
}; | ||
|
||
return ( | ||
<Card | ||
sx={{ | ||
width: '100%', | ||
background: 'transparent', | ||
padding: 2, | ||
...(isEditMode && { | ||
background: theme.palette.background.paper, | ||
padding: 1.9, | ||
variant: 'outlined' | ||
}) | ||
}} | ||
variant={isEditMode ? 'outlined' : undefined} | ||
> | ||
<Typography variant="h4" mb={1}> | ||
{organization.name} Logo | ||
</Typography> | ||
{isEditMode ? ( | ||
<EditLogoForm | ||
onSubmit={onSubmit} | ||
onHide={handleClose} | ||
orgLogo={imageData ? new File([imageData], imageData.name, { type: imageData.type }) : undefined} | ||
/> | ||
) : ( | ||
<> | ||
<Box sx={{ display: 'flex', flexDirection: 'column', height: 350, width: 300 }}> | ||
<LogoDisplay imageUrl={imageData ? URL.createObjectURL(imageData) : undefined} /> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'end' | ||
}} | ||
> | ||
<NERButton variant="contained" sx={{ my: 2 }} onClick={() => setIsEditMode(true)}> | ||
Update | ||
</NERButton> | ||
</Box> | ||
</Box> | ||
</> | ||
)} | ||
</Card> | ||
); | ||
}; | ||
|
||
export default EditLogo; |
Oops, something went wrong.