diff --git a/src/components/NewUI/GroupSettingsLink.tsx b/src/components/NewUI/GroupSettingsLink.tsx index 2fad6cf..116ccdd 100644 --- a/src/components/NewUI/GroupSettingsLink.tsx +++ b/src/components/NewUI/GroupSettingsLink.tsx @@ -1,7 +1,46 @@ import { useCallback, useState } from 'react'; import { IGroup } from './Group'; +import UILink from './UILink'; +import UIPressable from './UIPressable'; import UISecondaryBox from './UISecondaryBox'; +function GroupSettings({ group }: { group: IGroup }) { + const [deletionSuccessful, setDeletionSuccessful] = + useState(null); + + const deleteGroup = useCallback(() => { + fetch('http://localhost:5000/api/groups/' + group.id, { method: 'delete' }) + .then((res) => res.json()) + .then(({ status }) => { + setDeletionSuccessful(status === 'success'); + }) + .catch(() => { + setDeletionSuccessful(false); + }); + }, [group.id]); + + return ( + +

Settings

+ {deletionSuccessful !== true && ( + Delete Group + )} + {deletionSuccessful !== null && + (deletionSuccessful ? ( + + {group.name} was deleted. +
+ Home +
+ ) : ( + + For some reason, {group.name} was not successfully deleted. + + ))} +
+ ); +} + export default function GroupSettingsLink({ group }: { group: IGroup }) { const [open, setOpen] = useState(false); const toggle = useCallback(() => { @@ -20,11 +59,7 @@ export default function GroupSettingsLink({ group }: { group: IGroup }) { > Settings - {open && ( - -

Settings

-
- )} + {open && } ); } diff --git a/src/components/NewUI/UIPressable.tsx b/src/components/NewUI/UIPressable.tsx new file mode 100644 index 0000000..e57f65e --- /dev/null +++ b/src/components/NewUI/UIPressable.tsx @@ -0,0 +1,27 @@ +import { CSSProperties, ReactNode, useMemo } from 'react'; + +const baseStyle: CSSProperties = { + textDecoration: 'none', + cursor: 'pointer', + userSelect: 'none', +}; + +export default function UIPressable({ + onClick, + style, + children, +}: { + onClick: () => void; + style?: CSSProperties; + children: ReactNode; +}) { + const computedStyle = useMemo(() => { + return !style ? baseStyle : { ...baseStyle, ...style }; + }, [style]); + + return ( +
+ {children} +
+ ); +}