Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Refactoring the settings view #397

Merged
merged 1 commit into from
Apr 2, 2022
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
2 changes: 1 addition & 1 deletion ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import Home from "./views/home"
import Repo from "./views/Repo"
import Deployment from "./views/Deployment"
import Settings from "./views/Settings"
import Settings from "./views/settings"
import Members from "./views/members"

function App(): JSX.Element {
Expand Down
59 changes: 0 additions & 59 deletions ui/src/views/Settings.tsx

This file was deleted.

20 changes: 20 additions & 0 deletions ui/src/views/settings/SlackDescriptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { shallowEqual } from "react-redux"
import { Button, Descriptions } from "antd"

import { useAppSelector } from "../../redux/hooks"

export default function SlackDescriptions(): JSX.Element {
const { user } = useAppSelector(state => state.settings, shallowEqual)

const connected = (user?.chatUser)? true : false

return (
<Descriptions title="Slack">
<Descriptions.Item>
{(connected)?
<Button href="/slack/signout" type="primary" danger>DISCONNECTED</Button>:
<Button href="/slack/" type="primary">CONNECT</Button>}
</Descriptions.Item>
</Descriptions>
)
}
35 changes: 35 additions & 0 deletions ui/src/views/settings/UserDescriptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { shallowEqual } from "react-redux"
import { Tag, Descriptions, Input } from "antd"

import { useAppSelector } from "../../redux/hooks"

export default function UserDescriptions(): JSX.Element {
const { user } = useAppSelector(state => state.settings, shallowEqual)

return (
<Descriptions
title="User Info"
column={2}
layout="vertical"
style={{marginTop: "40px"}}
>
<Descriptions.Item label="Login">
{user?.login}
</Descriptions.Item>
<Descriptions.Item label="Role">
{(user?.admin)?
<Tag color="purple">Admin</Tag>
:
<Tag color="purple">Member</Tag>}
</Descriptions.Item>
<Descriptions.Item label="Token">
<Input.Password
value={user?.hash}
style={{width: 200, padding:0 }}
readOnly
bordered={false}
/>
</Descriptions.Item>
</Descriptions>
)
}
38 changes: 38 additions & 0 deletions ui/src/views/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useEffect } from "react"
import { shallowEqual } from "react-redux"
import { Helmet } from "react-helmet"

import { useAppSelector, useAppDispatch } from "../../redux/hooks"
import { fetchMe, checkSlack } from "../../redux/settings"

import Main from "../main"
import UserDescription from "./UserDescriptions"
import SlackDescriptions from "./SlackDescriptions"

export default function Settings(): JSX.Element {
const { isSlackEnabled } = useAppSelector(state => state.settings, shallowEqual)
const dispatch = useAppDispatch()

useEffect(() => {
dispatch(fetchMe())
dispatch(checkSlack())
}, [dispatch])

return (
<Main>
<Helmet>
<title>Settings</title>
</Helmet>
<h1>Settings</h1>
<div>
<UserDescription />
</div>
{(isSlackEnabled)?
<div style={{marginTop: "40px", marginBottom: "20px"}}>
<SlackDescriptions />
</div>
:
<></>}
</Main>
)
}