import React, {useState} from "react"; import axios from "axios"; import DateFnsUtils from '@date-io/date-fns'; import {nb} from 'date-fns/locale' import {DateTimePicker, MuiPickersUtilsProvider} from '@material-ui/pickers'; import {makeStyles} from '@material-ui/core/styles'; import ReCAPTCHA from "react-google-recaptcha"; import { Button, ButtonGroup, Container, Checkbox, CssBaseline, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, FormControl, FormControlLabel, FormGroup, Grid, IconButton, Paper, TextField, Typography, } from '@material-ui/core'; import { Alert, AlertTitle } from '@material-ui/lab'; import { Add, Remove, } from '@material-ui/icons' const useStyles = makeStyles((theme) => ({ fieldset: { //border: 'none', marginBottom: theme.spacing(3), paddingBottom: theme.spacing(3), }, form: { width: '100%', marginTop: theme.spacing(1), flexGrow: 1, }, paper: { padding: theme.spacing(2), alignItems: 'center', display: 'flex', flexDirection: 'column', } })); const ReCaptchaSubmitButton = (props) => { const recaptchaRef = React.createRef(); const [response, setResponse] = useState(null); const onChange = (value) => { if (value) { const request = { organizer: props.inputs.organizer || null, organizationNumber: props.inputs.organization_number || null, contactPerson: props.inputs.contact_name || null, contactEmail: props.inputs.contact_email || null, contactPhone: props.inputs.contact_phone || null, websiteUrl: props.inputs.contact_homepage || null, place: props.inputs.event_location || null, capacity: props.inputs.event_capacity || null, happensOn: props.inputs.dates || [], title: props.inputs.event_name || null, image: props.inputs.event_photo || null, description: props.inputs.event_description || null, bookingUrl: props.inputs.event_booking || null, audiences: (props.inputs.audiences || []).map(i => i.id), categories: (props.inputs.categories || []).map(i => i.id), captcha: value, }; axios.post("https://magy.giaever.online/tff/api/webflow_collection_events", request).then(resp => { setResponse({type: 'success', title: "Takk for ditt bidrag!", description: "Vi ser frem til din deltagelse."}); props.clearHandler(); }).catch(err => { if (err.response) { setResponse({type: 'error', title: err.response.data['hydra:title'], description: err.response.data['hydra:description']}); } else if (err.request) setResponse({type: 'error', title: "En feil oppstod.", description: "Vennligst prøv igjen senere."}); else setResponse({type: 'error', title: "En feil oppstod,", description: err.message}); }); } } return (
{ setResponse(null); recaptchaRef.current.reset(); }}> {response ? response.title : "unknown title"} {response ? ( response.type == "error" ?
    {response.description.split("\n").map((l, i) =>
  • {l}
  • )}
: response.description ) : "this is the body"}
); } const RegForm = (props) => { const classes = useStyles(); const [inputs, updateInputs] = useState({ dates: [{date: new Date(), duration: 0.5}], }); const inputHandler = (event) => { const target = event.target updateInputs((prevState) => ({...prevState, [target.id]: target.value})); }; const inputCategoryHandler = (type, event, category) => { const keys = Object.keys(inputs).filter(idx => idx == type); let arr = keys.length == 0 ? [] : inputs[keys[0]]; if (event.target.checked) arr.push(category); else arr = arr.filter(item => item.id != category.id); updateInputs((prevState) => ({...prevState, [type]: arr})); } const dateAddHandler = (idx) => { inputs.dates.splice(idx, 0, {...inputs.dates[idx]}); updateInputs((prevState) => ({...prevState, dates: inputs.dates})); } const dateRemoveHandler = (idx) => { if (inputs.dates.length == 1) return; if (!inputs.dates[idx]) return; updateInputs(prevState => ({...prevState, dates: [...inputs.dates.slice(0, idx), ...inputs.dates.slice(idx+1)]})); } const dateSaveHandler = (idx, e) => { if (!inputs.dates[idx]) return; inputs.dates[idx].date = e; updateInputs((prevState) => ({...prevState, dates: inputs.dates})); } const dateDurationSaveHandler = (idx, e) => { if (!inputs.dates[idx]) return; const target = e.target; inputs.dates[idx].duration = (target.value >= 0 ? target.value * 1.0 : 0.5).toFixed(2); updateInputs((prevState) => ({...prevState, dates: inputs.dates})); } let formRef = React.createRef(); const clearInputs = () => { formRef.current.reset(); updateInputs((prevState) => ({ dates: [{date: new Date(), duration: 0.5}] })); } return (
Om arrangøren Om arrangementet {inputs.dates.map((date, idx) => ( dateSaveHandler(idx, e)} margin={"normal"} /> dateDurationSaveHandler(idx, e)} inputProps={{step: 0.25}} type={"number"} placeholder={"antall timer"} value={date.duration ? date.duration : 0.5} fullWidth /> dateAddHandler(idx)}> dateRemoveHandler(idx)}> ))}
) } const CategorySelection = (props) => { const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(true); const [availableItems, setAvailableItems] = useState([]); React.useEffect(() => { axios.get("https://magy.giaever.online" + props.cid) .then((response) => { const data = response.data['hydra:member']; setAvailableItems(response.data['hydra:member']); }) .catch((error) => { setError(error); }) .then(() => { setIsLoading(false); }); }, []); return ( {isLoading ?

Laster...

: {availableItems.map(item => sitem.id == item.id).length > 0} value={item.id} onChange={() => props.inputCategoryHandler(props.name, event, item)} /> } label={item.name} /> )} }
) } const DialogCancelOk = (props) => { const [open, setOpen] = useState(false); const handleClickOpen = () => { setOpen(true); }; const handleClickClose = () => { setOpen(false); }; return (
{props.dialogTitle} {props.children}
) } export default RegForm;