Skip to content

Commit

Permalink
feat: delete the ocr after the successful post request #2053
Browse files Browse the repository at this point in the history
  • Loading branch information
arealclimber committed Aug 14, 2024
1 parent 65efe77 commit 94b7660
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/step_one_tab/step_one_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const StepOneTab = () => {
const { t } = useTranslation('common');
const { cameraScannerVisibilityHandler, toastHandler } = useGlobalCtx();
const { selectedCompany } = useUserCtx();
const { OCRList, OCRListStatus, updateOCRListHandler, selectOCRHandler } = useAccountingCtx();
const { OCRList, OCRListStatus, updateOCRListHandler, selectOCRHandler, deleteOCRHandler } =
useAccountingCtx();
// Info: (20240809 - Shirley) disabled for now , 分頁功能在 alpha release 還沒實作
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [currentFilePage, setCurrentFilePage] = useState<number>(1);
Expand Down Expand Up @@ -114,6 +115,7 @@ const StepOneTab = () => {
closeable: true,
});
} else if (success) {
deleteOCRHandler(aichResultId);
toastHandler({
id: `deleteUnprocessedOCR-${code}`,
/* Info: (20240805 - Anna) 將上傳憑證的吐司通知翻譯 */
Expand Down
10 changes: 10 additions & 0 deletions src/contexts/accounting_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface IAccountingContext {
OCRList: IOCR[];
OCRListStatus: { listSuccess: boolean | undefined; listCode: string | undefined };
updateOCRListHandler: (companyId: number | undefined, update: boolean) => void;
deleteOCRHandler: (aichId: string) => void;
accountList: IAccount[];
getAccountListHandler: (
companyId: number,
Expand Down Expand Up @@ -122,6 +123,7 @@ const initialAccountingContext: IAccountingContext = {
OCRList: [],
OCRListStatus: { listSuccess: undefined, listCode: undefined },
updateOCRListHandler: () => {},
deleteOCRHandler: () => {},
accountList: [],
getAccountListHandler: () => {},
getAIStatusHandler: () => {},
Expand Down Expand Up @@ -285,6 +287,13 @@ export const AccountingProvider = ({ children }: IAccountingProvider) => {
}
};

const deleteOCRHandler = (aichId: string) => {
setOCRList((prev) => {
const rs = prev.filter((ocr) => ocr.aichResultId !== aichId);
return rs;
});
};

useEffect(() => {
if (accountSuccess && accountTitleList) {
setAccountList(accountTitleList.data);
Expand Down Expand Up @@ -566,6 +575,7 @@ export const AccountingProvider = ({ children }: IAccountingProvider) => {
OCRList,
OCRListStatus,
updateOCRListHandler,
deleteOCRHandler,
accountList,
getAccountListHandler,
getAIStatusHandler,
Expand Down

0 comments on commit 94b7660

Please sign in to comment.