Skip to content

Commit

Permalink
fix: uploadCSV
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 committed Apr 3, 2023
1 parent 0494b9c commit 9755fbf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
22 changes: 22 additions & 0 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,28 @@ export default function App() {
}
}, [isOpen])

useEffect(() => {
const handleHashChange = () => {
const {
hash,
} = window.location
if (!isOpen && hash) {
const url = hash.split('#')[1]
if (url !== '/') {
setOpenPage({
isOpen: true,
openUrl: url,
})
}
}
}
window.addEventListener('hashchange', handleHashChange)

return () => {
window.removeEventListener('hashchange', handleHashChange)
}
}, [])

return (
<>
<HashRouter>
Expand Down
10 changes: 2 additions & 8 deletions apps/storefront/src/components/upload/B3Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import Grid from '@mui/material/Unstable_Grid2'

import {
useRef,
useState,
Dispatch,
SetStateAction,
Expand Down Expand Up @@ -111,7 +110,6 @@ export const B3Upload = (props: B3UploadProps) => {
currentChannelId,
},
} = useContext(GlobaledContext)
const uploadRef = useRef<HTMLInputElement>(null)
const [step, setStep] = useState<string>('init')
const [fileDatas, setFileDatas] = useState<CustomFieldItems>({})
const [fileName, setFileName] = useState('')
Expand Down Expand Up @@ -225,10 +223,6 @@ export const B3Upload = (props: B3UploadProps) => {
}
}

const openFile = () => {
if (uploadRef.current) (uploadRef.current.children[1] as HTMLElement).click()
}

const handleConfirmToList = async () => {
const validProduct = fileDatas?.validProduct || []
const stockErrorFile = fileDatas?.stockErrorFile || ''
Expand Down Expand Up @@ -257,6 +251,7 @@ export const B3Upload = (props: B3UploadProps) => {
transform: 'translate(-50%, -50%)',
top: '50%',
left: '50%',
pointerEvents: 'none',
}}
>
<Grid
Expand Down Expand Up @@ -331,7 +326,6 @@ export const B3Upload = (props: B3UploadProps) => {
xs={12}
>
<Button
onClick={openFile}
variant="outlined"
>
Upload file
Expand Down Expand Up @@ -390,7 +384,7 @@ export const B3Upload = (props: B3UploadProps) => {
>
{
step === 'init' && (
<FileUploadContainer ref={uploadRef}>
<FileUploadContainer>
{content}
<DropzoneArea
dropzoneClass="file-upload-area"
Expand Down

0 comments on commit 9755fbf

Please sign in to comment.