|
| 1 | +import Button from "@material-ui/core/Button" |
| 2 | +import CircularProgress from "@material-ui/core/CircularProgress" |
| 3 | +import MenuItem from "@material-ui/core/MenuItem" |
| 4 | +import Select from "@material-ui/core/Select" |
1 | 5 | import { makeStyles } from "@material-ui/core/styles"
|
| 6 | +import Table from "@material-ui/core/Table" |
| 7 | +import TableBody from "@material-ui/core/TableBody" |
| 8 | +import TableCell from "@material-ui/core/TableCell" |
| 9 | +import TableContainer from "@material-ui/core/TableContainer" |
| 10 | +import TableHead from "@material-ui/core/TableHead" |
| 11 | +import TableRow from "@material-ui/core/TableRow" |
| 12 | +import TextField from "@material-ui/core/TextField" |
| 13 | +import PersonAdd from "@material-ui/icons/PersonAdd" |
| 14 | +import Autocomplete from "@material-ui/lab/Autocomplete" |
| 15 | +import { TemplateUser } from "api/typesGenerated" |
| 16 | +import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" |
| 17 | +import { EmptyState } from "components/EmptyState/EmptyState" |
2 | 18 | import { ErrorSummary } from "components/ErrorSummary/ErrorSummary"
|
3 | 19 | import { Stack } from "components/Stack/Stack"
|
4 |
| -import { FC } from "react" |
| 20 | +import { TableLoader } from "components/TableLoader/TableLoader" |
| 21 | +import { FC, useState } from "react" |
5 | 22 |
|
6 | 23 | export interface TemplateCollaboratorsPageViewProps {
|
7 | 24 | deleteTemplateError: Error | unknown
|
| 25 | + templateUsers: TemplateUser[] | undefined |
8 | 26 | }
|
9 | 27 |
|
10 | 28 | export const TemplateCollaboratorsPageView: FC<
|
11 | 29 | React.PropsWithChildren<TemplateCollaboratorsPageViewProps>
|
12 |
| -> = ({ deleteTemplateError }) => { |
| 30 | +> = ({ deleteTemplateError, templateUsers }) => { |
| 31 | + const styles = useStyles() |
| 32 | + const [open, setOpen] = useState(false) |
| 33 | + const [options, setOptions] = useState([]) |
| 34 | + const isLoading = false |
13 | 35 | const deleteError = deleteTemplateError ? (
|
14 | 36 | <ErrorSummary error={deleteTemplateError} dismissible />
|
15 | 37 | ) : null
|
16 | 38 |
|
17 | 39 | return (
|
18 | 40 | <Stack spacing={2.5}>
|
19 | 41 | {deleteError}
|
20 |
| - <h2>Collaborators</h2> |
| 42 | + <Stack direction="row" alignItems="center" spacing={1}> |
| 43 | + <Autocomplete |
| 44 | + id="asynchronous-demo" |
| 45 | + style={{ width: 300 }} |
| 46 | + open={open} |
| 47 | + onOpen={() => { |
| 48 | + setOpen(true) |
| 49 | + }} |
| 50 | + onClose={() => { |
| 51 | + setOpen(false) |
| 52 | + }} |
| 53 | + getOptionSelected={(option: any, value: any) => option.name === value.name} |
| 54 | + getOptionLabel={(option) => option.name} |
| 55 | + options={options} |
| 56 | + loading={isLoading} |
| 57 | + className={styles.autocomplete} |
| 58 | + renderInput={(params) => ( |
| 59 | + <TextField |
| 60 | + {...params} |
| 61 | + margin="none" |
| 62 | + variant="outlined" |
| 63 | + placeholder="User email or username" |
| 64 | + InputProps={{ |
| 65 | + ...params.InputProps, |
| 66 | + endAdornment: ( |
| 67 | + <> |
| 68 | + {isLoading ? <CircularProgress size={16} /> : null} |
| 69 | + {params.InputProps.endAdornment} |
| 70 | + </> |
| 71 | + ), |
| 72 | + }} |
| 73 | + /> |
| 74 | + )} |
| 75 | + /> |
| 76 | + |
| 77 | + <Select defaultValue="read" variant="outlined" className={styles.select}> |
| 78 | + <MenuItem key="read" value="read"> |
| 79 | + Read |
| 80 | + </MenuItem> |
| 81 | + <MenuItem key="write" value="write"> |
| 82 | + Write |
| 83 | + </MenuItem> |
| 84 | + <MenuItem key="admin" value="admin"> |
| 85 | + Admin |
| 86 | + </MenuItem> |
| 87 | + </Select> |
| 88 | + |
| 89 | + <Button size="small" startIcon={<PersonAdd />}> |
| 90 | + Add collaborator |
| 91 | + </Button> |
| 92 | + </Stack> |
| 93 | + |
| 94 | + <TableContainer> |
| 95 | + <Table> |
| 96 | + <TableHead> |
| 97 | + <TableRow> |
| 98 | + <TableCell>User</TableCell> |
| 99 | + <TableCell>Role</TableCell> |
| 100 | + </TableRow> |
| 101 | + </TableHead> |
| 102 | + <TableBody> |
| 103 | + <ChooseOne> |
| 104 | + <Cond condition={!templateUsers}> |
| 105 | + <TableLoader /> |
| 106 | + </Cond> |
| 107 | + <Cond condition={Boolean(templateUsers && templateUsers.length === 0)}> |
| 108 | + <TableRow> |
| 109 | + <TableCell colSpan={999}> |
| 110 | + <EmptyState |
| 111 | + message="No collaborators yet" |
| 112 | + description="Add a collaborator using the controls above" |
| 113 | + /> |
| 114 | + </TableCell> |
| 115 | + </TableRow> |
| 116 | + </Cond> |
| 117 | + <Cond condition={Boolean(templateUsers && templateUsers.length > 0)}> |
| 118 | + <TableRow> |
| 119 | + <TableCell>Kyle</TableCell> |
| 120 | + <TableCell>Admin</TableCell> |
| 121 | + </TableRow> |
| 122 | + </Cond> |
| 123 | + </ChooseOne> |
| 124 | + </TableBody> |
| 125 | + </Table> |
| 126 | + </TableContainer> |
21 | 127 | </Stack>
|
22 | 128 | )
|
23 | 129 | }
|
24 | 130 |
|
25 |
| -export const useStyles = makeStyles(() => { |
26 |
| - return {} |
| 131 | +export const useStyles = makeStyles((theme) => { |
| 132 | + return { |
| 133 | + autocomplete: { |
| 134 | + "& .MuiInputBase-root": { |
| 135 | + width: 300, |
| 136 | + // Match button small height |
| 137 | + height: 36, |
| 138 | + }, |
| 139 | + |
| 140 | + "& input": { |
| 141 | + fontSize: 14, |
| 142 | + padding: `${theme.spacing(0, 0.5, 0, 0.5)} !important`, |
| 143 | + }, |
| 144 | + }, |
| 145 | + |
| 146 | + select: { |
| 147 | + // Match button small height |
| 148 | + height: 36, |
| 149 | + fontSize: 14, |
| 150 | + width: 100, |
| 151 | + }, |
| 152 | + } |
27 | 153 | })
|
0 commit comments