fix: change sign to create #34
@ -20,11 +20,11 @@ import {
|
|||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import { MuiFileInput } from 'mui-file-input'
|
import { MuiFileInput } from 'mui-file-input'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link, useNavigate } from 'react-router-dom'
|
||||||
import placeholderAvatar from '../../assets/images/nostr-logo.jpg'
|
import placeholderAvatar from '../../assets/images/nostr-logo.jpg'
|
||||||
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
||||||
import { MetadataController, NostrController } from '../../controllers'
|
import { MetadataController, NostrController } from '../../controllers'
|
||||||
import { getProfileRoute } from '../../routes'
|
import { appPrivateRoutes, getProfileRoute } from '../../routes'
|
||||||
import { ProfileMetadata, User, UserRole } from '../../types'
|
import { ProfileMetadata, User, UserRole } from '../../types'
|
||||||
import {
|
import {
|
||||||
encryptArrayBuffer,
|
encryptArrayBuffer,
|
||||||
@ -44,7 +44,8 @@ import JSZip from 'jszip'
|
|||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import { State } from '../../store/rootReducer'
|
import { State } from '../../store/rootReducer'
|
||||||
|
|
||||||
export const SignPage = () => {
|
export const CreatePage = () => {
|
||||||
|
const navigate = useNavigate()
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState('')
|
const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState('')
|
||||||
|
|
||||||
@ -63,6 +64,22 @@ export const SignPage = () => {
|
|||||||
|
|
||||||
const nostrController = NostrController.getInstance()
|
const nostrController = NostrController.getInstance()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (usersPubkey) {
|
||||||
|
setUsers((prev) => {
|
||||||
|
const existingUserIndex = prev.findIndex(
|
||||||
|
(user) => user.pubkey === usersPubkey
|
||||||
|
)
|
||||||
|
|
||||||
|
// make logged in user the first signer by default
|
||||||
|
if (existingUserIndex === -1)
|
||||||
|
return [{ pubkey: usersPubkey, role: UserRole.signer }, ...prev]
|
||||||
|
|
||||||
|
return prev
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [usersPubkey])
|
||||||
|
|
||||||
const handleAddUser = async () => {
|
const handleAddUser = async () => {
|
||||||
setError(undefined)
|
setError(undefined)
|
||||||
|
|
||||||
@ -89,8 +106,6 @@ export const SignPage = () => {
|
|||||||
|
|
||||||
return updatedUsers
|
return updatedUsers
|
||||||
})
|
})
|
||||||
|
|
||||||
setUserInput('')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userInput.startsWith('npub')) {
|
if (userInput.startsWith('npub')) {
|
||||||
@ -168,7 +183,7 @@ export const SignPage = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSign = async () => {
|
const handleCreate = async () => {
|
||||||
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.'
|
||||||
@ -329,8 +344,13 @@ export const SignPage = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
|
|
||||||
|
navigate(
|
||||||
|
`${appPrivateRoutes.verify}?file=${encodeURIComponent(
|
||||||
|
fileUrl
|
||||||
|
)}&key=${encodeURIComponent(encryptionKey)}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authUrl) {
|
if (authUrl) {
|
||||||
@ -413,8 +433,8 @@ export const SignPage = () => {
|
|||||||
handleRemoveUser={handleRemoveUser}
|
handleRemoveUser={handleRemoveUser}
|
||||||
/>
|
/>
|
||||||
<Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
|
<Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
|
||||||
<Button onClick={handleSign} variant='contained'>
|
<Button onClick={handleCreate} variant='contained'>
|
||||||
Sign
|
Create
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
@ -9,10 +9,10 @@ export const HomePage = () => {
|
|||||||
return (
|
return (
|
||||||
<Box className={styles.container}>
|
<Box className={styles.container}>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => navigate(appPrivateRoutes.sign)}
|
onClick={() => navigate(appPrivateRoutes.create)}
|
||||||
variant='contained'
|
variant='contained'
|
||||||
>
|
>
|
||||||
Sign
|
Create
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => navigate(appPrivateRoutes.verify)}
|
onClick={() => navigate(appPrivateRoutes.verify)}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { HomePage } from '../pages/home'
|
import { HomePage } from '../pages/home'
|
||||||
import { SignPage } from '../pages/sign'
|
import { CreatePage } from '../pages/create'
|
||||||
import { LandingPage } from '../pages/landing/LandingPage'
|
import { LandingPage } from '../pages/landing/LandingPage'
|
||||||
import { Login } from '../pages/login'
|
import { Login } from '../pages/login'
|
||||||
import { ProfilePage } from '../pages/profile'
|
import { ProfilePage } from '../pages/profile'
|
||||||
@ -8,7 +8,7 @@ import { VerifyPage } from '../pages/verify'
|
|||||||
|
|
||||||
export const appPrivateRoutes = {
|
export const appPrivateRoutes = {
|
||||||
homePage: '/',
|
homePage: '/',
|
||||||
sign: '/sign',
|
create: '/create',
|
||||||
verify: '/verify'
|
verify: '/verify'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ export const privateRoutes = [
|
|||||||
element: <HomePage />
|
element: <HomePage />
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: appPrivateRoutes.sign,
|
path: appPrivateRoutes.create,
|
||||||
element: <SignPage />
|
element: <CreatePage />
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: appPrivateRoutes.verify,
|
path: appPrivateRoutes.verify,
|
||||||
|
Loading…
Reference in New Issue
Block a user