Fix RolesContainer, refactor NestsContainer
This commit is contained in:
parent
ce40194147
commit
b1d30c1bde
8 changed files with 74 additions and 107 deletions
|
@ -1,5 +1,5 @@
|
|||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import getNests, { Context as NestsContext } from '@/api/swr/getNests';
|
||||
import getNests, { Context as NestsContext } from '@/api/admin/nests/getNests';
|
||||
import NewNestButton from '@/components/admin/nests/NewNestButton';
|
||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||
import useFlash from '@/plugins/useFlash';
|
||||
|
@ -39,11 +39,11 @@ const NestsContainer = () => {
|
|||
|
||||
useEffect(() => {
|
||||
if (!error) {
|
||||
clearFlashes('backups');
|
||||
clearFlashes('nests');
|
||||
return;
|
||||
}
|
||||
|
||||
clearAndAddHttpError({ error, key: 'backups' });
|
||||
clearAndAddHttpError({ error, key: 'nests' });
|
||||
}, [ error ]);
|
||||
|
||||
const length = nests?.items?.length || 0;
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
import React, { useState } from 'react';
|
||||
import createNest from '@/api/admin/nests/createNest';
|
||||
import { httpErrorToHuman } from '@/api/http';
|
||||
import { AdminContext } from '@/state/admin';
|
||||
import getNests from '@/api/admin/nests/getNests';
|
||||
import Button from '@/components/elements/Button';
|
||||
import Field from '@/components/elements/Field';
|
||||
import Modal from '@/components/elements/Modal';
|
||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||
import useFlash from '@/plugins/useFlash';
|
||||
import { Form, Formik, FormikHelpers } from 'formik';
|
||||
import tw from 'twin.macro';
|
||||
import { object, string } from 'yup';
|
||||
import tw from 'twin.macro';
|
||||
|
||||
interface Values {
|
||||
name: string,
|
||||
|
@ -26,9 +25,8 @@ const schema = object().shape({
|
|||
|
||||
export default () => {
|
||||
const [ visible, setVisible ] = useState(false);
|
||||
const { addError, clearFlashes } = useFlash();
|
||||
|
||||
const appendNest = AdminContext.useStoreActions(actions => actions.nests.appendNest);
|
||||
const { clearFlashes, clearAndAddHttpError } = useFlash();
|
||||
const { mutate } = getNests();
|
||||
|
||||
const submit = ({ name, description }: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
||||
clearFlashes('nest:create');
|
||||
|
@ -36,11 +34,11 @@ export default () => {
|
|||
|
||||
createNest(name, description)
|
||||
.then(nest => {
|
||||
appendNest(nest);
|
||||
mutate(data => ({ ...data, items: data.items.concat(nest) }), false);
|
||||
setVisible(false);
|
||||
})
|
||||
.catch(error => {
|
||||
addError({ key: 'nest:create', message: httpErrorToHuman(error) });
|
||||
clearAndAddHttpError({ key: 'nest:create', error });
|
||||
setSubmitting(false);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useDeepMemoize } from '@/plugins/useDeepMemoize';
|
||||
import { AdminContext } from '@/state/admin';
|
||||
import { httpErrorToHuman } from '@/api/http';
|
||||
|
@ -10,7 +10,7 @@ import tw from 'twin.macro';
|
|||
import AdminContentBlock from '@/components/admin/AdminContentBlock';
|
||||
import getRoles from '@/api/admin/roles/getRoles';
|
||||
import AdminCheckbox from '@/components/admin/AdminCheckbox';
|
||||
import AdminTable, { TableBody, TableHead, TableHeader, TableRow } from '@/components/admin/AdminTable';
|
||||
import AdminTable, { ContentWrapper, Loading, NoItems, TableBody, TableHead, TableHeader, TableRow } from '@/components/admin/AdminTable';
|
||||
|
||||
const RowCheckbox = ({ id }: { id: number}) => {
|
||||
const isChecked = AdminContext.useStoreState(state => state.roles.selectedRoles.indexOf(id) >= 0);
|
||||
|
@ -74,47 +74,49 @@ export default () => {
|
|||
|
||||
<FlashMessageRender byKey={'roles'} css={tw`mb-4`}/>
|
||||
|
||||
<AdminTable
|
||||
loading={loading}
|
||||
hasItems={roles.length > 0}
|
||||
checked={selectedRolesLength === (roles.length === 0 ? -1 : roles.length)}
|
||||
onSelectAllClick={onSelectAllClick}
|
||||
>
|
||||
<TableHead>
|
||||
<TableHeader name={'ID'}/>
|
||||
<TableHeader name={'Name'}/>
|
||||
<TableHeader name={'Description'}/>
|
||||
</TableHead>
|
||||
<AdminTable>
|
||||
{ loading ?
|
||||
<Loading/>
|
||||
:
|
||||
roles.length < 1 ?
|
||||
<NoItems/>
|
||||
:
|
||||
<ContentWrapper
|
||||
checked={selectedRolesLength === (roles.length === 0 ? -1 : roles.length)}
|
||||
onSelectAllClick={onSelectAllClick}
|
||||
>
|
||||
<div css={tw`overflow-x-auto`}>
|
||||
<table css={tw`w-full table-auto`}>
|
||||
<TableHead>
|
||||
<TableHeader name={'ID'}/>
|
||||
<TableHeader name={'Name'}/>
|
||||
<TableHeader name={'Description'}/>
|
||||
</TableHead>
|
||||
|
||||
<TableBody>
|
||||
{
|
||||
roles.map(role => (
|
||||
<TableRow key={role.id}>
|
||||
<td css={tw`pl-6`}>
|
||||
<RowCheckbox id={role.id}/>
|
||||
</td>
|
||||
<TableBody>
|
||||
{
|
||||
roles.map(role => (
|
||||
<TableRow key={role.id}>
|
||||
<td css={tw`pl-6`}>
|
||||
<RowCheckbox id={role.id}/>
|
||||
</td>
|
||||
|
||||
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap`}>{role.id}</td>
|
||||
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap`}>
|
||||
<NavLink to={`${match.url}/${role.id}`}>
|
||||
{role.name}
|
||||
</NavLink>
|
||||
</td>
|
||||
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap`}>{role.description}</td>
|
||||
</TableRow>
|
||||
))
|
||||
}
|
||||
</TableBody>
|
||||
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap`}>{role.id}</td>
|
||||
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap`}>
|
||||
<NavLink to={`${match.url}/${role.id}`}>
|
||||
{role.name}
|
||||
</NavLink>
|
||||
</td>
|
||||
<td css={tw`px-6 text-sm text-neutral-200 text-left whitespace-nowrap`}>{role.description}</td>
|
||||
</TableRow>
|
||||
))
|
||||
}
|
||||
</TableBody>
|
||||
</table>
|
||||
</div>
|
||||
</ContentWrapper>
|
||||
}
|
||||
</AdminTable>
|
||||
</AdminContentBlock>
|
||||
);
|
||||
}; */
|
||||
|
||||
import React from 'react';
|
||||
|
||||
export default () => {
|
||||
return (
|
||||
<>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue