Skip to content

Commit

Permalink
fix/account: use account hook to refactor page 'my/company'
Browse files Browse the repository at this point in the history
Signed-off-by: Chang Wei <[email protected]>
  • Loading branch information
cw1997 committed Oct 17, 2022
1 parent dae770b commit ba482d0
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/pages/my/company/index.page.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import React, { useContext, useEffect } from 'react';
import React, { useEffect } from 'react';
import useSWR, { useSWRConfig } from 'swr';
import { api } from '@tidb-community/datasource';

import { AuthContext, MeContext } from '~/context';
import { CommunityHead, PageLoader } from '~/components';
import { CommunityHead } from '~/components';
import { redDots as redDotsUtils } from '~/utils';

import * as Styled from './company.styled';
import Form from './form';
import Layout from '../layout';
import Verification from '../company/Verification.component';
import { Space } from 'antd';
import { useIsLoggedIn } from '~/hooks/account';

const PageContent = ({ title }) => {
const { login, isAnonymous, isLoggedIn } = useContext(AuthContext);
const isLoggedIn = useIsLoggedIn();
const { data: redDotsResp } = useSWR(isLoggedIn && 'operation.fetchRedDots');
const { meData } = useContext(MeContext);
const { mutate } = useSWRConfig();

const redDots = redDotsUtils.transformRespToMap(redDotsResp);
Expand All @@ -24,20 +22,11 @@ const PageContent = ({ title }) => {
(async () => {
if (redDots.companyInfo) {
await api.operation.setRedDotRead('company-info');
mutate('operation.fetchRedDots');
await mutate('operation.fetchRedDots');
}
})();
}, [redDots.companyInfo, mutate]);

if (isAnonymous) {
login();
return null;
}

if (!meData) {
return <PageLoader />;
}

const titleNode = (
<Space>
<div>{title}</div>
Expand Down

0 comments on commit ba482d0

Please sign in to comment.