Skip to content

Commit

Permalink
Merge pull request #203 from PKUHPC/enhance_init_move_to_different_path
Browse files Browse the repository at this point in the history
feat(mis):  move 4 sub-functions of mis-web to a different path
  • Loading branch information
tulvgengenr authored Oct 5, 2022
2 parents 9299b06 + 637e936 commit 04842cf
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 96 deletions.
71 changes: 71 additions & 0 deletions apps/mis-web/src/pageComponents/init/InitLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Button, Modal, Tabs } from "antd";
import Link from "next/link";
import Router, { useRouter } from "next/router";
import React from "react";
import { api } from "src/apis";
import { Centered } from "src/components/layouts";
import { Head } from "src/utils/head";
import styled from "styled-components";

type DrawerProps = {
children: React.ReactNode;
}

const Title = styled(Centered)`
position: relative;
`;

const CompleteButtonContainer = styled.div`
position: absolute;
right: 0;
`;

export const InitTab: React.FC = () => {
const TabItems = [
{ label: (<Link href="/init/importUsers">导入用户</Link>), key: "/init/importUsers" },
{ label: (<Link href="/init/users">用户账户管理</Link>), key: "/init/users" },
{ label: (<Link href="/init/createInitAdmin">创建初始管理员用户</Link>), key: "/init/createInitAdmin" },
{ label: (<Link href="/init/jobPriceTable">编辑作业价格表</Link>), key: "/init/jobPriceTable" },
];
return (
<div>
<Tabs centered items={TabItems} activeKey={useRouter().asPath}/>
</div>
);
};

export const InitDrawer: React.FC<DrawerProps> = (props) => {
const { children } = props;
return (
<div>
<Head title="系统初始化"/>
<Title>
<span />
<h1>系统初始化</h1>
<CompleteButtonContainer>
<Button type="primary" onClick={() => {
Modal.confirm({
title: "确认完成初始化",
content: "一旦完成初始化,您将无法进入此页面重新初始化。",
onOk: () => api.completeInit({}).then(() => {
Modal.success({
title: "初始化完成!",
content: "点击确认前往登录",
closable: false,
maskClosable: false,
onOk: () => Router.push("/api/auth"),
});
}),
});
}}
>
完成初始化
</Button>
</CompleteButtonContainer>
</Title>
<InitTab/>
<div>{children}</div>
</div>
);
};

100 changes: 4 additions & 96 deletions apps/mis-web/src/pages/init.tsx
Original file line number Diff line number Diff line change
@@ -1,101 +1,9 @@
import { Button, Modal, Result, Tabs } from "antd";
import { GetServerSideProps, NextPage } from "next";
import Router from "next/router";
import { api } from "src/apis";
import { NextPage } from "next";
import { SSRProps } from "src/auth/server";
import { UnifiedErrorPage } from "src/components/errorPages/UnifiedErrorPage";
import { Centered } from "src/components/layouts";
import { EditJobPriceTableForm } from "src/pageComponents/init/EditJobPriceTableForm";
import { InitAdminForm } from "src/pageComponents/init/InitAdminForm";
import { InitImportUsersForm } from "src/pageComponents/init/InitImportUsersForm";
import { InitUsersAndAccountsTable } from "src/pageComponents/init/InitUsersAndAccountsTable";
import { Head } from "src/utils/head";
import { queryIfInitialized } from "src/utils/init";
import styled from "styled-components";

import { Redirect } from "src/components/Redirect";
type Props = SSRProps<{}>;

const Title = styled(Centered)`
position: relative;
`;

const CompleteButtonContainer = styled.div`
position: absolute;
right: 0;
`;

export const InitSystemPage: NextPage<Props> = (props) => {

if ("error" in props) {
return (
<UnifiedErrorPage code={props.error}
customComponents={{
409: (
<Result
status="error"
title="系统已初始化"
subTitle="系统已经初始化完成,无法重新初始化!"
/>
),
}}
/>
);
}

return (
<div>
<Head title="系统初始化"/>
<Title>
<span />
<h1>系统初始化</h1>
<CompleteButtonContainer>
<Button type="primary" onClick={() => {
Modal.confirm({
title: "确认完成初始化",
content: "一旦完成初始化,您将无法进入此页面重新初始化。",
onOk: () => api.completeInit({}).then(() => {
Modal.success({
title: "初始化完成!",
content: "点击确认前往登录",
closable: false,
maskClosable: false,
onOk: () => Router.push("/api/auth"),
});
}),
});
}}
>
完成初始化
</Button>
</CompleteButtonContainer>
</Title>
<Tabs centered defaultActiveKey="1">
<Tabs.TabPane tab="导入用户" key="1">
<InitImportUsersForm />
</Tabs.TabPane>
<Tabs.TabPane tab="用户账户管理" key="2">
<InitUsersAndAccountsTable />
</Tabs.TabPane>
<Tabs.TabPane tab="创建初始管理员用户" key="3">
<InitAdminForm />
</Tabs.TabPane>
<Tabs.TabPane tab="编辑作业价格表" key="4">
<EditJobPriceTableForm />
</Tabs.TabPane>
</Tabs>
</div>
);

export const InitSystemPage: NextPage<Props> = () => {
return <Redirect url="/init/importUsers" />;
};

export const getServerSideProps: GetServerSideProps<Props> = async () => {

const result = await queryIfInitialized();

if (result) { return { props: { error: 409 } }; }

return { props: {} };

};

export default InitSystemPage;
48 changes: 48 additions & 0 deletions apps/mis-web/src/pages/init/createInitAdmin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Result } from "antd";
import { GetServerSideProps, NextPage } from "next";
import { useRouter } from "next/router";
import { SSRProps } from "src/auth/server";
import { UnifiedErrorPage } from "src/components/errorPages/UnifiedErrorPage";
import { InitAdminForm } from "src/pageComponents/init/InitAdminForm";
import { InitDrawer } from "src/pageComponents/init/InitLayout";
import { queryIfInitialized } from "src/utils/init";

type Props = SSRProps<{}>;

export const CreateInitAdminPage: NextPage<Props> = (props) => {
if ("error" in props) {
return (
<UnifiedErrorPage code={props.error}
customComponents={{
409: (
<Result
status="error"
title="系统已初始化"
subTitle="系统已经初始化完成,无法重新初始化!"
/>
),
}}
/>
);
}
return (
<div>
<InitDrawer url={useRouter().asPath}>
<InitAdminForm/>
</InitDrawer>
</div>
);

};

export const getServerSideProps: GetServerSideProps<Props> = async () => {

const result = await queryIfInitialized();

if (result) { return { props: { error: 409 } }; }

return { props: {} };

};

export default CreateInitAdminPage;
49 changes: 49 additions & 0 deletions apps/mis-web/src/pages/init/importUsers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Result } from "antd";
import { GetServerSideProps, NextPage } from "next";
import { useRouter } from "next/router";
import { SSRProps } from "src/auth/server";
import { UnifiedErrorPage } from "src/components/errorPages/UnifiedErrorPage";
import { InitImportUsersForm } from "src/pageComponents/init/InitImportUsersForm";
import { InitDrawer } from "src/pageComponents/init/InitLayout";
import { queryIfInitialized } from "src/utils/init";

type Props = SSRProps<{}>;

export const ImportUsersPage: NextPage<Props> = (props) => {
if ("error" in props) {
return (
<UnifiedErrorPage code={props.error}
customComponents={{
409: (
<Result
status="error"
title="系统已初始化"
subTitle="系统已经初始化完成,无法重新初始化!"
/>
),
}}
/>
);
}
return (
<div>
<InitDrawer url={useRouter().asPath}>
<InitImportUsersForm/>
</InitDrawer>
</div>
);

};

export const getServerSideProps: GetServerSideProps<Props> = async () => {

const result = await queryIfInitialized();

if (result) { return { props: { error: 409 } }; }

return { props: {} };

};


export default ImportUsersPage;
48 changes: 48 additions & 0 deletions apps/mis-web/src/pages/init/jobPriceTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Result } from "antd";
import { GetServerSideProps, NextPage } from "next";
import { useRouter } from "next/router";
import { SSRProps } from "src/auth/server";
import { UnifiedErrorPage } from "src/components/errorPages/UnifiedErrorPage";
import { EditJobPriceTableForm } from "src/pageComponents/init/EditJobPriceTableForm";
import { InitDrawer } from "src/pageComponents/init/InitLayout";
import { queryIfInitialized } from "src/utils/init";

type Props = SSRProps<{}>;

export const JobPriceTablePage: NextPage<Props> = (props) => {
if ("error" in props) {
return (
<UnifiedErrorPage code={props.error}
customComponents={{
409: (
<Result
status="error"
title="系统已初始化"
subTitle="系统已经初始化完成,无法重新初始化!"
/>
),
}}
/>
);
}
return (
<div>
<InitDrawer url={useRouter().asPath}>
<EditJobPriceTableForm/>
</InitDrawer>
</div>
);

};

export const getServerSideProps: GetServerSideProps<Props> = async () => {

const result = await queryIfInitialized();

if (result) { return { props: { error: 409 } }; }

return { props: {} };

};

export default JobPriceTablePage;
49 changes: 49 additions & 0 deletions apps/mis-web/src/pages/init/users.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Result } from "antd";
import { GetServerSideProps, NextPage } from "next";
import { useRouter } from "next/router";
import { SSRProps } from "src/auth/server";
import { UnifiedErrorPage } from "src/components/errorPages/UnifiedErrorPage";
import { InitDrawer } from "src/pageComponents/init/InitLayout";
import { InitUsersAndAccountsTable } from "src/pageComponents/init/InitUsersAndAccountsTable";
import { queryIfInitialized } from "src/utils/init";

type Props = SSRProps<{}>;

export const UsersPage: NextPage<Props> = (props) => {
if ("error" in props) {
return (
<UnifiedErrorPage code={props.error}
customComponents={{
409: (
<Result
status="error"
title="系统已初始化"
subTitle="系统已经初始化完成,无法重新初始化!"
/>
),
}}
/>
);
}
return (
<div>
<InitDrawer url={useRouter().asPath}>
<InitUsersAndAccountsTable/>
</InitDrawer>
</div>
);

};

export const getServerSideProps: GetServerSideProps<Props> = async () => {

const result = await queryIfInitialized();

if (result) { return { props: { error: 409 } }; }

return { props: {} };

};


export default UsersPage;

0 comments on commit 04842cf

Please sign in to comment.