-
Notifications
You must be signed in to change notification settings - Fork 8
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
#3060-Edit Organization Logo #3065
Merged
Peyton-McKee
merged 18 commits into
feature/homepage-redesign
from
#3060-Caio-EditOrgLogo
Dec 21, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
db222ba
#3060-created hooks
caiodasilva2005 32e23a4
#3060-created forms
caiodasilva2005 907e54d
#3060-updated logo fom
caiodasilva2005 f2e10f9
#3060-merged feature branch
caiodasilva2005 e59e07b
#3060-removed unnneeded migration
caiodasilva2005 eec9ffd
#3060-created edit logo
caiodasilva2005 ed36d21
#3060-small fix
caiodasilva2005 3ffe659
#3060-default logo showing
caiodasilva2005 b466c25
#3060-small fix
caiodasilva2005 61b6cf8
#3060-await
caiodasilva2005 0e2fed5
#3060-fixed tests
caiodasilva2005 8477e87
#3060-removed default image
caiodasilva2005 53d5e72
#3060-removed check for no logo
caiodasilva2005 55f17f4
#3060-prettier
caiodasilva2005 2722e7d
#3060-added onboarding endpoints
caiodasilva2005 b9206bd
#3060-removed finance get image
caiodasilva2005 06df950
#3060-fixed issues
caiodasilva2005 a1d8637
#3060-merged feature-branch
caiodasilva2005 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably toast why were closing