Skip to content

Commit 8d90c5f

Browse files
committed
Resolves #15, adds the ability to delete account, change password .etc.
1 parent 0f08b10 commit 8d90c5f

File tree

6 files changed

+83
-13
lines changed

6 files changed

+83
-13
lines changed

ui/src/components/navbar/NavAuthLinks.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import useAuthValid from "../../hooks/useAuthValid";
1+
import {useAuthValidWithModel} from "../../hooks/useAuthValid";
22
import URLS from "../../helpers/URLS";
33
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
44
import {faUserCircle} from "@fortawesome/free-solid-svg-icons/faUserCircle";
@@ -11,7 +11,7 @@ import NavBarDropdownLink, {
1111
} from "./NavBarDropdownLink";
1212

1313
export default function NavAuthLinks() {
14-
const authValid = useAuthValid();
14+
const [authValid, model] = useAuthValidWithModel();
1515

1616
if (authValid) {
1717
return <>
@@ -23,7 +23,7 @@ export default function NavAuthLinks() {
2323
</NavBarDropdownLinkText>
2424
<NavBarDropdownItemContainer>
2525
<NavBarDropdownItem>
26-
<NavBarLink href={URLS.USER_SETTINGS}>Account</NavBarLink>
26+
<NavBarLink href={URLS.USER_SETTINGS + "/" + model?.id}>Account</NavBarLink>
2727
</NavBarDropdownItem>
2828
<NavBarDropdownItem>
2929
<NavBarLink href={URLS.LOGOUT}>Logout</NavBarLink>

ui/src/helpers/URLS.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const URLS: { [key: string]: string } = {
66
LOGOUT: "/auth/logout",
77
OAUTH2_REDIRECT: "/auth/oauth",
88
FORGOT_PASSWORD: "/auth/forgot-password",
9-
RESET_PASSWORD: "/auth/reset-password/:token",
9+
RESET_PASSWORD: "/auth/reset-password",
1010
CHANGE_PASSWORD: "/auth/change-password",
1111
USER_SETTINGS: "/dashboard/user",
1212
}

ui/src/main.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import OAuth from "./routes/OAuth";
1818
import ForgotPassword from "./routes/ForgotPassword";
1919
import ResetPassword from "./routes/ResetPassword";
2020
import ChangePassword from "./routes/ChangePassword";
21-
import User from "./routes/Dashboards/User";
21+
import User, {userLoader} from "./routes/Dashboards/User";
2222

2323
const router = createBrowserRouter([
2424
{
@@ -41,7 +41,7 @@ const router = createBrowserRouter([
4141
element: <ForgotPassword/>,
4242
},
4343
{
44-
path: URLS.RESET_PASSWORD,
44+
path: URLS.RESET_PASSWORD + "/:token" ,
4545
element: <ResetPassword/>
4646
},
4747
{
@@ -85,8 +85,9 @@ const router = createBrowserRouter([
8585
errorElement: <DashboardError/>,
8686
},
8787
{
88-
path: "user",
88+
path: "user/:id",
8989
element: <User />,
90+
loader: userLoader,
9091
}
9192
]
9293
},

ui/src/routes/Dashboards/Team.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import SelectInput, {DashboardSelectItem} from "../../components/dashboard/Selec
2727
import DashboardObjectActions from "../../components/dashboard/DashboardObjectActions";
2828
import DashboardObjectAction from "../../components/dashboard/DashboardObjectAction";
2929
import {faTrash} from "@fortawesome/free-solid-svg-icons/faTrash";
30+
import DashboardObjectBody from "../../components/dashboard/DashboardObjectBody";
3031

3132
const userRoles: DashboardSelectItem[] = [
3233
{
@@ -404,6 +405,9 @@ export default function Team() {
404405
</DashboardObjectHeaderIcon>
405406
<DashboardObjectHeaderName>Add Member</DashboardObjectHeaderName>
406407
</DashboardObjectHeader>
408+
<DashboardObjectBody>
409+
<p>Also allows transfer of ownership.</p>
410+
</DashboardObjectBody>
407411
</DashboardObject>
408412
</DashboardObjectsList>
409413
</DashboardObjects>}

ui/src/routes/Dashboards/User.tsx

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Link, useNavigate} from "react-router-dom";
1+
import {Link, useLoaderData, useNavigate} from "react-router-dom";
22
import Content from "../../components/general/Content";
33
import DashboardSpacer from "../../components/dashboard/DashboardSpacer";
44
import SettingButtons from "../../components/dashboard/config/SettingButtons";
@@ -7,11 +7,36 @@ import DashboardNavbar from "../../components/navbar/DashboardNavbar";
77
import {useAuthValidWithModel} from "../../hooks/useAuthValid";
88
import useAuthRedirect from "../../hooks/useAuthRedirect";
99
import URLS from "../../helpers/URLS";
10+
import pocketbase from "../../libraries/Pocketbase";
11+
import {ListResult} from "pocketbase";
12+
import {TeamRecord} from "../../types/Structures";
13+
import {useState} from "preact/compat";
1014

1115
export default function User() {
1216
const [, model] = useAuthValidWithModel();
1317
const navigate = useNavigate();
1418
useAuthRedirect(URLS.LOGIN, false);
19+
const [confirmDelete, setConfirmDelete] = useState(false);
20+
const [message, setMessage] = useState("");
21+
22+
const teams = useLoaderData() as ListResult<TeamRecord>;
23+
24+
const deleteAccount = () => {
25+
if (!confirmDelete) {
26+
setConfirmDelete(true);
27+
setMessage("Are you sure you want to delete your account? This action is irreversible! Click the button again to confirm.");
28+
return;
29+
}
30+
31+
console.log(model?.id)
32+
33+
pocketbase.collection('users').delete(model?.id as string).then(() => {
34+
pocketbase.authStore?.clear();
35+
navigate(URLS.HOME);
36+
}).catch(() => {
37+
setMessage("An error occurred while deleting your account. Please try again later.")
38+
});
39+
}
1540

1641
return <>
1742
<DashboardNavbar>
@@ -35,20 +60,30 @@ export default function User() {
3560

3661
<h1 className="action-header">Delete account</h1>
3762

38-
<p>If you want to, you can delete your ConfigDN account. This actions is irreversible! Any teams you are the owner of will also be deleted.</p>
63+
<p>If you want to, you can delete your ConfigDN account. This actions is <strong>irreversible</strong>! <strong>All teams</strong> you are the owner of will also be deleted.</p>
3964

4065
<p>You currently own the following teams:</p>
4166

42-
<ul>
43-
<li>Test</li>
67+
<ul class="owned-teams-list">
68+
{
69+
teams.items.map(v => <li><a href={URLS.DASHBOARD + "/" + v.id}>{v.name}</a></li>)
70+
}
4471
</ul>
4572

73+
<p>You can transfer them by clicking on the links above, choosing add member, then owner and set the owner to the new owner.</p>
74+
4675
<SettingButtons>
47-
<SettingButton onClick={() => navigate(URLS.CHANGE_PASSWORD)}
48-
type={"Change Password"}/>
76+
<SettingButton onClick={() => deleteAccount()}
77+
type={"Delete Account"}/>
4978
</SettingButtons>
5079

80+
<p class="delete-account-warning">{message}</p>
81+
5182
<DashboardSpacer/>
5283
</Content>
5384
</>;
85+
}
86+
87+
export function userLoader({params}: { params: any }) {
88+
return pocketbase.collection('team').getList(params.team, undefined, {expand: "owner", filter: `owner = "${params.id}"`});
5489
}

ui/src/styles/style.scss

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,19 @@ div.page-transition {
931931
background: mix(mix($celadon-blue, $oxford-blue, 40%), $white, 70%)
932932
}
933933
}
934+
935+
&.button__delete-account {
936+
// a dark mixed red
937+
background-color: #900;
938+
939+
&:hover {
940+
background-color: mix(#900, #fff, 80%);
941+
}
942+
943+
&:active {
944+
background-color: mix(#900, #fff, 70%);
945+
}
946+
}
934947
}
935948
}
936949

@@ -1239,6 +1252,23 @@ div.page-transition {
12391252
margin-top: 20px;
12401253
}
12411254
}
1255+
1256+
ul.owned-teams-list {
1257+
padding: 10px 15px;
1258+
1259+
li {
1260+
list-style-type: disc;
1261+
text-decoration: underline;
1262+
}
1263+
}
1264+
1265+
.delete-account-warning {
1266+
font-size: 1.5em;
1267+
margin-top: 20px;
1268+
margin-bottom: 10px;
1269+
1270+
color: #900;
1271+
}
12421272
}
12431273

12441274
// Auth pages (login, register)

0 commit comments

Comments
 (0)