feat(dashboard): rewrite system privacy and add pronouns
This commit is contained in:
parent
267e85b891
commit
68d15b98f7
@ -1,9 +1,10 @@
|
|||||||
interface SystemPrivacy {
|
export interface SystemPrivacy {
|
||||||
description_privacy?: string,
|
description_privacy?: string,
|
||||||
member_list_privacy?: string,
|
member_list_privacy?: string,
|
||||||
front_privacy?: string,
|
front_privacy?: string,
|
||||||
front_history_privacy?: string,
|
front_history_privacy?: string,
|
||||||
group_list_privacy?: string
|
group_list_privacy?: string,
|
||||||
|
pronoun_privacy?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface System {
|
export interface System {
|
||||||
|
@ -4,12 +4,22 @@
|
|||||||
import FaUserLock from 'svelte-icons/fa/FaUserLock.svelte';
|
import FaUserLock from 'svelte-icons/fa/FaUserLock.svelte';
|
||||||
import PrivacyEdit from './PrivacyEdit.svelte';
|
import PrivacyEdit from './PrivacyEdit.svelte';
|
||||||
|
|
||||||
import { System } from '../../api/types';
|
import { System, SystemPrivacy } from '../../api/types';
|
||||||
|
|
||||||
export let user: System;
|
export let user: System;
|
||||||
let editMode = false;
|
let editMode = false;
|
||||||
|
|
||||||
let loading: boolean;
|
let loading: boolean;
|
||||||
|
|
||||||
|
const privacyNames: { [P in keyof SystemPrivacy]-?: string; } = {
|
||||||
|
description_privacy: "Description",
|
||||||
|
member_list_privacy: "Member list",
|
||||||
|
front_privacy: "Front",
|
||||||
|
front_history_privacy: "Front history",
|
||||||
|
group_list_privacy: "Group list",
|
||||||
|
pronoun_privacy: "Pronouns"
|
||||||
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card class="mb-4">
|
<Card class="mb-4">
|
||||||
@ -23,24 +33,14 @@
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardBody style="border-left: 4px solid #{user.color}">
|
<CardBody style="border-left: 4px solid #{user.color}">
|
||||||
{#if editMode}
|
{#if editMode}
|
||||||
<PrivacyEdit bind:loading bind:user={user} bind:editMode/>
|
<PrivacyEdit bind:user={user} bind:editMode/>
|
||||||
{:else}
|
{:else}
|
||||||
<Row>
|
<Row>
|
||||||
|
{#each Object.keys(user.privacy) as x}
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
<Col xs={12} lg={4} class="mb-3">
|
||||||
<b>Description:</b> {user.privacy.description_privacy}
|
<b>{privacyNames[x]}:</b> {user.privacy[x]}
|
||||||
</Col>
|
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
|
||||||
<b>Member list:</b> {user.privacy.member_list_privacy}
|
|
||||||
</Col>
|
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
|
||||||
<b>Group list:</b> {user.privacy.group_list_privacy}
|
|
||||||
</Col>
|
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
|
||||||
<b>Current front:</b> {user.privacy.front_privacy}
|
|
||||||
</Col>
|
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
|
||||||
<b>Front history:</b> {user.privacy.front_history_privacy}
|
|
||||||
</Col>
|
</Col>
|
||||||
|
{/each}
|
||||||
</Row>
|
</Row>
|
||||||
<Button style="flex: 0" color="primary" on:click={() => editMode = true} aria-label="edit system privacy">Edit</Button>
|
<Button style="flex: 0" color="primary" on:click={() => editMode = true} aria-label="edit system privacy">Edit</Button>
|
||||||
<Link to="/dash/bulk-member-privacy"><Button style="flex: 0" color="secondary" tabindex={-1}>Bulk member privacy</Button></Link>
|
<Link to="/dash/bulk-member-privacy"><Button style="flex: 0" color="secondary" tabindex={-1}>Bulk member privacy</Button></Link>
|
||||||
|
@ -1,96 +1,76 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Input, Row, Col, Button, Label, Alert } from 'sveltestrap';
|
import { Input, Row, Col, Button, Label, Alert, Spinner } from 'sveltestrap';
|
||||||
import { currentUser } from '../../stores';
|
import { currentUser } from '../../stores';
|
||||||
|
|
||||||
import { System } from '../../api/types';
|
import { System, SystemPrivacy } from '../../api/types';
|
||||||
import api from '../../api';
|
import api from '../../api';
|
||||||
|
|
||||||
export let loading = false;
|
|
||||||
export let user: System;
|
export let user: System;
|
||||||
export let editMode: boolean;
|
export let editMode: boolean;
|
||||||
|
|
||||||
let err: string;
|
let err: string;
|
||||||
|
let success = false;
|
||||||
|
let loading = false;
|
||||||
|
|
||||||
let input: System = {privacy: user.privacy};
|
function changeAll(e: Event) {
|
||||||
|
const target = e.target as HTMLInputElement;
|
||||||
|
Object.keys(privacy).forEach(x => privacy[x] = target.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
let privacy = user.privacy;
|
||||||
|
|
||||||
|
const privacyNames: { [P in keyof SystemPrivacy]-?: string; } = {
|
||||||
|
description_privacy: "Description",
|
||||||
|
member_list_privacy: "Member list",
|
||||||
|
front_privacy: "Front",
|
||||||
|
front_history_privacy: "Front history",
|
||||||
|
group_list_privacy: "Group list",
|
||||||
|
pronoun_privacy: "Pronouns"
|
||||||
|
};
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
let data = input;
|
|
||||||
err = null;
|
|
||||||
|
|
||||||
loading = true;
|
loading = true;
|
||||||
|
const data: System = {privacy: privacy};
|
||||||
try {
|
try {
|
||||||
let res = await api().systems("@me").patch({data});
|
let res = await api().systems(user.id).patch({data});
|
||||||
user = res;
|
user = res;
|
||||||
currentUser.update(() => res);
|
currentUser.update(() => res);
|
||||||
editMode = false;
|
success = true;
|
||||||
loading = false;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
err = error.message;
|
err = error.message;
|
||||||
err = err;
|
}
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let allPrivacy: string;
|
|
||||||
|
|
||||||
$: { changePrivacy(allPrivacy)}
|
|
||||||
|
|
||||||
function changePrivacy(value: string) {
|
|
||||||
if (value) {
|
|
||||||
input.privacy.description_privacy = value;
|
|
||||||
input.privacy.member_list_privacy = value;
|
|
||||||
input.privacy.group_list_privacy = value;
|
|
||||||
input.privacy.front_privacy = value;
|
|
||||||
input.privacy.front_history_privacy = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if err}
|
|
||||||
|
{#if err}
|
||||||
<Alert color="danger">{err}</Alert>
|
<Alert color="danger">{err}</Alert>
|
||||||
{/if}
|
{/if}
|
||||||
<Label><b>Set all to:</b></Label>
|
{#if success}
|
||||||
<Input type="select" bind:value={allPrivacy} aria-label="set all to">
|
<Alert color="success">System privacy updated!</Alert>
|
||||||
|
{/if}
|
||||||
|
<Label><b>Set all to:</b></Label>
|
||||||
|
<select class="form-control" on:change={(e) => changeAll(e)} aria-label="set all to">
|
||||||
<option>public</option>
|
<option>public</option>
|
||||||
<option>private</option>
|
<option>private</option>
|
||||||
</Input>
|
</select>
|
||||||
<hr />
|
<hr/>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
{#each Object.keys(privacy) as x}
|
||||||
<Label>Description:</Label>
|
<Col xs={12} lg={6} class="mb-3">
|
||||||
<Input type="select" bind:value={input.privacy.description_privacy} aria-label="system description privacy">
|
<Label>{privacyNames[x]}:</Label>
|
||||||
<option default={user.privacy.description_privacy === "public"}>public</option>
|
<Input type="select" bind:value={privacy[x]} aria-label={`group ${privacyNames[x]} privacy`}>
|
||||||
<option default={user.privacy.description_privacy === "private"}>private</option>
|
<option default={privacy[x] === "public"}>public</option>
|
||||||
|
<option default={privacy[x] === "private"}>private</option>
|
||||||
</Input>
|
</Input>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
{/each}
|
||||||
<Label>Member list:</Label>
|
</Row>
|
||||||
<Input type="select" bind:value={input.privacy.member_list_privacy} aria-label="system member list privacy">
|
|
||||||
<option default={user.privacy.member_list_privacy === "public"}>public</option>
|
{#if loading}
|
||||||
<option default={user.privacy.member_list_privacy === "private"}>private</option>
|
<Button style="flex: 0" color="primary" aria-label="submit privacy edit"><Spinner size="sm"/></Button> <Button style="flex: 0" color="secondary" aria-label="cancel privacy edit"><Spinner size="sm"/></Button>
|
||||||
</Input>
|
{:else}
|
||||||
</Col>
|
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
|
||||||
<Label>Group list:</Label>
|
|
||||||
<Input type="select" bind:value={input.privacy.group_list_privacy} aria-label="system group list privacy">
|
|
||||||
<option default={user.privacy.group_list_privacy === "public"}>public</option>
|
|
||||||
<option default={user.privacy.group_list_privacy === "private"}>private</option>
|
|
||||||
</Input>
|
|
||||||
</Col>
|
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
|
||||||
<Label>Current front:</Label>
|
|
||||||
<Input type="select" bind:value={input.privacy.front_privacy} aria-label="system front privacy">
|
|
||||||
<option default={user.privacy.front_privacy === "public"}>public</option>
|
|
||||||
<option default={user.privacy.front_privacy === "private"}>private</option>
|
|
||||||
</Input>
|
|
||||||
</Col>
|
|
||||||
<Col xs={12} lg={4} class="mb-3">
|
|
||||||
<Label>Front history:</Label>
|
|
||||||
<Input type="select" bind:value={input.privacy.front_history_privacy} aria-label="system front history privacy">
|
|
||||||
<option default={user.privacy.front_history_privacy === "public"}>public</option>
|
|
||||||
<option default={user.privacy.front_history_privacy === "private"}>private</option>
|
|
||||||
</Input>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Button style="flex: 0" color="primary" on:click={submit} aria-label="submit privacy edit">Submit</Button> <Button style="flex: 0" color="secondary" on:click={() => editMode = false} aria-label="cancel privacy edit">Back</Button>
|
<Button style="flex: 0" color="primary" on:click={submit} aria-label="submit privacy edit">Submit</Button> <Button style="flex: 0" color="secondary" on:click={() => editMode = false} aria-label="cancel privacy edit">Back</Button>
|
||||||
|
{/if}
|
Loading…
Reference in New Issue
Block a user