regform.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import React, {useState} from "react";
  2. import axios from "axios";
  3. import {
  4. Button,
  5. Container,
  6. Checkbox,
  7. CssBaseline,
  8. Dialog,
  9. DialogTitle,
  10. DialogContent,
  11. DialogActions,
  12. Grid,
  13. FormControl,
  14. FormControlLabel,
  15. FormGroup,
  16. Paper,
  17. TextField,
  18. Typography,
  19. } from '@material-ui/core';
  20. import {makeStyles} from '@material-ui/core/styles';
  21. const useStyles = makeStyles((theme) => ({
  22. fieldset: {
  23. //border: 'none',
  24. //borderBottom: '1px solid',
  25. },
  26. form: {
  27. width: '100%',
  28. marginTop: theme.spacing(1),
  29. flexGrow: 1,
  30. },
  31. paper: {
  32. padding: theme.spacing(2),
  33. alignItems: 'center',
  34. display: 'flex',
  35. flexDirection: 'column',
  36. }
  37. }));
  38. const RegForm = (props) => {
  39. const classes = useStyles();
  40. return (
  41. <Container component="main" maxWidth="md">
  42. <CssBaseline />
  43. <Paper className={classes.paper}>
  44. <Typography component={"h1"} variant={"h5"}>
  45. Registrer ditt event
  46. </Typography>
  47. <form className={classes.form}>
  48. <FormControl component={"fieldset"} className={classes.fieldset}>
  49. <Grid container spacing={3}>
  50. <Grid item xs={12}>
  51. <TextField
  52. id={"organizer"}
  53. label={"Arrangør"}
  54. name={"organizer"}
  55. variant={"outlined"}
  56. margin={"normal"}
  57. required
  58. fullWidth
  59. autoFocus
  60. />
  61. </Grid>
  62. <Grid item xs={12} sm={4}>
  63. <TextField
  64. id={"contact_name"}
  65. label={"Kontakt person"}
  66. name={"contact_name"}
  67. variant={"outlined"}
  68. margin={"normal"}
  69. required
  70. fullWidth
  71. />
  72. </Grid>
  73. <Grid item xs={12} sm={4}>
  74. <TextField
  75. id={"contact_email"}
  76. label={"Epostadresse"}
  77. name={"contact_email"}
  78. variant={"outlined"}
  79. margin={"normal"}
  80. type={"email"}
  81. required
  82. fullWidth
  83. />
  84. </Grid>
  85. <Grid item xs={12} sm={4}>
  86. <TextField
  87. id={"contact_phone"}
  88. label={"Telefonnummer"}
  89. name={"contact_phone"}
  90. variant={"outlined"}
  91. margin={"normal"}
  92. type={"tel"}
  93. required
  94. fullWidth
  95. />
  96. </Grid>
  97. </Grid>
  98. </FormControl>
  99. <FormControl component={"fieldset"} className={classes.fieldset}>
  100. <legend>Arrangement</legend>
  101. <Grid container spacing={3}>
  102. <Grid item xs={12} sm={8}>
  103. <TextField
  104. id={"event_name"}
  105. label={"Navn på arrangement"}
  106. name={"event_name"}
  107. variant={"outlined"}
  108. margin={"normal"}
  109. required
  110. fullWidth
  111. />
  112. </Grid>
  113. <Grid item xs={12} sm={4}>
  114. <TextField
  115. id={"event_capacity"}
  116. label={"Kapasitet"}
  117. name={"event_capacity"}
  118. variant={"outlined"}
  119. margin={"normal"}
  120. type={"number"}
  121. required
  122. fullWidth
  123. />
  124. </Grid>
  125. <Grid item xs={12} sm={6}>
  126. <Categories cid={"5ed0f77a42f75848a95ebf03"} />
  127. </Grid>
  128. <Grid item xs={12} sm={6}>
  129. </Grid>
  130. </Grid>
  131. </FormControl>
  132. </form>
  133. </Paper>
  134. </Container>
  135. )
  136. }
  137. const Categories = (props) => {
  138. const [error, setError] = useState(null);
  139. const [isLoading, setIsLoading] = useState(true);
  140. const [availableItems, setAvailableItems] = useState([]);
  141. React.useEffect(() => {
  142. axios.get("https://magy.giaever.online/tff/api/webflow_items?cid=" + props.cid)
  143. .then((response) => {
  144. const data = response.data['hydra:member'];
  145. setAvailableItems(data);
  146. })
  147. .catch((error) => {
  148. console.log(error);
  149. setError(error);
  150. })
  151. .then(() => {
  152. console.log("DONE");
  153. setIsLoading(false);
  154. });
  155. }, []);
  156. return (
  157. <DialogCancelOk
  158. buttonDesc={isLoading ? "Laster kategorier" : "Velg kategori"}
  159. buttonDisabled={isLoading}
  160. dialogTitle={"Velg kategori(er)"}
  161. >
  162. {isLoading ?
  163. <p>
  164. Laster...
  165. </p>
  166. :
  167. <FormGroup>
  168. {availableItems.map(item => <FormControlLabel
  169. key={item.id}
  170. control={
  171. <Checkbox checked={false} value={item.id} />
  172. }
  173. label={item.name}
  174. />
  175. )}
  176. </FormGroup>
  177. }
  178. </DialogCancelOk>
  179. )
  180. }
  181. const DialogCancelOk = (props) => {
  182. const [open, setOpen] = useState(false);
  183. const handleClickOpen = () => {
  184. setOpen(true);
  185. };
  186. const handleClickClose = () => {
  187. setOpen(false);
  188. };
  189. return (
  190. <div>
  191. <Button
  192. fullWidth
  193. disabled={props.buttonDisabled}
  194. color={"secondary"}
  195. variant={"outlined"}
  196. onClick={handleClickOpen}>
  197. {props.buttonDesc}
  198. </Button>
  199. <Dialog
  200. disableBackdropClick
  201. disableEscapeKeyDown
  202. open={open}
  203. onClose={handleClickClose}
  204. >
  205. <DialogTitle>{props.dialogTitle}</DialogTitle>
  206. <DialogContent>
  207. {props.children}
  208. </DialogContent>
  209. <DialogActions>
  210. <Button onClick={handleClickClose} color={"primary"}>
  211. Ferdig
  212. </Button>
  213. </DialogActions>
  214. </Dialog>
  215. </div>
  216. )
  217. }
  218. export default RegForm;