Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/admin: Vault and Withdrawals improvements #1682

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/components/admin/vaults/VaultSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useField, useFormikContext } from 'formik'

import FormTextField from 'components/common/form/FormTextField'
import { VaultResponse } from 'gql/vault'
import { WithdrawalInput } from 'gql/withdrawals'

export type SetFieldValueType = (field: string, value: unknown, shouldValidate?: boolean) => void

Expand All @@ -24,7 +25,7 @@ export default function VaultSelect({
const { t } = useTranslation('vaults')

const [field, meta] = useField(name)
const { setFieldValue } = useFormikContext()
const { values, setFieldValue } = useFormikContext<WithdrawalInput>()

const handleChange = (event: React.ChangeEvent<{ value: unknown }>) => {
setFieldValue(name, event.target.value)
Expand All @@ -50,11 +51,13 @@ export default function VaultSelect({
<MenuItem value="" disabled>
{t(`fields.${name}`)}
</MenuItem>
{vaults?.map((value, index) => (
<MenuItem key={index} value={value.id}>
{value.name}
</MenuItem>
))}
{vaults
?.filter((vault) => vault.campaignId === values.sourceCampaignId)
.map((value, index) => (
<MenuItem key={index} value={value.id}>
{value.name}
</MenuItem>
))}
</FormTextField>
</FormControl>
)
Expand Down
28 changes: 23 additions & 5 deletions src/components/admin/vaults/grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import React, { useState } from 'react'
import { UseQueryResult } from '@tanstack/react-query'
import { useTranslation } from 'next-i18next'
import { Box } from '@mui/material'
import { DataGrid, GridColDef, GridRenderCellParams } from '@mui/x-data-grid'
import {
DataGrid,
GridColDef,
GridRenderCellParams,
GridValueFormatterParams,
} from '@mui/x-data-grid'
import { observer } from 'mobx-react'

import { routes } from 'common/routes'
Expand All @@ -17,7 +22,7 @@ import { money } from 'common/util/money'
import theme from 'common/theme'

export default observer(function Grid() {
const { t } = useTranslation('vaults')
const { t, i18n } = useTranslation('vaults')
const { data }: UseQueryResult<VaultResponse[]> = useVaultsList()
const { isDetailsOpen } = ModalStore
const [paginationModel, setPaginationModel] = useState({
Expand All @@ -31,7 +36,7 @@ export default observer(function Grid() {
headerAlign: 'left',
}

const columns: GridColDef[] = [
const columns: GridColDef<VaultResponse>[] = [
{
field: 'actions',
headerName: t('actions'),
Expand Down Expand Up @@ -78,27 +83,40 @@ export default observer(function Grid() {
),
},
{
field: 'reachedAmound',
field: 'reachedAmount',
headerName: t('amount'),
...commonProps,
renderCell: (params: GridRenderCellParams) => (
<>{money(params.row.amount - params.row.blockedAmount, params.row.currency)}</>
),
},
{
field: 'withdrawnAmount',
headerName: t('Успешно преведени'),
...commonProps,
renderCell: (params: GridRenderCellParams) => <>{money(params.row.withdrawnAmount)}</>,
},
{
field: 'createdAt',
headerName: t('createdAt'),
...commonProps,
valueFormatter(params: GridValueFormatterParams<Date>) {
return new Date(params.value).toLocaleDateString(i18n.language)
},
},
{
field: 'updatedAt',
headerName: t('updatedAt'),
...commonProps,
valueFormatter(params: GridValueFormatterParams<Date>) {
return new Date(params.value).toLocaleDateString(i18n.language)
},
},
{
field: 'campaignId',
headerName: t('campaignId'),
headerName: t('Кампания'),
...commonProps,
renderCell: (params: GridRenderCellParams) => <>{params.row.campaign.title}</>,
width: 450,
},
]
Expand Down
1 change: 1 addition & 0 deletions src/gql/vault.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type VaultResponse = {
campaign: Campaign
createdAt: Date
updatedAt: Date | null
withDrawnAmount: number
}

export type VaultInput = {
Expand Down
Loading