Skip to content

Commit

Permalink
Process seminars/add
Browse files Browse the repository at this point in the history
  • Loading branch information
robol committed Oct 27, 2023
1 parent 650b6da commit 9735b1e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 37 deletions.
2 changes: 0 additions & 2 deletions src/components/DatetimeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export function DatetimeInput({ value, setValue }) {
: ''
)

console.log(date, time)

return (
<div className="row d-flex">
<div className="col-sm-8 pe-0">
Expand Down
105 changes: 70 additions & 35 deletions src/processes/AddSeminar.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,115 @@
import { Button, Card, Form } from 'react-bootstrap'
import { ModelInput } from '../components/ModelInput'
import { useState } from 'react'
import EventSeminar from '../models/EventSeminar'
import { useEngine } from '../Engine'

export default function AddSeminar() {
const [speaker, setSpeaker] = useState(null)
const [speakerBlockDisabled, setSpeakerBlockDisabled] = useState(false)
const [seminarDetailsBlockDisabled, setSeminarDetailsBlockDisabled] = useState(true)
const [person, setPerson] = useState(null)
const [title, setTitle] = useState("")
const [date, setDate] = useState(null)
const [duration, setDuration] = useState(60)
const [room, setRoom] = useState(null)
const [category, setCategory] = useState(null)
const [seminarAdded, setSeminarAdded] = useState(false)

const onSpeakerSelected = x => {
setSpeaker(x)
setSpeakerBlockDisabled(true)
setSeminarDetailsBlockDisabled(false)
}
const engine = useEngine()
const putSeminar = engine.usePut('event-seminar')

const speakerBlock = <div className={speakerBlockDisabled ? "d-none" : "d-block"}>
<SelectPersonBlock onCompleted={onSpeakerSelected}></SelectPersonBlock>
</div>;
const onCompleted = async () => {
// Insert the seminar in the database
const s = {
title: title,
startDatetime: date,
duration: duration,
conferenceRoom: room,
speaker: person,
category: category
}

const seminarDetails = <div className={seminarDetailsBlockDisabled ? "d-none" : "d-block"}>
<SeminarDetailsBlock speaker={speaker}></SeminarDetailsBlock>
</div>
console.log(s)

if (await putSeminar(s)) {
setSeminarAdded(true)
}
else {
console.log("error")
}
}

if (seminarAdded) {
return <div>
<p>Seminario inserito correttamente.</p>
<a href="/"><button className="btn btn-primary">Torna alla home</button></a>
</div>
}

return <div>
<h1 className="text-primary pb-4">Nuovo Seminario</h1>
{speakerBlock}
{seminarDetails}
<h1 className="text-primary pb-4">Inserimento nuovo seminario</h1>
<SelectPersonBlock person={person} setPerson={setPerson} disabled={person != null}></SelectPersonBlock>
<SeminarDetailsBlock disabled={person == null}
title={title} setTitle={setTitle}
date={date} setDate={setDate}
duration={duration} setDuration={setDuration}
room={room} setRoom={setRoom}
category={category} setCategory={setCategory}
onCompleted={onCompleted}
></SeminarDetailsBlock>
</div>;
}

function SeminarDetailsBlock({ speaker, onCompleted }) {
const [confirm] = useState(false)
function SeminarDetailsBlock({ speaker, onCompleted, disabled, room, setRoom, date, setDate, title, setTitle, duration, setDuration, category, setCategory }) {
const confirm_enabled = (title != "") && (date != null) && (duration > 0) && (room != null) && (category != null)

if (disabled) {
return <></>
}

return <Card className="shadow">
<Card.Header>Dettagli del seminario [speaker: <strong>{speaker?.firstName} {speaker?.lastName}</strong>]</Card.Header>
<Card.Header>Dettagli del seminario</Card.Header>
<Card.Body>
<Form>
<Form.Group className="my-3">
<ModelInput field="Titolo" schema={{ type: "string" }}></ModelInput>
<ModelInput field="Titolo" schema={{ type: "string" }} value={title} setValue={setTitle}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Categoria" schema={{ "x-ref": "SeminarCategory" }} value={category} setValue={setCategory}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Data e ora" schema={{ format: "date-time", widget: "datetime" }}></ModelInput>
<ModelInput field="Data e ora" schema={{ format: "date-time", widget: "datetime" }} value={date} setValue={setDate}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Durata (in minuti)" schema={{ type: "number" }}></ModelInput>
<ModelInput field="Durata (in minuti)" schema={{ type: "number" }} value={duration} setValue={setDuration}></ModelInput>
</Form.Group>
<Form.Group className="my-3">
<ModelInput field="Aula" schema={{ "x-ref": "ConferenceRoom" }}></ModelInput>
<ModelInput field="Aula" schema={{ "x-ref": "ConferenceRoom" }} value={room} setValue={setRoom}></ModelInput>
</Form.Group>
</Form>
<div className="d-flex flex-row justify-content-end">
<Button className="text-end" onClick={() => onCompleted()} disabled={! confirm}>Conferma</Button>
<Button className="text-end" onClick={onCompleted} disabled={! confirm_enabled}>Conferma</Button>
</div>
</Card.Body>
</Card>;
}

function SelectPersonBlock({ onCompleted }) {
const [person, setPerson] = useState(null)
const [confirm, setConfirm] = useState(person !== null)

const onSpeakerSelected = x => {
setPerson(x)
setConfirm(x !== null)
function SelectPersonBlock({ onCompleted, disabled, person, setPerson }) {
if (disabled) {
return <Card className="shadow mb-3">
<Card.Header>Selezione speaker: <strong>{person?.firstName} {person?.lastName}</strong></Card.Header>
</Card>
}

return <div>
<Card className="shadow">
<Card className="shadow mb-3">
<Card.Header>Selezione speaker</Card.Header>
<Card.Body>
<Form>
<Form.Group>
<ModelInput field="Speaker" schema={{'x-ref': 'Person'}} value={person} setValue={onSpeakerSelected}></ModelInput>
<ModelInput field="Speaker" schema={{'x-ref': 'Person'}} value={person} setValue={setPerson}></ModelInput>
</Form.Group>
</Form>
<div className="d-flex flex-row justify-content-end">
<Button className="text-end" onClick={() => onCompleted(person)} disabled={! confirm}>Conferma</Button>
<Button className="text-end" onClick={() => onCompleted(person)} disabled={person != null}>Conferma</Button>
</div>
</Card.Body>
</Card>
Expand Down

0 comments on commit 9735b1e

Please sign in to comment.