2024-06-07 16:13:32 +05:00
|
|
|
import {
|
|
|
|
Add,
|
|
|
|
CalendarMonth,
|
|
|
|
Description,
|
2024-06-07 16:17:35 +05:00
|
|
|
PersonOutline,
|
|
|
|
Upload
|
2024-06-07 16:13:32 +05:00
|
|
|
} from '@mui/icons-material'
|
2024-06-08 00:37:03 +05:00
|
|
|
import { Box, Button, Tooltip, Typography } from '@mui/material'
|
2024-05-14 14:27:05 +05:00
|
|
|
import { useNavigate } from 'react-router-dom'
|
2024-06-13 11:47:28 +05:00
|
|
|
import { appPrivateRoutes, appPublicRoutes } from '../../routes'
|
2024-06-07 16:13:32 +05:00
|
|
|
import styles from './style.module.scss'
|
2024-06-13 11:47:28 +05:00
|
|
|
import { useRef } from 'react'
|
|
|
|
import JSZip from 'jszip'
|
|
|
|
import { toast } from 'react-toastify'
|
2024-04-08 17:45:51 +05:00
|
|
|
|
|
|
|
export const HomePage = () => {
|
2024-05-14 14:27:05 +05:00
|
|
|
const navigate = useNavigate()
|
2024-06-13 11:47:28 +05:00
|
|
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
|
|
|
|
|
|
const handleUploadClick = () => {
|
|
|
|
if (fileInputRef.current) {
|
|
|
|
fileInputRef.current.click()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleFileChange = async (
|
|
|
|
event: React.ChangeEvent<HTMLInputElement>
|
|
|
|
) => {
|
|
|
|
const file = event.target.files?.[0]
|
|
|
|
if (file) {
|
|
|
|
// Check if the file extension is .sigit.zip
|
|
|
|
const fileName = file.name
|
|
|
|
const fileExtension = fileName.slice(-10) // ".sigit.zip" has 10 characters
|
|
|
|
if (fileExtension === '.sigit.zip') {
|
|
|
|
const zip = await JSZip.loadAsync(file).catch((err) => {
|
|
|
|
console.log('err in loading zip file :>> ', err)
|
|
|
|
toast.error(err.message || 'An error occurred in loading zip file.')
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!zip) return
|
|
|
|
|
|
|
|
// navigate to sign page if zip contains keys.json
|
|
|
|
if ('keys.json' in zip.files) {
|
|
|
|
return navigate(appPrivateRoutes.sign, {
|
|
|
|
state: { uploadedZip: file }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// navigate to verify page if zip contains meta.json
|
|
|
|
if ('meta.json' in zip.files) {
|
|
|
|
return navigate(appPublicRoutes.verify, {
|
|
|
|
state: { uploadedZip: file }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
toast.error('Invalid zip file')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// navigate to create page
|
|
|
|
navigate(appPrivateRoutes.create, { state: { uploadedFile: file } })
|
|
|
|
}
|
|
|
|
}
|
2024-04-08 17:45:51 +05:00
|
|
|
|
|
|
|
return (
|
2024-05-14 14:27:05 +05:00
|
|
|
<Box className={styles.container}>
|
2024-06-07 16:13:32 +05:00
|
|
|
<Box className={styles.header}>
|
|
|
|
<Typography variant="h3" className={styles.title}>
|
|
|
|
Sigits
|
|
|
|
</Typography>
|
2024-06-08 00:37:03 +05:00
|
|
|
{/* This is for desktop view */}
|
|
|
|
<Box
|
|
|
|
className={styles.actionButtons}
|
|
|
|
sx={{
|
|
|
|
display: {
|
|
|
|
xs: 'none',
|
|
|
|
md: 'flex'
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2024-06-13 11:47:28 +05:00
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
ref={fileInputRef}
|
|
|
|
style={{ display: 'none' }}
|
|
|
|
onChange={handleFileChange}
|
|
|
|
/>
|
2024-06-07 16:13:32 +05:00
|
|
|
<Button
|
|
|
|
variant="outlined"
|
2024-06-07 16:17:35 +05:00
|
|
|
startIcon={<Upload />}
|
2024-06-13 11:47:28 +05:00
|
|
|
onClick={handleUploadClick}
|
2024-06-07 16:13:32 +05:00
|
|
|
>
|
2024-06-07 16:17:35 +05:00
|
|
|
Upload
|
2024-06-07 16:13:32 +05:00
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
variant="contained"
|
|
|
|
startIcon={<Add />}
|
|
|
|
onClick={() => navigate(appPrivateRoutes.create)}
|
|
|
|
>
|
|
|
|
Create
|
|
|
|
</Button>
|
|
|
|
</Box>
|
2024-06-08 00:37:03 +05:00
|
|
|
{/* This is for mobile view */}
|
|
|
|
<Box
|
|
|
|
className={styles.actionButtons}
|
|
|
|
sx={{
|
|
|
|
display: {
|
|
|
|
xs: 'flex',
|
|
|
|
md: 'none'
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Tooltip title="Upload" arrow>
|
|
|
|
<Button
|
|
|
|
variant="outlined"
|
|
|
|
onClick={() => navigate(appPrivateRoutes.sign)}
|
|
|
|
>
|
|
|
|
<Upload />
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip title="Create" arrow>
|
|
|
|
<Button
|
|
|
|
variant="contained"
|
|
|
|
onClick={() => navigate(appPrivateRoutes.create)}
|
|
|
|
>
|
|
|
|
<Add />
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<Box className={styles.submissions}>
|
|
|
|
<PlaceHolder />
|
|
|
|
<PlaceHolder />
|
|
|
|
<PlaceHolder />
|
2024-06-07 16:13:32 +05:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const PlaceHolder = () => {
|
|
|
|
return (
|
2024-06-08 00:37:03 +05:00
|
|
|
<Box
|
|
|
|
className={styles.item}
|
|
|
|
sx={{
|
|
|
|
flexDirection: {
|
|
|
|
xs: 'column',
|
|
|
|
md: 'row'
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
className={styles.titleBox}
|
|
|
|
sx={{
|
|
|
|
flexDirection: {
|
|
|
|
xs: 'row',
|
|
|
|
md: 'column'
|
|
|
|
},
|
|
|
|
borderBottomLeftRadius: {
|
|
|
|
xs: 'initial',
|
|
|
|
md: 'inherit'
|
|
|
|
},
|
|
|
|
borderTopRightRadius: {
|
|
|
|
xs: 'inherit',
|
|
|
|
md: 'initial'
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Typography variant="body1" className={styles.titleBoxItem}>
|
|
|
|
<Description />
|
|
|
|
Title
|
|
|
|
</Typography>
|
|
|
|
<Typography variant="body2" className={styles.titleBoxItem}>
|
|
|
|
<PersonOutline />
|
|
|
|
Sigit
|
|
|
|
</Typography>
|
|
|
|
<Typography variant="body2" className={styles.titleBoxItem}>
|
|
|
|
<CalendarMonth />
|
|
|
|
07 Jun 10:23 AM
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<Box className={styles.signers}>
|
|
|
|
<Box className={styles.signerItem}>
|
|
|
|
<Typography variant="button" className={styles.status}>
|
|
|
|
Sent
|
2024-06-07 16:13:32 +05:00
|
|
|
</Typography>
|
2024-06-08 00:37:03 +05:00
|
|
|
<Typography variant="body1">placeholder@sigit.io</Typography>
|
2024-06-07 16:13:32 +05:00
|
|
|
</Box>
|
2024-06-08 00:37:03 +05:00
|
|
|
<Box className={styles.signerItem}>
|
|
|
|
<Typography variant="button" className={styles.status}>
|
|
|
|
Awaiting
|
|
|
|
</Typography>
|
|
|
|
<Typography variant="body1">placeholder@sigit.io</Typography>
|
2024-06-07 16:13:32 +05:00
|
|
|
</Box>
|
|
|
|
</Box>
|
2024-05-14 14:27:05 +05:00
|
|
|
</Box>
|
2024-04-08 17:45:51 +05:00
|
|
|
)
|
|
|
|
}
|