mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat(webapp): import resource UI
This commit is contained in:
87
packages/webapp/src/containers/Import/ImportFileProvider.tsx
Normal file
87
packages/webapp/src/containers/Import/ImportFileProvider.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
// @ts-nocheck
|
||||
import React, {
|
||||
Dispatch,
|
||||
SetStateAction,
|
||||
createContext,
|
||||
useContext,
|
||||
useState,
|
||||
} from 'react';
|
||||
|
||||
type EntityColumn = { key: string; name: string };
|
||||
type SheetColumn = string;
|
||||
type SheetMap = { from: string; to: string };
|
||||
|
||||
interface ImportFileContextValue {
|
||||
sheetColumns: SheetColumn[];
|
||||
setSheetColumns: Dispatch<SetStateAction<SheetColumn[]>>;
|
||||
|
||||
entityColumns: EntityColumn[];
|
||||
setEntityColumns: Dispatch<SetStateAction<EntityColumn[]>>;
|
||||
|
||||
sheetMapping: SheetMap[];
|
||||
setSheetMapping: Dispatch<SetStateAction<SheetMap[]>>;
|
||||
|
||||
step: number;
|
||||
setStep: Dispatch<SetStateAction<number>>;
|
||||
|
||||
importId: string;
|
||||
setImportId: Dispatch<SetStateAction<string>>;
|
||||
|
||||
resource: string;
|
||||
}
|
||||
interface ImportFileProviderProps {
|
||||
resource: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const ImportFileContext = createContext<ImportFileContextValue>(
|
||||
{} as ImportFileContextValue,
|
||||
);
|
||||
|
||||
export const useImportFileContext = () => {
|
||||
const context = useContext<ImportFileContextValue>(ImportFileContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
'useImportFileContext must be used within an ImportFileProvider',
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
export const ImportFileProvider = ({
|
||||
resource,
|
||||
children,
|
||||
}: ImportFileProviderProps) => {
|
||||
const [sheetColumns, setSheetColumns] = useState<SheetColumn[]>([]);
|
||||
const [entityColumns, setEntityColumns] = useState<SheetColumn[]>([]);
|
||||
const [sheetMapping, setSheetMapping] = useState<SheetMap[]>([]);
|
||||
const [importId, setImportId] = useState<string>('');
|
||||
|
||||
const [step, setStep] = useState<number>(0);
|
||||
|
||||
const value = {
|
||||
sheetColumns,
|
||||
setSheetColumns,
|
||||
|
||||
entityColumns,
|
||||
setEntityColumns,
|
||||
|
||||
sheetMapping,
|
||||
setSheetMapping,
|
||||
|
||||
step,
|
||||
setStep,
|
||||
|
||||
importId,
|
||||
setImportId,
|
||||
|
||||
resource,
|
||||
};
|
||||
|
||||
return (
|
||||
<ImportFileContext.Provider value={value}>
|
||||
{children}
|
||||
</ImportFileContext.Provider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user