-
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.
- Loading branch information
1 parent
e59e07b
commit eec9ffd
Showing
8 changed files
with
212 additions
and
75 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
75 changes: 66 additions & 9 deletions
75
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 |
---|---|---|
@@ -1,29 +1,86 @@ | ||
import React from 'react'; | ||
import { useCurrentOrganization, useSetOrganizationLogo } from '../../../hooks/organizations.hooks'; | ||
import React, { useState } from 'react'; | ||
import { useCurrentOrganization, useOrganizationLogo, useSetOrganizationLogo } from '../../../hooks/organizations.hooks'; | ||
import LoadingIndicator from '../../../components/LoadingIndicator'; | ||
import EditLogoForm from './EditLogoForm'; | ||
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'; | ||
|
||
const EditLogo = () => { | ||
const { data: organization, isLoading: organizationIsLoading } = useCurrentOrganization(); | ||
const { mutateAsync } = useSetOrganizationLogo(); | ||
const { data: imageData, isLoading: imageDataIsLoading } = useOrganizationLogo(); | ||
const { mutateAsync, isLoading } = useSetOrganizationLogo(); | ||
const toast = useToast(); | ||
const [isEditMode, setIsEditMode] = useState(false); | ||
const theme = useTheme(); | ||
|
||
if (organizationIsLoading || !organization) return <LoadingIndicator />; | ||
if (isLoading || !mutateAsync || organizationIsLoading || !organization || !imageData || imageDataIsLoading) | ||
return <LoadingIndicator />; | ||
|
||
const onSubmitWrapper = async (logoImage: File) => { | ||
const handleClose = () => { | ||
setIsEditMode(false); | ||
}; | ||
|
||
const onSubmit = async (logoInput: EditLogoInput) => { | ||
try { | ||
await mutateAsync(logoImage); | ||
console.log(logoInput); | ||
if (!logoInput.logoImage) { | ||
handleClose(); | ||
return; | ||
} | ||
await mutateAsync(logoInput.logoImage); | ||
toast.success('Logo updated successfully!'); | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
toast.error(e.message); | ||
} | ||
} | ||
await mutateAsync(logoImage); | ||
handleClose(); | ||
}; | ||
|
||
return <EditLogoForm onSubmit={onSubmitWrapper} />; | ||
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={new File([imageData.blob], imageData.blob.name, { type: imageData.blob.type })} | ||
/> | ||
) : ( | ||
<> | ||
<Box sx={{ display: 'flex', flexDirection: 'column', height: 350, width: 300 }}> | ||
<LogoDisplay imageUrl={imageData ? imageData.url : undefined} /> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'end' | ||
}} | ||
> | ||
<NERButton variant="contained" sx={{ my: 2 }} onClick={() => setIsEditMode(true)}> | ||
Update | ||
</NERButton> | ||
</Box> | ||
</Box> | ||
</> | ||
)} | ||
</Card> | ||
); | ||
}; | ||
|
||
export default EditLogo; |
155 changes: 109 additions & 46 deletions
155
src/frontend/src/pages/AdminToolsPage/EditGuestView/EditLogoForm.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
18 changes: 13 additions & 5 deletions
18
src/frontend/src/pages/AdminToolsPage/EditGuestView/GuestViewConfig.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
31 changes: 20 additions & 11 deletions
31
src/frontend/src/pages/HomePage/components/LogoDisplay.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