chore: add title field in meta.json

This commit is contained in:
SwiftHawk 2024-06-03 22:59:51 +05:00
parent 12ca854c48
commit 07459e5e89
3 changed files with 80 additions and 67 deletions

View File

@ -61,8 +61,8 @@ export const CreatePage = () => {
const [authUrl, setAuthUrl] = useState<string>() const [authUrl, setAuthUrl] = useState<string>()
const [title, setTitle] = useState('')
const [selectedFiles, setSelectedFiles] = useState<File[]>([]) const [selectedFiles, setSelectedFiles] = useState<File[]>([])
const [displayUserInput, setDisplayUserInput] = useState(false)
const [userInput, setUserInput] = useState('') const [userInput, setUserInput] = useState('')
const [userRole, setUserRole] = useState<UserRole>(UserRole.signer) const [userRole, setUserRole] = useState<UserRole>(UserRole.signer)
@ -204,7 +204,6 @@ export const CreatePage = () => {
} }
const handleSelectFiles = (files: File[]) => { const handleSelectFiles = (files: File[]) => {
setDisplayUserInput(true)
setSelectedFiles((prev) => { setSelectedFiles((prev) => {
const prevFileNames = prev.map((file) => file.name) const prevFileNames = prev.map((file) => file.name)
@ -223,6 +222,11 @@ export const CreatePage = () => {
} }
const handleCreate = async () => { const handleCreate = async () => {
if (!title.trim()) {
toast.error('Title can not be empty')
return
}
if (users.length === 0) { if (users.length === 0) {
toast.error( toast.error(
'No signer/viewer is provided. At least add one signer or viewer.' 'No signer/viewer is provided. At least add one signer or viewer.'
@ -290,6 +294,7 @@ export const CreatePage = () => {
// create content for meta file // create content for meta file
const meta: Meta = { const meta: Meta = {
title,
createSignature: JSON.stringify(createSignature, null, 2), createSignature: JSON.stringify(createSignature, null, 2),
docSignatures: {} docSignatures: {}
} }
@ -422,78 +427,84 @@ export const CreatePage = () => {
<> <>
{isLoading && <LoadingSpinner desc={loadingSpinnerDesc} />} {isLoading && <LoadingSpinner desc={loadingSpinnerDesc} />}
<Box className={styles.container}> <Box className={styles.container}>
<Typography component="label" variant="h6"> <TextField
Select files label="Title"
</Typography> value={title}
onChange={(e) => setTitle(e.target.value)}
<MuiFileInput variant="outlined"
multiple
placeholder="Choose Files"
value={selectedFiles}
onChange={(value) => handleSelectFiles(value)}
/> />
<ul> <Box>
{selectedFiles.map((file, index) => ( <MuiFileInput
<li key={index}> fullWidth
<Typography component="label">{file.name}</Typography> multiple
<IconButton onClick={() => handleRemoveFile(file)}> placeholder="Choose Files"
<Clear style={{ color: 'red' }} />{' '} value={selectedFiles}
</IconButton> onChange={(value) => handleSelectFiles(value)}
</li> />
))}
</ul>
{displayUserInput && ( {selectedFiles.length > 0 && (
<> <ul>
<Typography component="label" variant="h6"> {selectedFiles.map((file, index) => (
Add Counterparties <li key={index}>
</Typography> <Typography component="label">{file.name}</Typography>
<Box className={styles.inputBlock}> <IconButton onClick={() => handleRemoveFile(file)}>
<TextField <Clear style={{ color: 'red' }} />{' '}
label="nip05 / npub" </IconButton>
value={userInput} </li>
onChange={(e) => setUserInput(e.target.value)} ))}
helperText={error} </ul>
error={!!error} )}
/> </Box>
<FormControl fullWidth>
<InputLabel id="select-role-label">Role</InputLabel>
<Select
labelId="select-role-label"
id="demo-simple-select"
value={userRole}
label="Role"
onChange={(e) => setUserRole(e.target.value as UserRole)}
>
<MenuItem value={UserRole.signer}>{UserRole.signer}</MenuItem>
<MenuItem value={UserRole.viewer}>{UserRole.viewer}</MenuItem>
</Select>
</FormControl>
<Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}> <Typography component="label" variant="h6">
<Button Add Counterparts
disabled={!userInput} </Typography>
onClick={handleAddUser} <Box className={styles.inputBlock}>
variant="contained" <Box className={styles.inputBlock}>
> <TextField
Add label="nip05 / npub"
</Button> value={userInput}
</Box> onChange={(e) => setUserInput(e.target.value)}
</Box> helperText={error}
<DisplayUser error={!!error}
users={users}
handleUserRoleChange={handleUserRoleChange}
handleRemoveUser={handleRemoveUser}
moveSigner={moveSigner}
/> />
<FormControl fullWidth>
<InputLabel id="select-role-label">Role</InputLabel>
<Select
labelId="select-role-label"
id="demo-simple-select"
value={userRole}
label="Role"
onChange={(e) => setUserRole(e.target.value as UserRole)}
>
<MenuItem value={UserRole.signer}>{UserRole.signer}</MenuItem>
<MenuItem value={UserRole.viewer}>{UserRole.viewer}</MenuItem>
</Select>
</FormControl>
<Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}> <Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleCreate} variant="contained"> <Button
Create disabled={!userInput}
onClick={handleAddUser}
variant="contained"
>
Add
</Button> </Button>
</Box> </Box>
</> </Box>
)} </Box>
<DisplayUser
users={users}
handleUserRoleChange={handleUserRoleChange}
handleRemoveUser={handleRemoveUser}
moveSigner={moveSigner}
/>
<Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleCreate} variant="contained">
Create
</Button>
</Box>
</Box> </Box>
<CopyModal <CopyModal
open={openCopyModal} open={openCopyModal}

View File

@ -4,12 +4,13 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
color: $text-color; color: $text-color;
margin-top: 10px;
gap: 10px;
.inputBlock { .inputBlock {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 25px; gap: 25px;
margin-top: 10px;
} }
} }

View File

@ -9,6 +9,7 @@ export interface User {
} }
export interface Meta { export interface Meta {
title: string
createSignature: string createSignature: string
docSignatures: { [key: `npub1${string}`]: string } docSignatures: { [key: `npub1${string}`]: string }
exportSignature?: string exportSignature?: string