Skip to content

Commit

Permalink
refactor: Additional restructure and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 committed Jun 25, 2024
1 parent 9c34ce1 commit 991dda1
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/common/hooks/donation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QueryClient, useMutation, useQuery } from '@tanstack/react-query'
import { ApiErrors } from 'service/apiErrors'
import { AlertStore } from 'stores/AlertStore'
import { endpoints } from 'service/apiEndpoints'
import { authConfig, authQueryFnFactory } from 'service/restRequests'
import { authQueryFnFactory } from 'service/restRequests'
import {
CheckoutSessionInput,
CheckoutSessionResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { createContext } from 'react'
import { Actions, CreatePayment, createPaymentStepReducer } from './createPaymentStepReducer'
import CreatePaymentStepper from '../create-payment/CreatePaymentStepper'
import {
Actions,
CreatePayment,
createPaymentStepReducer,
} from './helpers/createPaymentStepReducer'
import CreatePaymentStepper from './CreatePaymentStepper'
import { observer } from 'mobx-react'

export type PaymentContext = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Button, Card, CardContent, Dialog, Grid, IconButton } from '@mui/material'

import { Form, Formik, useField, useFormikContext } from 'formik'
import { Form, Formik } from 'formik'
import React, { useContext } from 'react'
import * as yup from 'yup'
import { FileImportDialog } from './benevity/FileImportDialog'
import { benevityInputValidation, benevityValidation } from './benevity/helpers/validation'
import BenevityImportTypeSelector from './benevity/BenevityImportTypeSelector'
import CreatePaymentFromBenevityRecord from './benevity/CreatePaymentFromBenevityRecord'
import { PaymentContext } from '../store/CreatePaymentContext'
import { PaymentContext } from './CreatePaymentDialog'
import PaymentTypeSelector from './PaymentTypeSelector'
import { BenevityManualImport } from './benevity/BenevityManualImport'
import { stripeInputValidation } from './stripe/helpers/validations'
import { StripeChargeLookupForm } from './stripe/StripeChargeLookupForm'
import { SelectedPaymentSource } from '../store/createPaymentStepReducer'
import { SelectedPaymentSource } from './helpers/createPaymentStepReducer'
import { CreatePaymentFromStripeCharge } from './stripe/CreatePaymentFromStripeCharge'
import { ModalStore } from '../PaymentsPage'
import ArrowBackIcon from '@mui/icons-material/ArrowBack'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box, Button, Typography } from '@mui/material'
import { useTranslation } from 'next-i18next'
import React, { useContext } from 'react'
import { SelectedPaymentSource } from '../store/createPaymentStepReducer'
import { PaymentContext } from '../store/CreatePaymentContext'
import { SelectedPaymentSource } from './helpers/createPaymentStepReducer'
import { PaymentContext } from './CreatePaymentDialog'

export default function PaymentTypeSelector() {
const paymentContext = useContext(PaymentContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const BenevityInput = ({
}) => {
const { t } = useTranslation()
const [editable, setEditable] = useState(false)
const [field, meta, { setValue }] = useField(name)
const [field, meta] = useField(name)
const helperText = meta.touched ? translateError(meta.error as TranslatableField, t) : ''

const ref = useRef<HTMLDivElement | null>(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Box, Button, Typography } from '@mui/material'
import { useTranslation } from 'next-i18next'
import { CreatePaymentStore, TImportType } from '../../store/CreatePaymentStore'
import { observer } from 'mobx-react'
import { useContext } from 'react'
import { PaymentContext } from '../../store/CreatePaymentContext'
import { PaymentContext } from '../CreatePaymentDialog'
import { BenevityImportType } from '../helpers/createPaymentStepReducer'

function BenevityImportFirstStep() {
const { t } = useTranslation()
const paymentContext = useContext(PaymentContext)

const handleImportTypeChange = (importType: TImportType) => {
const handleImportTypeChange = (importType: BenevityImportType) => {
paymentContext.dispatch({ type: 'SET_BENEVITY_IMPORT_TYPE', payload: importType })
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Grid, Typography } from '@mui/material'
import { useMutation } from '@tanstack/react-query'
import { useImportBenevityDonation } from 'service/donation'
import { CreatePaymentStore, benevityInitialValues } from '../../store/CreatePaymentStore'
import { benevityInitialValues } from './helpers/form/initialValues'
import { useFormikContext } from 'formik'
import { AxiosError, AxiosResponse } from 'axios'
import { TPaymentResponse } from 'gql/donations'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { useField } from 'formik'
import { useRef, useState } from 'react'

export function FileImportDialog() {
const [isDragging, setIsDragging] = useState(false)
const [, setIsDragging] = useState(false)
const inputFile = useRef<HTMLInputElement | null>(null)
const submitButtonRef = useRef<HTMLButtonElement | null>(null)
const [field, meta, { setValue }] = useField('benevityData')
const [, , { setValue }] = useField('benevityData')

const onDragOver = (event: React.DragEvent) => {
event.preventDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FieldArray, useFormikContext } from 'formik'

import { BenevityImportInput } from '../benevity.types'
import { Delete } from '@mui/icons-material'
import { benevityDonationInitialValues } from '../../../../store/CreatePaymentStore'
import { benevityDonationInitialValues } from './initialValues'
import { BenevityInput } from '../../BenevityEditableInput'
import AddCircleIcon from '@mui/icons-material/AddCircle'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { TBenevityCSVParser, TBenevityDonation } from '../benevity.types'

export const benevityInitialValues: TBenevityCSVParser = {
charityId: '',
charityName: '',
currency: '',
donations: [],
periodEnding: '',
paymentMethod: '',
disbursementId: '',
checkFee: '',
totalDonationsGross: '',
netTotalPayment: 0,
transactionAmount: 0,
exchangeRate: 0,
note: '',
}

export const benevityDonationInitialValues: TBenevityDonation = {
company: '',
project: '',
donationDate: '',
donorFirstName: '',
donorLastName: '',
email: '',
address: '',
city: '',
stateProvince: '',
postalCode: '',
activity: '',
comment: '',
transactionId: '',
donationFrequency: '',
currency: '',
projectRemoteId: '',
source: '',
reason: '',
totalDonationToBeAcknowledged: 0,
matchAmount: 0,
causeSupportFee: 0,
merchantFee: 0,
feeComment: '',
totalFee: 0,
totalAmount: 0,
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { stripeFeeCalculator } from 'components/client/one-time-donation/helpers
import { StripeChargeResponse, TPaymentResponse } from 'gql/donations'
import React from 'react'
import { useTranslation } from 'next-i18next'
import { endpoints } from 'service/apiEndpoints'
import { useCreatePaymentFromStripeMutation } from 'service/donation'
import Stripe from 'stripe'
import { AlertStore } from 'stores/AlertStore'
Expand Down Expand Up @@ -73,7 +72,7 @@ export function CreatePaymentFromStripeChargeTable({
<Grid item>
<TableContainer>
<TableHead>
<TableCell></TableCell>
<TableCell />
<TableCell>База данни на Страйп</TableCell>
<TableCell>Вътрена база данни</TableCell>
</TableHead>
Expand Down
4 changes: 2 additions & 2 deletions src/components/admin/payments/grid/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react'
import { UseQueryResult } from '@tanstack/react-query'
import { useTranslation } from 'next-i18next'
import { Box, Button, IconButton, Tooltip } from '@mui/material'
import { Box, IconButton, Tooltip } from '@mui/material'
import { Edit } from '@mui/icons-material'
import {
DataGrid,
Expand Down Expand Up @@ -30,7 +30,7 @@ import { PaymentStatus, PaymentProvider } from '../../../../gql/donations.enums'
import { useSession } from 'next-auth/react'
import { PaymentAdminResponse } from 'gql/donations'
import Link from 'next/link'
import CreatePaymentDialog from '../store/CreatePaymentContext'
import CreatePaymentDialog from '../create-payment/CreatePaymentDialog'

interface RenderCellProps {
params: GridRenderCellParams
Expand Down
1 change: 0 additions & 1 deletion src/components/admin/payments/grid/GridAppbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useRouter } from 'next/router'
import { useTranslation } from 'next-i18next'
import {
Box,
Button,
FormControl,
IconButton,
InputLabel,
Expand Down
80 changes: 0 additions & 80 deletions src/components/admin/payments/store/CreatePaymentStore.ts

This file was deleted.

0 comments on commit 991dda1

Please sign in to comment.