import React, { useState, useEffect } from 'react'; import { useSelector } from 'react-redux'; import PageHeader from 'components/layout/PageHeader'; import Button from 'components/common/Button'; import Icon from 'components/common/Icon'; import Table from 'components/common/Table'; import Modal from 'components/common/Modal'; import WebsiteEditForm from 'components/forms/WebsiteEditForm'; import AccountEditForm from 'components/forms/AccountEditForm'; import Pen from 'assets/pen.svg'; import Plus from 'assets/plus.svg'; import Trash from 'assets/trash.svg'; import Check from 'assets/check.svg'; import { get } from 'lib/web'; import styles from './AccountSettings.module.css'; import DeleteForm from './forms/DeleteForm'; export default function AccountSettings() { const user = useSelector(state => state.user); const [data, setData] = useState(); const [addAccount, setAddAccount] = useState(); const [editAccount, setEditAccount] = useState(); const [deleteAccount, setDeleteAccount] = useState(); const [saved, setSaved] = useState(0); const columns = [ { key: 'username', label: 'Username' }, { key: 'is_admin', label: 'Administrator', render: ({ is_admin }) => (is_admin ? } size="medium" /> : null), }, { className: styles.buttons, render: row => row.username !== 'admin' ? ( <> ) : null, }, ]; function handleSave() { setSaved(state => state + 1); handleClose(); } function handleClose() { setEditAccount(null); setAddAccount(null); setDeleteAccount(null); } async function loadData() { setData(await get(`/api/account`)); } useEffect(() => { loadData(); }, [saved]); if (!data) { return null; } return ( <>
Accounts
{editAccount && ( )} {addAccount && ( )} {deleteAccount && ( )} ); }