-
-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from bigcapitalhq/validate-imported-sheet-empty
feat: validate the given imported sheet whether is empty
- Loading branch information
Showing
7 changed files
with
131 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { ReactNode } from 'react'; | ||
import { useState, createContext, useContext } from 'react'; | ||
|
||
interface AlertsManagerContextValue { | ||
alerts: (string | number)[]; | ||
showAlert: (alert: string | number) => void; | ||
hideAlert: (alert: string | number) => void; | ||
|
||
hideAlerts: () => void; | ||
isAlertActive: (alert: string | number) => boolean; | ||
findAlert: (alert: string | number) => string | number | undefined; | ||
} | ||
|
||
const AlertsManagerContext = createContext<AlertsManagerContextValue>( | ||
{} as AlertsManagerContextValue, | ||
); | ||
|
||
export function AlertsManager({ children }: { children: ReactNode }) { | ||
const [alerts, setAlerts] = useState<(string | number)[]>([]); | ||
|
||
const showAlert = (type: string | number): void => { | ||
setAlerts([...alerts, type]); | ||
}; | ||
const hideAlert = (type: string | number): void => { | ||
alerts.filter((t) => t !== type); | ||
}; | ||
const hideAlerts = (): void => { | ||
setAlerts([]); | ||
}; | ||
const isAlertActive = (type: string | number): boolean => { | ||
return alerts.some((t) => t === type); | ||
}; | ||
const findAlert = (type: string | number): number | string | undefined => { | ||
return alerts.find((t) => t === type); | ||
}; | ||
|
||
return ( | ||
<AlertsManagerContext.Provider | ||
value={{ | ||
alerts, | ||
showAlert, | ||
hideAlert, | ||
hideAlerts, | ||
isAlertActive, | ||
findAlert, | ||
}} | ||
> | ||
{children} | ||
</AlertsManagerContext.Provider> | ||
); | ||
} | ||
|
||
export const useAlertsManager = () => useContext(AlertsManagerContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 39 additions & 18 deletions
57
packages/webapp/src/containers/Import/ImportFileUploadStep.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,56 @@ | ||
// @ts-nocheck | ||
import { Classes } from '@blueprintjs/core'; | ||
import { Callout, Classes, Intent } from '@blueprintjs/core'; | ||
import { Stack } from '@/components'; | ||
import { ImportDropzone } from './ImportDropzone'; | ||
import { ImportSampleDownload } from './ImportSampleDownload'; | ||
import { ImportFileUploadForm } from './ImportFileUploadForm'; | ||
import { ImportFileUploadFooterActions } from './ImportFileFooterActions'; | ||
import { ImportFileContainer } from './ImportFileContainer'; | ||
import { useImportFileContext } from './ImportFileProvider'; | ||
import { AlertsManager, useAlertsManager } from './AlertsManager'; | ||
import { ImportAlert } from './_types'; | ||
|
||
function ImportFileUploadCallouts() { | ||
const { isAlertActive } = useAlertsManager(); | ||
return ( | ||
<> | ||
{isAlertActive(ImportAlert.IMPORTED_SHEET_EMPTY) && ( | ||
<Callout intent={Intent.DANGER} icon={null}> | ||
The imported sheet is empty. | ||
</Callout> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export function ImportFileUploadStep() { | ||
const { exampleDownload } = useImportFileContext(); | ||
|
||
return ( | ||
<ImportFileUploadForm> | ||
<ImportFileContainer> | ||
<p | ||
className={Classes.TEXT_MUTED} | ||
style={{ marginBottom: 18, lineHeight: 1.6 }} | ||
> | ||
Download a sample file and compare it with your import file to ensure | ||
it is properly formatted. It's not necessary for the columns to be in | ||
the same order, you can map them later. | ||
</p> | ||
<AlertsManager> | ||
<ImportFileUploadForm> | ||
<ImportFileContainer> | ||
<p | ||
className={Classes.TEXT_MUTED} | ||
style={{ marginBottom: 18, lineHeight: 1.6 }} | ||
> | ||
Download a sample file and compare it with your import file to | ||
ensure it is properly formatted. It's not necessary for the columns | ||
to be in the same order, you can map them later. | ||
</p> | ||
|
||
<Stack> | ||
<ImportFileUploadCallouts /> | ||
|
||
<Stack spacing={40}> | ||
<ImportDropzone /> | ||
{exampleDownload && <ImportSampleDownload />} | ||
</Stack> | ||
</ImportFileContainer> | ||
<Stack spacing={40}> | ||
<ImportDropzone /> | ||
{exampleDownload && <ImportSampleDownload />} | ||
</Stack> | ||
</Stack> | ||
</ImportFileContainer> | ||
|
||
<ImportFileUploadFooterActions /> | ||
</ImportFileUploadForm> | ||
<ImportFileUploadFooterActions /> | ||
</ImportFileUploadForm> | ||
</AlertsManager> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters