Skip to content

Commit

Permalink
feat(FT-25): pages
Browse files Browse the repository at this point in the history
* feat(pages): add rules page

* feat(pages): add page management
  • Loading branch information
jonassimoen authored Nov 30, 2023
1 parent bb94e60 commit 61ae2aa
Show file tree
Hide file tree
Showing 10 changed files with 535 additions and 198 deletions.
17 changes: 16 additions & 1 deletion src/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
"portraitUrl": {
"required": "Portret afbeelding vereist"
}
},
"page": {
"translation": {
"langCode": "Taalcode",
"body": "Tekst"
},
"slug": "Afkorting"
}
},
"form": {
Expand Down Expand Up @@ -121,6 +128,13 @@
},
"week": {
"add": "Voeg matchweek toe"
},
"page": {
"add": "Voeg pagina toe",
"translation": {
"add": "Voeg vertaling toe"
},
"remove": "Verwijder"
}
},
"modal": {
Expand Down Expand Up @@ -178,5 +192,6 @@
"weekWinnerPoints": "winnaar",
"statsBlockTitle": "Statistieken",
"overviewBlockTitle": "Overzicht"
}
},
"pageTitle": "Pagina"
}
16 changes: 10 additions & 6 deletions src/pages/Admin.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useAuth } from "@/lib/stores/AuthContext";
import { useAppSelector } from "@/reducers";
import { CalendarOutlined, HomeOutlined, SkinOutlined, StarOutlined, UserOutlined } from "@ant-design/icons";
import { CalendarOutlined, CopyOutlined, HomeOutlined, SkinOutlined, StarOutlined, UserOutlined } from "@ant-design/icons";
import { Menu, MenuProps } from "antd";
import Title from "antd/es/typography/Title";
import { useContext, useState } from "react";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { Link, Navigate, Outlet, useLocation } from "react-router-dom";
import secureLocalStorage from "react-secure-storage";
Expand All @@ -14,6 +13,11 @@ const items: MenuProps["items"] = [
key: "admin",
icon: <HomeOutlined />,
},
{
label: (<Link to={{ pathname: "pages" }}>Pages</Link>),
key: "pages",
icon: <CopyOutlined />,
},
{
label: (<Link to={{ pathname: "players" }}>Players</Link>),
key: "players",
Expand Down Expand Up @@ -44,9 +48,9 @@ const items: MenuProps["items"] = [

export const Admin = (props: { redirectPath: string }) => {
const location = useLocation();

const user = useAppSelector((state) => state.userState.user);

const { t } = useTranslation();
const [current, setCurrent] = useState(location.pathname.split("/").pop() || "admin");
const onClick: MenuProps["onClick"] = (e) => {
Expand All @@ -64,7 +68,7 @@ export const Admin = (props: { redirectPath: string }) => {
return (
<>
<Title>{t("admin.welcome", { name: user?.firstName })}</Title>
<Menu style={{backgroundColor: "#f2f0f4"}} onClick={onClick} selectedKeys={[current]} mode="horizontal" items={items} />
<Menu style={{ backgroundColor: "#f2f0f4" }} onClick={onClick} selectedKeys={[current]} mode="horizontal" items={items} />
<Outlet />
</>
);
Expand Down
207 changes: 207 additions & 0 deletions src/pages/PageManagement/PageManagement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import { CreateModal } from "@/components/CreateModal";
import { EditModal } from "@/components/EditModal";
import { Button } from "@/components/UI/Button/Button";
import { FormItem } from "@/components/UI/Form/Form";
import { Col, Row } from "@/components/UI/Grid/Grid";
import { InputNumber } from "@/components/UI/InputNumber/InputNumber";
import { useCreatePageMutation, useDeletePageMutation, useGetPagesQuery, useUpdatePageMutation } from "@/services/pagesApi";
import { theme } from "@/styles/theme";
import { DeleteOutlined, EditOutlined, PlusOutlined } from "@ant-design/icons";
import { Divider, Form, Input, Table } from "antd";
import TextArea from "antd/lib/input/TextArea";
import Title from "antd/lib/typography/Title";
import React from "react";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { TranslationStyle } from "./PlayerManagementStyle";

declare type PageManagementState = {
openEditModal: boolean
openCreateModal: boolean
editObject?: Page
}

export const PageManagement = () => {
const { data: pages, isLoading: pagesLoading, isError: pagesError, isSuccess: pagesSucces } = useGetPagesQuery();
const [updatePage] = useUpdatePageMutation();
const [createPage] = useCreatePageMutation();
const [deletePage] = useDeletePageMutation();

const [state, setState] = useState<PageManagementState>({
openEditModal: false,
openCreateModal: false,
});

const { t } = useTranslation();

const PageForm =
<>
<Row>
<Col span={24}>
<FormItem
name={"slug"}
label={t("property.page.slug")}
>
<Input />
</FormItem>
</Col>
</Row>
<Form.List name="translation">
{(fields, { add, remove }) => (
<>
{
fields.map((field) => (
<Row key={field.key}>
<Col span={16}>
<Form.Item
label={t("property.page.translation.langCode")}
name={[field.name, "langCode"]}
>
<Input />
</Form.Item>
</Col>
<Col span={8}>
<Button
icon={<DeleteOutlined />}
onClick={() => remove(field.name)}
type="dashed"
style={{ marginTop: "30px" }}
>
{t("management.page.remove")}
</Button>
</Col>
<Col span={24}>
<Form.Item
label={t("property.page.translation.body")}
name={[field.name, "body"]}
>
<TextArea rows={10} />
</Form.Item>
</Col>
<Divider />
</Row>
))};

<Button
icon={<PlusOutlined />}
onClick={() => add()}
type="primary"
>
{t("management.page.add")}
</Button>
</>
)}
</Form.List>
</>;

return (
<>

<Row align='middle'>
<Col md={20} sm={12} xs={24}>
<Title level={2}>Pages management</Title>
</Col>
<Col md={4} sm={12} xs={24}>
<Button style={{ float: "right" }} icon={<PlusOutlined />} onClick={() => setState({ ...state, openCreateModal: true })} type="primary">{t("management.page.add")}</Button>
</Col>
</Row>

{pages && (
<Table
loading={pagesLoading}
dataSource={pages}
rowKey={"id"}
size="small"
rowClassName={"ant-table-row"}
pagination={{ position: ["bottomCenter"], showSizeChanger: false }}
columns={[
{
title: "ID",
dataIndex: "id",
width: "3%",
render: (txt: number, record: any) => {
return (
<p>{txt}</p>
);
},
sorter: (a: Player, b: Player) => b.id - a.id,

Check failure on line 127 in src/pages/PageManagement/PageManagement.tsx

View workflow job for this annotation

GitHub Actions / build

Type '(a: Player, b: Player) => number' is not assignable to type 'boolean | CompareFn<Page> | { compare?: CompareFn<Page>; multiple?: number; }'.
defaultSortOrder: "descend"
},
{
title: "Slug",
dataIndex: "slug",
width: "5%",
render: (txt: number, record: any) => {
return (
<p>{txt}</p>
);
}
},
{
title: "Translations",
dataIndex: "translation",
width: "5%",
render: (translations: PageTranslation[], record: any) => {
return translations.map((tl: PageTranslation) => (
<TranslationStyle key={`tl_${tl.id}`}>
<b>{tl.langCode}</b>
<p>{tl.body.slice(0, 100)}...</p>
</TranslationStyle>
));
},
},
{
dataIndex: "operation",
width: "10%",
align: "center",
render: (_: any, record: any) => {
return (
<>
<Button
icon={<EditOutlined />}
onClick={() => setState({ ...state, openEditModal: true, editObject: record })}
shape={"circle"}
type="primary"
/>
<Button
icon={<DeleteOutlined />}
onClick={() => deletePage(record)}
shape={"circle"}
type="primary"
/>
</>
);
}
}
]}
/>
)}
<EditModal
object={state.editObject}
open={state.openEditModal}
onCreate={(page: any) => { updatePage(page); setState({ ...state, openEditModal: false }); }}
onCancel={() => setState({ ...state, openEditModal: false })}
type='page'
action='edit'
>

<FormItem
name={"id"}
hidden={true}
>
<InputNumber />
</FormItem>
{PageForm}
</EditModal>
<CreateModal
open={state.openCreateModal}
object={{} as Page}
onCreate={(page: Page) => { console.log(page); createPage(page); setState({ ...state, openCreateModal: false }); }}
onCancel={() => setState({ ...state, openCreateModal: false })}
title={t("pageTitle")}
>
{PageForm}
</CreateModal>
</>
);
};
10 changes: 10 additions & 0 deletions src/pages/PageManagement/PlayerManagementStyle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import styled from "@/styles/styled-components";
import { theme } from "@/styles/theme";

export const TranslationStyle = styled.div`
b {
background-color: ${theme.primaryContrast};
color: ${theme.primaryColor};
padding: 5px;
}
`;
Loading

0 comments on commit 61ae2aa

Please sign in to comment.