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

[REFACTORING]: deleting the duplicated code #82

Merged
merged 17 commits into from
Jan 22, 2025
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
317 changes: 317 additions & 0 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions v6y-apps/front-bo/src/commons/components/VitalityBaseTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Table } from 'antd';
import { AnyObject } from 'antd/es/_util/type';
import React from 'react';

const VitalityTable = ({
dataSource,
columns,
}: {
dataSource: AnyObject[];
columns: AnyObject[];
}) => <Table dataSource={dataSource} columns={columns} rowKey="key" />;

export default VitalityTable;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HttpError } from '@refinedev/core';
import { Descriptions, Typography } from 'antd';
import { VitalityText } from '@v6y/shared-ui';
import { Descriptions } from 'antd';
import * as React from 'react';
import { ReactNode } from 'react';

Expand All @@ -20,7 +21,7 @@ const VitalityDetailsView = ({
<Descriptions bordered size="middle" column={1}>
{Object.keys(details).map((itemKey, index) => (
<Descriptions.Item key={`${itemKey}-${index}`} label={itemKey}>
<Typography.Text>{details[itemKey]}</Typography.Text>
<VitalityText text={details[itemKey] as string} />
</Descriptions.Item>
))}
</Descriptions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Empty, Typography } from 'antd';
import { VitalityText } from '@v6y/shared-ui';
import { Empty } from 'antd';
import * as React from 'react';

import { useTranslation } from '../../infrastructure/adapters/translation/TranslationAdapter';

Expand All @@ -7,7 +9,7 @@ const VitalityEmptyView = ({ message }: { message?: string }) => {
return (
<Empty
description={
<Typography.Text>{message || translate('pages.error.empty-data')}</Typography.Text>
<VitalityText text={message || translate('pages.error.empty-data') || ''} />
}
/>
);
Expand Down
6 changes: 4 additions & 2 deletions v6y-apps/front-bo/src/commons/components/VitalityLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { LinkType } from '@v6y/core-logic';
import { Col, Row, Typography } from 'antd';
import { VitalityText } from '@v6y/shared-ui';
import { Col, Row } from 'antd';
import Link from 'next/link';
import * as React from 'react';

type ContentJustify =
| 'end'
Expand Down Expand Up @@ -34,7 +36,7 @@ const VitalityLinks = ({ links, align }: { links: LinkType[]; align: ContentJust
rel="noopener noreferrer"
style={{ textDecoration: 'underline' }}
>
<Typography.Text>{link.label}</Typography.Text>
<VitalityText text={link.label} />
</Link>
</Col>
);
Expand Down
37 changes: 27 additions & 10 deletions v6y-apps/front-bo/src/commons/components/VitalityTable.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import { Table } from 'antd';
import { AnyObject } from 'antd/es/_util/type';

const VitalityTable = ({
dataSource,
columns,
}: {
dataSource: AnyObject[];
columns: AnyObject[];
}) => <Table dataSource={dataSource} columns={columns} rowKey="key" />;
import React from 'react';

import { buildCommonTableColumns, buildCommonTableDataSource } from '../config/VitalityTableConfig';
import VitalityBaseTable from './VitalityBaseTable';

interface VitalityTableProps {
dataSource: unknown[];
columnKeys: string[];
columnOptions: {
enableEdit: boolean;
enableShow: boolean;
enableDelete: boolean;
deleteMetaQuery?: {
gqlMutation: string;
operation: string;
};
};
}

const VitalityTable: React.FC<VitalityTableProps> = ({ dataSource, columnKeys, columnOptions }) => {
return (
<VitalityBaseTable
dataSource={buildCommonTableDataSource(dataSource)}
columns={buildCommonTableColumns(dataSource, columnKeys, columnOptions)}
/>
);
};

export default VitalityTable;
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@

import { DownOutlined } from '@ant-design/icons';
import { useGetIdentity } from '@refinedev/core';
import {
Layout as AntdLayout,
Avatar,
Button,
Dropdown,
Space,
Switch,
Typography,
theme,
} from 'antd';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import { VitalityText } from '@v6y/shared-ui';
import { Layout as AntdLayout, Avatar, Button, Dropdown, Space, Switch, theme } from 'antd';
import Cookie from 'js-cookie';
import * as React from 'react';
import { useContext } from 'react';
Expand Down Expand Up @@ -77,9 +67,7 @@ export const VitalityPageHeader = () => {
<Button type="text">
<Space>
<Avatar size={16} src={`/images/flags/${currentLocale}.svg`} />
<Typography.Text>
{currentLocale === 'en' ? 'English' : 'French'}
</Typography.Text>
<VitalityText text={currentLocale === 'en' ? 'English' : 'French'} />
<DownOutlined />
</Space>
</Button>
Expand All @@ -96,7 +84,7 @@ export const VitalityPageHeader = () => {
/>
{(user?.name || user?.avatar) && (
<Space style={{ marginLeft: '8px' }} size="middle">
{user?.name && <Typography.Text strong>{user.name}</Typography.Text>}
{user?.name && <VitalityText strong text={user.name} />}
{user?.avatar && <Avatar src={user?.avatar} alt={user?.name} />}
</Space>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { ThemedLayoutV2 } from '@refinedev/antd';
import { Typography } from 'antd';
import { VitalityTitle } from '@v6y/shared-ui';
import * as React from 'react';
import { ReactNode } from 'react';

Expand All @@ -12,14 +12,13 @@ const VitalityPageLayout = ({ children }: { children: ReactNode }) => {
return (
<ThemedLayoutV2
Title={() => (
<Typography.Title
<VitalityTitle
level={1}
style={{
marginTop: '1rem',
}}
>
V6Y
</Typography.Title>
title="V6Y"
/>
)}
Header={() => <VitalityPageHeader />}
Footer={() => <VitalityPageFooter />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use client';

import { ApplicationType } from '@v6y/core-logic/src/types/ApplicationType';
import { Typography } from 'antd';
import { VitalityTitle } from '@v6y/shared-ui';
import * as React from 'react';
import { useEffect, useState } from 'react';

import GetApplicationListByPageAndParams from '../../../commons/apis/getApplicationListByPageAndParams';
Expand Down Expand Up @@ -30,11 +31,7 @@ export default function VitalityAccountCreateView() {

return (
<RefineSelectWrapper
title={
<Typography.Title level={2}>
{translate('v6y-accounts.titles.create')}
</Typography.Title>
}
title={<VitalityTitle title="v6y-accounts.titles.create" />}
createOptions={{
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpError, useParsed } from '@refinedev/core';
import { AccountType } from '@v6y/core-logic';
import Matcher from '@v6y/core-logic/src/core/Matcher';
import { Typography } from 'antd';
import { VitalityTitle } from '@v6y/shared-ui';
import * as React from 'react';

import VitalityDetailsView from '../../../commons/components/VitalityDetailsView';
Expand Down Expand Up @@ -42,11 +42,7 @@ export default function VitalityAccountDetailsView() {

return (
<RefineShowWrapper
title={
<Typography.Title level={2}>
{translate('v6y-account.titles.show')}
</Typography.Title>
}
title={<VitalityTitle title="v6y-account.titles.show" />}
queryOptions={{
resource: 'getAccountDetailsByParams',
query: GetAccountDetailsByParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useParsed } from '@refinedev/core';
import { ApplicationType } from '@v6y/core-logic/src/types/ApplicationType';
import { Typography } from 'antd';
import { VitalityTitle } from '@v6y/shared-ui';
import { useEffect, useState } from 'react';
import React from 'react';

Expand Down Expand Up @@ -35,11 +35,7 @@ export default function VitalityAccountEditView() {

return (
<RefineSelectWrapper
title={
<Typography.Title level={2}>
{translate('v6y-accounts.titles.edit')}
</Typography.Title>
}
title={<VitalityTitle title="v6y-accounts.titles.edit" />}
queryOptions={{
queryFormAdapter: accountCreateOrEditFormInAdapter,
query: GetAccountDetailsByParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import VitalityTable from '../../../commons/components/VitalityTable';
import {
buildCommonTableColumns,
buildCommonTableDataSource,
} from '../../../commons/config/VitalityTableConfig';
import RenderVitalityTable from '../../../commons/components/VitalityTable';
import { useTranslation } from '../../../infrastructure/adapters/translation/TranslationAdapter';
import RefineTableWrapper from '../../../infrastructure/components/RefineTableWrapper';
import DeleteAccount from '../apis/deleteAccount';
Expand All @@ -26,17 +22,18 @@ export default function VitalityAccountListView() {
query: GetAccountListByPageAndParams,
}}
renderTable={(dataSource) => (
<VitalityTable
dataSource={buildCommonTableDataSource(dataSource)}
columns={buildCommonTableColumns(dataSource, [], {
<RenderVitalityTable
dataSource={dataSource}
columnKeys={[]}
columnOptions={{
enableEdit: true,
enableShow: true,
enableDelete: true,
deleteMetaQuery: {
gqlMutation: DeleteAccount,
operation: 'deleteAccount',
},
})}
}}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Typography } from 'antd';
import { VitalityTitle } from '@v6y/shared-ui';
import * as React from 'react';

import {
Expand All @@ -13,11 +13,7 @@ export default function VitalityApplicationCreateView() {
const { translate } = useTranslation();
return (
<RefineCreateWrapper
title={
<Typography.Title level={2}>
{translate('v6y-applications.titles.create')}
</Typography.Title>
}
title={<VitalityTitle title="v6y-applications.titles.create" />}
createOptions={{
createFormAdapter: applicationCreateOrEditFormOutputAdapter,
createQuery: CreateOrEditApplication,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpError, useParsed } from '@refinedev/core';
import { ApplicationType } from '@v6y/core-logic';
import Matcher from '@v6y/core-logic/src/core/Matcher';
import { Typography } from 'antd';
import { VitalityTitle } from '@v6y/shared-ui';
import * as React from 'react';

import VitalityDetailsView from '../../../commons/components/VitalityDetailsView';
Expand Down Expand Up @@ -42,11 +42,7 @@ export default function VitalityApplicationDetailsView() {

return (
<RefineShowWrapper
title={
<Typography.Title level={2}>
{translate('v6y-applications.titles.show')}
</Typography.Title>
}
title={<VitalityTitle title="v6y-applications.titles.show" />}
queryOptions={{
resource: 'getApplicationDetailsInfoByParams',
query: GetApplicationDetails,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useParsed } from '@refinedev/core';
import { Typography } from 'antd';
import { VitalityTitle } from '@v6y/shared-ui';
import * as React from 'react';

import {
Expand All @@ -18,11 +18,7 @@ export default function VitalityApplicationEditView() {

return (
<RefineEditWrapper
title={
<Typography.Title level={2}>
{translate('v6y-applications.titles.edit')}
</Typography.Title>
}
title={<VitalityTitle title="v6y-applications.titles.edit" />}
queryOptions={{
queryFormAdapter: applicationCreateOrEditFormInAdapter as (
data: unknown,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { ApplicationType } from '@v6y/core-logic';

import GetApplicationListByPageAndParams from '../../../commons/apis/getApplicationListByPageAndParams';
import VitalityTable from '../../../commons/components/VitalityTable';
import {
buildCommonTableColumns,
buildCommonTableDataSource,
} from '../../../commons/config/VitalityTableConfig';
import RenderVitalityTable from '../../../commons/components/VitalityTable';
import { useTranslation } from '../../../infrastructure/adapters/translation/TranslationAdapter';
import RefineTableWrapper from '../../../infrastructure/components/RefineTableWrapper';
import DeleteApplication from '../apis/deleteApplication';
Expand All @@ -28,17 +24,18 @@ export default function VitalityApplicationListView() {
query: GetApplicationListByPageAndParams,
}}
renderTable={(dataSource: ApplicationType[]) => (
<VitalityTable
dataSource={buildCommonTableDataSource(dataSource)}
columns={buildCommonTableColumns(dataSource, [], {
<RenderVitalityTable
dataSource={dataSource}
columnKeys={[]}
columnOptions={{
enableEdit: true,
enableShow: true,
enableDelete: true,
deleteMetaQuery: {
gqlMutation: DeleteApplication,
operation: 'deleteApplication',
},
})}
}}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpError, useParsed } from '@refinedev/core';
import { AuditHelpType } from '@v6y/core-logic';
import { Typography } from 'antd';
import { VitalityTitle } from '@v6y/shared-ui';
import * as React from 'react';

import VitalityDetailsView from '../../../commons/components/VitalityDetailsView';
Expand All @@ -16,11 +16,7 @@ export default function VitalityAuditHelpDetailsView() {

return (
<RefineShowWrapper
title={
<Typography.Title level={2}>
{translate('v6y-audit-helps.titles.show')}
</Typography.Title>
}
title={<VitalityTitle title="v6y-audit-helps.titles.show" />}
queryOptions={{
resource: 'getAuditHelpDetailsByParams',
query: GetAuditHelpDetailsByParams,
Expand Down
Loading
Loading