regform.js 7.3 KB

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