Skip to content
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

Staging: custom banners #2254

Merged
merged 48 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
57ddff1
Add path
juniusfree Feb 24, 2024
f9fe823
Add to menu
juniusfree Feb 24, 2024
f51a7c8
Implement components, static data, responsive
juniusfree Feb 24, 2024
aa62847
Fix layout
juniusfree Mar 1, 2024
874f4ba
Add tooltip
juniusfree Mar 1, 2024
a8f7a9f
Add base images
juniusfree Mar 1, 2024
83c3848
Add update_org_banner mutation
juniusfree Mar 1, 2024
090985c
Add delete org banner
juniusfree Mar 1, 2024
f7c5c75
Implement file upload and delete
juniusfree Mar 1, 2024
587a621
Add placeholder for query
juniusfree Mar 1, 2024
6cf2748
Clear input field on delete
juniusfree Mar 1, 2024
4e6bd13
Update OrgBannerFragment
juniusfree Mar 2, 2024
f97dd30
Integrate updated apis
juniusfree Mar 2, 2024
3a587de
Check for org sub
juniusfree Mar 3, 2024
b2bad65
Add exempted org ids
juniusfree Mar 3, 2024
2754655
Add types to commandBanners
juniusfree Mar 3, 2024
1f59007
Add snackbar
juniusfree Mar 3, 2024
82dbc96
Add file validation
juniusfree Mar 3, 2024
acf4444
Fix layout, image size
juniusfree Mar 3, 2024
b6f6a68
Fix upload cursor
juniusfree Mar 3, 2024
d5a2892
Add snackbar on error
juniusfree Mar 3, 2024
9edbe72
Add return
juniusfree Mar 3, 2024
44af3b5
Remove unused imports
juniusfree Mar 3, 2024
7d5c065
Refactor update and delete functions
juniusfree Mar 3, 2024
bfe7c04
Use error alert
juniusfree Mar 3, 2024
7c28edb
Add snackbar severity
juniusfree Mar 3, 2024
dce100d
Fix subscription check
juniusfree Mar 4, 2024
7dab6b8
Rename topImage to top-image
juniusfree Mar 5, 2024
2301b31
Fix paywall
juniusfree Mar 5, 2024
e3ffefd
Use slug
juniusfree Mar 5, 2024
0655dfa
Add loading
juniusfree Mar 5, 2024
9c05609
Update store tooltip
juniusfree Mar 5, 2024
55bad33
Fix layout
juniusfree Mar 5, 2024
bec9ff6
fix layout
juniusfree Mar 5, 2024
02d0874
Remove oldassetid
juniusfree Mar 7, 2024
a0261f1
Fix width
juniusfree Mar 7, 2024
80a1ad2
Update query and upsert
juniusfree Mar 18, 2024
59dfcca
Update delete banner
juniusfree Mar 19, 2024
a729cd4
Remove comments
juniusfree Mar 19, 2024
9ae7721
Update and use the AvatarEditor
juniusfree Mar 20, 2024
b421e06
Fixes
juniusfree Mar 20, 2024
2008ede
Add gap to modal styling
juniusfree Mar 20, 2024
ba3bd08
Refactor naming
juniusfree Mar 20, 2024
f12c234
Merge pull request #2223 from wondrous-dev/junius/customize-banners
andywong418 Apr 26, 2024
d42264b
fix aspect ratio on web
Lamperoyge May 1, 2024
8f3c2fd
Merge pull request #2255 from wondrous-dev/fix/chart-aspect-ratio
Lamperoyge May 1, 2024
9932a1a
fix keys
Lamperoyge May 1, 2024
fa41a69
Merge pull request #2256 from wondrous-dev/fix/change-keys
andywong418 May 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions wondrous-bot-admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { WonderWeb3Provider } from "utils/context/WonderWeb3Context";
import SettingsPage from "pages/settings";
import TeamSettingsPage from "pages/settings/team";
import BillingPage from "pages/settings/billing";
import CustomizeBannersPage from "pages/settings/customize-banners";
import NotificationSettingsPage from "pages/settings/notification";
import WalletConnectPage from "pages/wallet/connect";
import OnboardingPage from "pages/onboarding";
Expand Down Expand Up @@ -119,6 +120,10 @@ const router = createBrowserRouter([
path: "/settings/nft",
element: <CommunityNFTSettingsPage />,
},
{
path: "/settings/customize-banners",
element: <CustomizeBannersPage />,
},
{
path: "/",
element: <Home />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function LineBarChart({ title, data = null, renderComponents = null }) {
const options: ChartOptions<"line" | "bar"> = {
responsive: true,
maintainAspectRatio: true,
aspectRatio: isMobile ? 1 : 2,
aspectRatio: isMobile ? 1 : 3,
plugins: {
legend: {
position: "top",
Expand Down
159 changes: 81 additions & 78 deletions wondrous-bot-admin/src/components/ImageUpload/AvatarEditor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { useEffect, useRef, useState } from 'react';

import max from 'lodash/max';
import DefaultAvatarEditor from 'react-avatar-editor';

import { AvatarEditorTypes } from 'types/assets';
import {
ButtonIconWrapper,
SharedSecondaryButton,
} from 'components/Shared/styles';
import Modal from 'components/Shared/Modal';
import { Box, Grid } from '@mui/material';
import { pinkColors } from 'utils/theme/colors';
import ReplaceIcon from 'components/Icons/ReplaceIcon';
import DeleteIcon from 'components/Icons/Delete';
import { Label } from 'components/CreateTemplate/styles';
import { ZoomIn, ZoomOut } from '@mui/icons-material';
import { useEffect, useRef, useState } from "react";

import max from "lodash/max";
import DefaultAvatarEditor from "react-avatar-editor";

import { AvatarEditorTypes } from "types/assets";
import { ButtonIconWrapper, SharedSecondaryButton } from "components/Shared/styles";
import Modal from "components/Shared/Modal";
import { Box, Grid } from "@mui/material";
import { pinkColors } from "utils/theme/colors";
import ReplaceIcon from "components/Icons/ReplaceIcon";
import DeleteIcon from "components/Icons/Delete";
import { Label } from "components/CreateTemplate/styles";
import { ZoomIn, ZoomOut } from "@mui/icons-material";

type Props = {
originalImage: string | File;
Expand All @@ -25,7 +22,7 @@ type Props = {
clearInput: () => void;
imageType: AvatarEditorTypes;
title: string;
recommendDateionText: string;
recommendDateionText?: string;
};

interface ImageViewerObjectProps {
Expand All @@ -34,6 +31,29 @@ interface ImageViewerObjectProps {
borderRadius: number;
}

const IMAGE_VIEWER_SIZE: Record<Props["imageType"], ImageViewerObjectProps> = {
HEADER_IMAGE: {
width: 550,
height: 78,
borderRadius: 0,
},
ICON_IMAGE: {
width: 250,
height: 250,
borderRadius: 250,
},
BANNER_IMAGE: {
width: 640,
height: 140,
borderRadius: 0,
},
BANNER_LOGO_IMAGE: {
width: 400,
height: 400,
borderRadius: 0,
},
};

const AvatarEditor = ({
originalImage,
open,
Expand All @@ -50,18 +70,7 @@ const AvatarEditor = ({
const [angle, setAngle] = useState(0);
const editorRef = useRef(null);

const imageViewerSize: Record<Props['imageType'], ImageViewerObjectProps> = {
HEADER_IMAGE: {
width: 550,
height: 78,
borderRadius: 0,
},
ICON_IMAGE: {
width: 250,
height: 250,
borderRadius: 250,
},
};
const currentImageViewerSize = IMAGE_VIEWER_SIZE[imageType];

useEffect(() => {
setScale(1.0);
Expand All @@ -83,27 +92,27 @@ const AvatarEditor = ({
// Event handlers
const onAction = (action) => {
switch (action) {
case 'zoom_in':
case "zoom_in":
setScale(scale + defaultZoomScale);
break;

case 'zoom_out':
case "zoom_out":
setScale(max([scale - defaultZoomScale, maxZoomOut]) || maxZoomOut);
break;

case 'rotate_right':
case "rotate_right":
setAngle(angle + defaultRotateAngle);
break;

case 'rotate_left':
case "rotate_left":
setAngle(angle - defaultRotateAngle);
break;

case 'crop':
case "crop":
break;

default:
throw new Error('Unknown action');
throw new Error("Unknown action");
}
};

Expand All @@ -125,95 +134,89 @@ const AvatarEditor = ({
const file = new File([blob], `profile-pic.${blob.type.substring(6)}`, {
type: blob.type,
});
console.log("fetch file", file);
onSave([file]);
});
};

const maxWidth =
currentImageViewerSize.width > currentImageViewerSize.height
? currentImageViewerSize.width * 1.5
: currentImageViewerSize.width * 2;

return (
<Modal
open={open}
title='Upload image'
title="Upload image"
onClose={onCancel}
maxWidth={600}
maxWidth={maxWidth}
footerLeft={
<SharedSecondaryButton $reverse onClick={onCancel}>
Cancel
</SharedSecondaryButton>
}
footerRight={
<SharedSecondaryButton onClick={handleSave}>
Confirm image
</SharedSecondaryButton>
}
footerRight={<SharedSecondaryButton onClick={handleSave}>Confirm image</SharedSecondaryButton>}
modalFooterStyle={{
gap: "8px",
}}
>
<Grid container direction='column' alignItems='center' gap='20px'>
<Box display='flex' justifyContent='center' alignItems='center'>
<Grid container direction="column" alignItems="center" gap="20px">
<Box display="flex" justifyContent="center" alignItems="center">
<DefaultAvatarEditor
styles={{ borderRadius: 6 }}
ref={editorRef}
image={image}
width={imageViewerSize[imageType].width}
height={imageViewerSize[imageType].height}
borderRadius={imageViewerSize[imageType].borderRadius}
width={currentImageViewerSize.width}
height={currentImageViewerSize.height}
borderRadius={currentImageViewerSize.borderRadius}
scale={scale}
rotate={angle}
border={[0, 20]}
/>
</Box>
<Grid
display='flex'
width='100%'
alignItems='center'
justifyContent='space-between'
gap='8px'
>
<Box display='flex' gap='8px'>
<SharedSecondaryButton
borderRadius='6px'
onClick={openSelectFile}
background={pinkColors.pink50}
>
<Grid container alignItems="center" justifyContent="space-between" gap="8px">
<Box display="flex" gap="8px">
<SharedSecondaryButton borderRadius="6px" onClick={openSelectFile} background={pinkColors.pink50}>
<ReplaceIcon />
Replace image
</SharedSecondaryButton>
<SharedSecondaryButton
borderRadius='6px'
onClick={onClearInput}
background={pinkColors.pink50}
>
<SharedSecondaryButton borderRadius="6px" onClick={onClearInput} background={pinkColors.pink50}>
<DeleteIcon />
Delete image
</SharedSecondaryButton>
</Box>
<Box display='flex' gap='8px'>
<ButtonIconWrapper onClick={() => onAction('zoom_in')}>
<Box display="flex" gap="8px">
<ButtonIconWrapper onClick={() => onAction("zoom_in")}>
<ZoomIn
sx={{
color: 'black',
color: "black",
}}
/>
</ButtonIconWrapper>
<ButtonIconWrapper onClick={() => onAction('zoom_out')}>
<ButtonIconWrapper onClick={() => onAction("zoom_out")}>
<ZoomOut
sx={{
color: 'black',
color: "black",
}}
/>
</ButtonIconWrapper>
</Box>
</Grid>
<Box width='100%'>
<Label>Recommended: 800 x 800px</Label>
<Box width="100%">
<Label>
Recommended: {currentImageViewerSize.width} x {currentImageViewerSize.height}
</Label>
</Box>
</Grid>
</Modal>
);
};

export const AVATAR_EDITOR_TYPES: Record<AvatarEditorTypes, AvatarEditorTypes> =
{
HEADER_IMAGE: 'HEADER_IMAGE',
ICON_IMAGE: 'ICON_IMAGE',
};
export const AVATAR_EDITOR_TYPES: Record<AvatarEditorTypes, AvatarEditorTypes> = {
HEADER_IMAGE: "HEADER_IMAGE",
ICON_IMAGE: "ICON_IMAGE",
BANNER_IMAGE: "BANNER_IMAGE",
BANNER_LOGO_IMAGE: "BANNER_LOGO_IMAGE",
};

export default AvatarEditor;
Loading
Loading