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

Rifeljm/nft gallery user folders #1867

Open
wants to merge 2 commits into
base: nft_user_folders
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
85 changes: 85 additions & 0 deletions packages/core/src/components/UserFolders/AddUserFolderDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Trans } from '@lingui/macro';
import { Dialog, DialogTitle, DialogContent } from '@mui/material';
import React, { ReactNode } from 'react';
import { useForm } from 'react-hook-form';

import Button from '../Button';
import DialogActions from '../DialogActions';
import Form from '../Form';
import TextField from '../TextField';

export type AlertDialogProps = {
title?: ReactNode;
open?: boolean;
onClose?: (value?: any) => void;
onAdd: (value: string) => void;
placeholderName?: string;
};

export default function AlertDialog(props: AlertDialogProps) {
const { onClose = () => {}, open = false, title, onAdd, placeholderName = 'Title' } = props;

const inputWrapper = React.useRef<HTMLDivElement>(null);

React.useEffect(() => {
setTimeout(() => {
if (inputWrapper?.current) {
(inputWrapper?.current.querySelector('input') as HTMLElement).focus();
}
}, 100);
}, [inputWrapper]);

function handleClose() {
onClose?.(true);
}

function handleHide() {
onClose?.();
}

type FormData = {
folderName: string;
};

const formMethods = useForm<FormData>({
defaultValues: {
folderName: '',
},
});

function handleSubmit(objValue: any) {
onAdd(objValue.folderName);
handleClose();
}

return (
<Dialog
onClose={handleHide}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
open={open}
>
<Form methods={formMethods} onSubmit={formMethods.handleSubmit(handleSubmit)}>
{title && <DialogTitle id="alert-dialog-title">{title}</DialogTitle>}
<DialogContent id="alert-dialog-description">
<TextField
type="text"
ref={inputWrapper}
autoFocus
name="folderName"
label={placeholderName}
variant="filled"
/>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} variant="outlined" color="primary" autoFocus>
<Trans>Cancel</Trans>
</Button>
<Button type="submit" variant="contained" color="primary" autoFocus>
<Trans>Add</Trans>
</Button>
</DialogActions>
</Form>
</Dialog>
);
}
1 change: 1 addition & 0 deletions packages/core/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ export { default as TooltipIcon } from './TooltipIcon';
export { default as TooltipTypography } from './TooltipTypography';
export { default as Truncate, truncateValue } from './Truncate';
export { default as UnitFormat } from './UnitFormat';
export { default as AddUserFolderDialog } from './UserFolders/AddUserFolderDialog';
export { default as NewerAppVersionAvailable } from './LayoutDashboard/NewerAppVersionAvailable';
183 changes: 154 additions & 29 deletions packages/gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading