Move packages/apps back
This commit is contained in:
parent
6eaaf8e9be
commit
5535d6b575
348 changed files with 0 additions and 0 deletions
27
apps/metamigo-frontend/components/users/UserCreate.tsx
Normal file
27
apps/metamigo-frontend/components/users/UserCreate.tsx
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { FC } from "react";
|
||||
import {
|
||||
SimpleForm,
|
||||
TextInput,
|
||||
BooleanInput,
|
||||
Create,
|
||||
CreateProps,
|
||||
} from "react-admin";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { UserRoleInput } from "./shared";
|
||||
|
||||
const UserCreate: FC<CreateProps> = (props) => {
|
||||
const { data: session } = useSession();
|
||||
return (
|
||||
<Create {...props} title="Create Users">
|
||||
<SimpleForm>
|
||||
<TextInput source="email" />
|
||||
<TextInput source="name" />
|
||||
<UserRoleInput session={session} initialValue="NONE" />
|
||||
<BooleanInput source="isActive" defaultValue={true} />
|
||||
<TextInput source="createdBy" defaultValue={session.user.name} />
|
||||
</SimpleForm>
|
||||
</Create>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserCreate;
|
||||
64
apps/metamigo-frontend/components/users/UserEdit.tsx
Normal file
64
apps/metamigo-frontend/components/users/UserEdit.tsx
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import {
|
||||
SimpleForm,
|
||||
TextInput,
|
||||
BooleanInput,
|
||||
DateInput,
|
||||
Edit,
|
||||
Toolbar,
|
||||
SaveButton,
|
||||
DeleteButton,
|
||||
EditProps,
|
||||
useRedirect,
|
||||
} from "react-admin";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { UserRoleInput } from "./shared";
|
||||
|
||||
const useStyles = makeStyles((_theme) => ({
|
||||
defaultToolbar: {
|
||||
flex: 1,
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
},
|
||||
}));
|
||||
|
||||
const UserEditToolbar = (props) => {
|
||||
const classes = useStyles(props);
|
||||
const redirect = useRedirect();
|
||||
|
||||
return (
|
||||
<Toolbar className={classes.defaultToolbar} {...props}>
|
||||
<SaveButton
|
||||
label="save"
|
||||
mutationOptions={{ onSuccess: (response) => redirect("/users") }}
|
||||
/>
|
||||
<DeleteButton disabled={props.session.user.id === props.record.id} />
|
||||
</Toolbar>
|
||||
);
|
||||
};
|
||||
|
||||
const UserTitle = ({ record }: { record?: any }) => {
|
||||
let title = "";
|
||||
if (record) title = record.name ? record.name : record.email;
|
||||
return <span>User {title}</span>;
|
||||
};
|
||||
|
||||
const UserEdit = (props: EditProps) => {
|
||||
const { data: session } = useSession();
|
||||
|
||||
return (
|
||||
<Edit title={<UserTitle />} {...props}>
|
||||
<SimpleForm toolbar={<UserEditToolbar session={session} />}>
|
||||
<TextInput disabled source="id" />
|
||||
<TextInput source="email" />
|
||||
<TextInput source="name" />
|
||||
<UserRoleInput session={session} />
|
||||
<DateInput source="emailVerified" />
|
||||
<BooleanInput source="isActive" />
|
||||
<TextInput source="createdBy" />
|
||||
</SimpleForm>
|
||||
</Edit>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserEdit;
|
||||
28
apps/metamigo-frontend/components/users/UserList.tsx
Normal file
28
apps/metamigo-frontend/components/users/UserList.tsx
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import {
|
||||
List,
|
||||
Datagrid,
|
||||
ImageField,
|
||||
DateField,
|
||||
TextField,
|
||||
EmailField,
|
||||
BooleanField,
|
||||
ListProps,
|
||||
} from "react-admin";
|
||||
|
||||
const UserList = (props: ListProps) => (
|
||||
<List {...props} exporter={false}>
|
||||
<Datagrid rowClick="edit">
|
||||
<EmailField source="email" />
|
||||
<DateField source="emailVerified" />
|
||||
<TextField source="name" />
|
||||
<ImageField source="avatar" />
|
||||
<TextField source="userRole" />
|
||||
<BooleanField source="isActive" />
|
||||
<DateField source="createdAt" />
|
||||
<DateField source="updatedAt" />
|
||||
<TextField source="createdBy" />
|
||||
</Datagrid>
|
||||
</List>
|
||||
);
|
||||
|
||||
export default UserList;
|
||||
12
apps/metamigo-frontend/components/users/index.ts
Normal file
12
apps/metamigo-frontend/components/users/index.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import UserIcon from "@material-ui/icons/People";
|
||||
import UserList from "./UserList";
|
||||
import UserEdit from "./UserEdit";
|
||||
import UserCreate from "./UserCreate";
|
||||
|
||||
// eslint-disable-next-line import/no-anonymous-default-export
|
||||
export default {
|
||||
list: UserList,
|
||||
create: UserCreate,
|
||||
edit: UserEdit,
|
||||
icon: UserIcon,
|
||||
};
|
||||
14
apps/metamigo-frontend/components/users/shared.tsx
Normal file
14
apps/metamigo-frontend/components/users/shared.tsx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { SelectInput } from "react-admin";
|
||||
|
||||
export const UserRoleInput = (props) => (
|
||||
<SelectInput
|
||||
source="userRole"
|
||||
choices={[
|
||||
{ id: "NONE", name: "None" },
|
||||
{ id: "USER", name: "User" },
|
||||
{ id: "ADMIN", name: "Admin" },
|
||||
]}
|
||||
disabled={props.session.user.id === props.record.id}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue