diff --git a/README.md b/README.md index cb12588a9..a7f2f445f 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,9 @@ Watch releases of this repository to be notified about future updates: ## Contributors ✨ + [![All Contributors](https://img.shields.io/badge/all_contributors-69-orange.svg?style=flat-square)](#contributors-) + Please check [contributors guide](https://github.com/podkrepi-bg/frontend/blob/master/CONTRIBUTING.md) for: diff --git a/public/locales/bg/bank-transactions.json b/public/locales/bg/bank-transactions.json index ae54fd65a..1257c4e84 100644 --- a/public/locales/bg/bank-transactions.json +++ b/public/locales/bg/bank-transactions.json @@ -17,8 +17,10 @@ "to": "До", "apply-ref-heading": "Приложи код на кампания", "apply-ref": "Приложи кода", - "edit": "Редактирай" + "edit": "Редактирай", + "start-sync": "Стартирай синхронизация" }, "matched-ref": "Разпознат код", - "payment-ref": "Код на кампанията" + "payment-ref": "Код на кампанията", + "rerun-dates": "Повтори банково синхронизиране" } diff --git a/public/locales/en/expenses.json b/public/locales/en/expenses.json index 946378e24..8e04fda7b 100644 --- a/public/locales/en/expenses.json +++ b/public/locales/en/expenses.json @@ -38,7 +38,7 @@ "bank": "Bank", "advertising": "Advertising", "other": "Other" - }, + }, "alerts": { "new-row": { "error": "Error occurred trying to create an expense.", diff --git a/src/components/admin/bank-transactions/grid/GridAppbar.tsx b/src/components/admin/bank-transactions/grid/GridAppbar.tsx index 1ce8fe84a..d50d4a2ac 100644 --- a/src/components/admin/bank-transactions/grid/GridAppbar.tsx +++ b/src/components/admin/bank-transactions/grid/GridAppbar.tsx @@ -1,6 +1,6 @@ import { useTranslation } from 'next-i18next' import { Box, TextField, Toolbar, Tooltip, Typography } from '@mui/material' -import { GetApp as DownloadFileIcon } from '@mui/icons-material' +import { GetApp as DownloadFileIcon, RotateLeftOutlined } from '@mui/icons-material' import { useMutation } from '@tanstack/react-query' import { useExportToExcel } from 'service/bankTransaction' @@ -9,6 +9,7 @@ import { downloadFile } from '../../../../common/util/downloadFile' import { useMemo, useState } from 'react' import { useStores } from 'common/hooks/useStores' import { debounce } from 'lodash' +import RerunTransactionSyncModal from './RerunTransactionsSyncDialog' const addIconStyles = { background: '#4ac3ff', @@ -21,6 +22,7 @@ const addIconStyles = { export default function GridAppbar() { const { bankTransactionsStore } = useStores() const { t } = useTranslation() + const exportToExcel = useMutation({ mutationFn: useExportToExcel(), onError: () => AlertStore.show(t('common:alerts.error'), 'error'), @@ -29,6 +31,7 @@ export default function GridAppbar() { AlertStore.show(t('common:alerts.success'), 'success') }, }) + const [searchValue, setSearchValue] = useState('') const debounceSearch = useMemo( @@ -50,6 +53,15 @@ export default function GridAppbar() { debounceSearch(searchText) } + const [isRerunSyncOpen, setIsRerunSyncOpen] = useState(false) + const handleRerunSyncOpen = () => { + setIsRerunSyncOpen(true) + } + const handleRerunSyncClose = () => { + setIsRerunSyncOpen(false) + //TODO: refetch() after sync + } + return ( + + + handleRerunSyncOpen()} + /> + + + ) diff --git a/src/components/admin/bank-transactions/grid/RerunTransactionsSyncDialog.tsx b/src/components/admin/bank-transactions/grid/RerunTransactionsSyncDialog.tsx new file mode 100644 index 000000000..f13bf6d5b --- /dev/null +++ b/src/components/admin/bank-transactions/grid/RerunTransactionsSyncDialog.tsx @@ -0,0 +1,92 @@ +import { Dialog, Grid, DialogContent, DialogTitle } from '@mui/material' +import GenericForm from 'components/common/form/GenericForm' +import SubmitButton from 'components/common/form/SubmitButton' +import { useState } from 'react' +import { useTranslation } from 'next-i18next' +import * as yup from 'yup' +import CloseModalButton from 'components/common/CloseModalButton' +import { RerunTransactionsDatesInput } from 'gql/bank-transactions' +import { useRerunBankImportForDate } from 'service/bankTransaction' +import FormDatePicker from 'components/common/form/FormDatePicker' +import { useMutation } from '@tanstack/react-query' +import { AlertStore } from 'stores/AlertStore' + +const validationSchema: yup.SchemaOf = yup.object().defined().shape({ + startDate: yup.date().required(), + endDate: yup.date().required(), +}) + +export default function RerunTransactionSyncModal({ + isOpen, + handleClose, +}: { + isOpen: boolean + handleClose: () => void +}) { + const { t } = useTranslation() + const [loading, setLoading] = useState(false) + + const rerunSyncMutation = useMutation({ + mutationFn: useRerunBankImportForDate(), + onError: () => AlertStore.show(t('common:alerts.error'), 'error'), + onSuccess: () => { + AlertStore.show(t('common:alerts.success'), 'success') + handleClose() + }, + }) + + async function onSubmit(values: RerunTransactionsDatesInput) { + setLoading(true) + try { + await rerunSyncMutation.mutateAsync(values) + } finally { + setLoading(false) + } + } + + return ( + + + + + + + {t('bank-transactions:rerun-dates')} + + + + + + + + + + + + + + + + + + + ) +} diff --git a/src/gql/bank-transactions.ts b/src/gql/bank-transactions.ts index 16f5ce852..aa4c9b746 100644 --- a/src/gql/bank-transactions.ts +++ b/src/gql/bank-transactions.ts @@ -35,3 +35,8 @@ export type BankTransactionEditRefResponse = { paymentRef: string status: string } + +export type RerunTransactionsDatesInput = { + startDate: Date | string + endDate: Date | string +} diff --git a/src/service/apiEndpoints.ts b/src/service/apiEndpoints.ts index 6294e07c8..88fdec022 100644 --- a/src/service/apiEndpoints.ts +++ b/src/service/apiEndpoints.ts @@ -146,6 +146,7 @@ export const endpoints = { exportToExcel: { url: '/bank-transaction/export-excel', method: 'GET' }, editPaymentRef: (id: string) => { url: `/bank-transaction/${id}/edit-ref`, method: 'PUT' }, + rerunDates: { url: '/bank-transaction/rerun-dates', method: 'POST' }, }, documents: { documentsList: { url: '/document', method: 'GET' }, diff --git a/src/service/bankTransaction.ts b/src/service/bankTransaction.ts index d1b05a42b..3aee89c0e 100644 --- a/src/service/bankTransaction.ts +++ b/src/service/bankTransaction.ts @@ -1,5 +1,10 @@ import { AxiosResponse } from 'axios' -import { BankTransactionEditRefInput, BankTransactionEditRefResponse } from 'gql/bank-transactions' +import { + BankTransactionEditRefInput, + BankTransactionEditRefResponse, + BankTransactionsHistoryResponse, + RerunTransactionsDatesInput, +} from 'gql/bank-transactions' import { useSession } from 'next-auth/react' import { apiClient } from './apiClient' import { endpoints } from './apiEndpoints' @@ -24,3 +29,14 @@ export function useEditTransactionPaymentRef(slug: string) { >(endpoints.bankTransactions.editPaymentRef(slug).url, data, authConfig(session?.accessToken)) } } + +export const useRerunBankImportForDate = () => { + const { data: session } = useSession() + return async (transactionDates: RerunTransactionsDatesInput) => { + return await apiClient.post>( + endpoints.bankTransactions.rerunDates.url, + transactionDates, + authConfig(session?.accessToken), + ) + } +}