groups: set color in settings

This commit is contained in:
Liam Fitzgerald 2020-10-06 13:21:59 +10:00
parent 5e7f4db67d
commit 897905d638
7 changed files with 44 additions and 15 deletions

View File

@ -26,7 +26,7 @@ export default class GroupsApi extends BaseApi<StoreState> {
return this.proxyAction({ addMembers: { resource, ships } }); return this.proxyAction({ addMembers: { resource, ships } });
} }
changePolicy(resource: Resource, diff: GroupPolicyDiff) { changePolicy(resource: Resource, diff: Enc<GroupPolicyDiff>) {
return this.proxyAction({ changePolicy: { resource, diff } }); return this.proxyAction({ changePolicy: { resource, diff } });
} }

View File

@ -1,7 +1,7 @@
import BaseApi from './base'; import BaseApi from './base';
import { StoreState } from '../store/type'; import { StoreState } from '../store/type';
import { Path, Patp } from '~/types/noun'; import { Path, Patp, Association, Metadata } from '~/types';
export default class MetadataApi extends BaseApi<StoreState> { export default class MetadataApi extends BaseApi<StoreState> {
@ -27,6 +27,20 @@ export default class MetadataApi extends BaseApi<StoreState> {
}); });
} }
update(association: Association, newMetadata: Partial<Metadata>) {
const metadata = {...association.metadata, ...newMetadata };
return this.metadataAction({
add: {
'group-path': association['group-path'],
resource: {
'app-path': association['app-path'],
'app-name': association['app-name'],
},
metadata
}
});
}
private metadataAction(data) { private metadataAction(data) {
return this.action('metadata-hook', 'metadata-action', data); return this.action('metadata-hook', 'metadata-action', data);
} }

View File

@ -6,7 +6,11 @@ export function useOutsideClick(
) { ) {
useEffect(() => { useEffect(() => {
function handleClick(event: MouseEvent) { function handleClick(event: MouseEvent) {
if (ref.current && !ref.current.contains(event.target as any)) { if (
ref.current &&
!ref.current.contains(event.target as any) &&
!document.querySelector("#portal-root")!.contains(event.target as any)
) {
onClick(); onClick();
} }
} }

View File

@ -45,7 +45,7 @@ export type Association = Resource & {
metadata: Metadata; metadata: Metadata;
}; };
interface Metadata { export interface Metadata {
color: string; color: string;
creator: Patp; creator: Patp;
'date-created': string; 'date-created': string;

View File

@ -17,16 +17,19 @@ import { Association } from "~/types/metadata-update";
import GlobalApi from "~/logic/api/global"; import GlobalApi from "~/logic/api/global";
import { resourceFromPath, roleForShip } from "~/logic/lib/group"; import { resourceFromPath, roleForShip } from "~/logic/lib/group";
import { StatelessAsyncButton } from "~/views/components/StatelessAsyncButton"; import { StatelessAsyncButton } from "~/views/components/StatelessAsyncButton";
import { ColorInput } from "~/views/components/ColorInput";
interface FormSchema { interface FormSchema {
name: string; title: string;
description?: string; description: string;
color: string;
isPrivate: boolean; isPrivate: boolean;
} }
const formSchema = Yup.object({ const formSchema = Yup.object({
name: Yup.string().required("Group must have a name"), title: Yup.string().required("Group must have a name"),
description: Yup.string(), description: Yup.string(),
color: Yup.string(),
isPrivate: Yup.boolean(), isPrivate: Yup.boolean(),
}); });
@ -40,8 +43,9 @@ export function GroupSettings(props: GroupSettingsProps) {
const { metadata } = association; const { metadata } = association;
const currentPrivate = "invite" in props.group.policy; const currentPrivate = "invite" in props.group.policy;
const initialValues: FormSchema = { const initialValues: FormSchema = {
name: metadata.title, title: metadata.title,
description: metadata.description, description: metadata.description,
color: metadata.color,
isPrivate: currentPrivate, isPrivate: currentPrivate,
}; };
@ -50,8 +54,8 @@ export function GroupSettings(props: GroupSettingsProps) {
actions: FormikHelpers<FormSchema> actions: FormikHelpers<FormSchema>
) => { ) => {
try { try {
const { name, description, isPrivate } = values; const { title, description, color, isPrivate } = values;
await props.api.metadata.editGroup(props.association, name, description); await props.api.metadata.update(props.association, { title, description, color });
if (isPrivate !== currentPrivate) { if (isPrivate !== currentPrivate) {
const resource = resourceFromPath(props.association["group-path"]); const resource = resourceFromPath(props.association["group-path"]);
const newPolicy: Enc<GroupPolicy> = isPrivate const newPolicy: Enc<GroupPolicy> = isPrivate
@ -108,7 +112,7 @@ export function GroupSettings(props: GroupSettingsProps) {
</> </>
)} )}
<Input <Input
id="name" id="title"
label="Group Name" label="Group Name"
caption="The name for your group to be called by" caption="The name for your group to be called by"
disabled={disabled} disabled={disabled}
@ -119,6 +123,12 @@ export function GroupSettings(props: GroupSettingsProps) {
caption="The description of your group" caption="The description of your group"
disabled={disabled} disabled={disabled}
/> />
<ColorInput
id="color"
label="Group color"
caption="A color to represent your group"
disabled={disabled}
/>
<Checkbox <Checkbox
id="isPrivate" id="isPrivate"
label="Private group" label="Private group"

View File

@ -152,12 +152,12 @@ export function GroupSwitcher(props: {
</Col> </Col>
} }
> >
<Box p={2} alignItems="center" display="flex"> <Row p={2} alignItems="center">
<Box mr={1} flex='1'> <Row alignItems="center" mr={1} flex='1'>
<Text overflow='hidden' display='inline-block' maxWidth='144px' style={{ textOverflow: 'ellipsis', whiteSpace: 'pre'}}>{title}</Text> <Text overflow='hidden' display='inline-block' maxWidth='144px' style={{ textOverflow: 'ellipsis', whiteSpace: 'pre'}}>{title}</Text>
</Box> </Row>
<Icon mt="0px" display="block" icon="ChevronSouth" /> <Icon mt="0px" display="block" icon="ChevronSouth" />
</Box> </Row>
</Dropdown> </Dropdown>
<Row collapse pr={1} justifyContent="flex-end" alignItems="center"> <Row collapse pr={1} justifyContent="flex-end" alignItems="center">
{workspace.type === "group" && ( {workspace.type === "group" && (

View File

@ -130,6 +130,7 @@ export function PopoverRoutes(
group={props.group} group={props.group}
contacts={props.contacts} contacts={props.contacts}
association={props.association} association={props.association}
api={props.api}
/> />
)} )}
{view === "profile" && ( {view === "profile" && (