mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-03 22:47:59 +00:00
2fa397548a
* feat/navigate upgrade react router * feat/navigate migrate to react router 6 * feat/navigate style modal * feat/navigate create endpoints for app settings * feat/navigate protect editor with pin * feat/navigate apply dynamic routing draft * feat/navigate upgrade relevant packages * feat/navigate restructure directory and add tests * feat/navigate test aliases validation * feat/navigate validate aliases before sending * feat/navigate create data endpoint * feat/navigate config: prettier * feat/navigate invalidate empty strings * feat/navigate create endpoints * feat/navigate parse on import * feat/navigate navigate to alias * feat/navigate user help and sample data * feat/navigate refact aliases modal * feat/navigate refact settings style * feat/navigate update sample db * feat/navigate link is relative to hostname * feat/navigate navigate to first match * feat/navigate update readme and version bump * feat/navigate config: create shared module * feat/navigate config: cheat module install * feat/navigate fix tests * feat/navigate run tests in pull request * Update ontime_cy.yml
172 lines
5.2 KiB
React
172 lines
5.2 KiB
React
import { ModalBody } from '@chakra-ui/modal';
|
|
import { FormLabel, Input, Textarea } from '@chakra-ui/react';
|
|
import { fetchEvent, postEvent } from 'app/api/eventApi';
|
|
import { useEffect, useState } from 'react';
|
|
import { useFetch } from 'app/hooks/useFetch';
|
|
import { EVENT_TABLE } from 'app/api/apiConstants';
|
|
import style from './Modals.module.scss';
|
|
import { eventPlaceholderSettings } from '../../app/api/ontimeApi';
|
|
import SubmitContainer from './SubmitContainer';
|
|
import { inputProps } from './modalHelper';
|
|
|
|
export default function SettingsModal() {
|
|
const { data, status, refetch } = useFetch(EVENT_TABLE, fetchEvent);
|
|
const [formData, setFormData] = useState(eventPlaceholderSettings);
|
|
const [changed, setChanged] = useState(false);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
|
|
/**
|
|
* Set formdata from server state
|
|
*/
|
|
useEffect(() => {
|
|
if (data == null) return;
|
|
if (changed) return;
|
|
|
|
setFormData({
|
|
title: data.title,
|
|
url: data.url,
|
|
publicInfo: data.publicInfo,
|
|
backstageInfo: data.backstageInfo,
|
|
endMessage: data.endMessage,
|
|
});
|
|
}, [changed, data]);
|
|
|
|
/**
|
|
* Validate and submit data
|
|
*/
|
|
const submitHandler = async (event) => {
|
|
event.preventDefault();
|
|
setSubmitting(true);
|
|
|
|
await postEvent(formData);
|
|
|
|
setChanged(false);
|
|
setSubmitting(false);
|
|
};
|
|
|
|
/**
|
|
* Reverts local state equals to server state
|
|
*/
|
|
const revert = async () => {
|
|
setChanged(false);
|
|
await refetch();
|
|
};
|
|
|
|
/**
|
|
* Handles change of input field in local state
|
|
* @param {string} field - object parameter to update
|
|
* @param {string} value - new object parameter value
|
|
*/
|
|
const handleChange = (field, value) => {
|
|
const temp = { ...formData };
|
|
temp[field] = value;
|
|
setFormData(temp);
|
|
setChanged(true);
|
|
};
|
|
|
|
return (
|
|
<ModalBody className={style.modalBody}>
|
|
<p className={style.notes}>
|
|
Options related to the running event
|
|
<br />
|
|
Affects rendered views
|
|
</p>
|
|
<form onSubmit={submitHandler}>
|
|
<div className={style.modalFields}>
|
|
<div className={style.hSeparator}>Event Data</div>
|
|
<div className={style.spacedEntry}>
|
|
<FormLabel htmlFor='title'>Event Title</FormLabel>
|
|
<Input
|
|
{...inputProps}
|
|
maxLength={35}
|
|
name='title'
|
|
placeholder='Event Title'
|
|
value={formData.title}
|
|
onChange={(event) => handleChange('title', event.target.value)}
|
|
/>
|
|
</div>
|
|
<div className={style.hSeparator}>Additional Screen Info</div>
|
|
<div className={style.spacedEntry}>
|
|
<FormLabel htmlFor='url'>
|
|
Event URL
|
|
<span className={style.labelNote}>
|
|
<br />
|
|
Shown as a QR code in some views
|
|
</span>
|
|
</FormLabel>
|
|
<Input
|
|
{...inputProps}
|
|
name='url'
|
|
placeholder='www.onsite.no'
|
|
value={formData.url}
|
|
onChange={(event) => handleChange('url', event.target.value)}
|
|
/>
|
|
</div>
|
|
<div className={style.spacedEntry}>
|
|
<FormLabel htmlFor='pubInfo'>
|
|
Public Info
|
|
<span className={style.labelNote}>
|
|
<br />
|
|
Information to be shown on public screens
|
|
</span>
|
|
</FormLabel>
|
|
<Textarea
|
|
{...inputProps}
|
|
name='pubInfo'
|
|
placeholder='Information to be shown on public screens'
|
|
value={formData.publicInfo}
|
|
onChange={(event) =>
|
|
handleChange('publicInfo', event.target.value)
|
|
}
|
|
/>
|
|
</div>
|
|
<div className={style.spacedEntry}>
|
|
<FormLabel htmlFor='backstageInfo'>
|
|
Backstage Info
|
|
<span className={style.labelNote}>
|
|
<br />
|
|
Information to be shown on backstage screens
|
|
</span>
|
|
</FormLabel>
|
|
<Textarea
|
|
{...inputProps}
|
|
name='backstageInfo'
|
|
placeholder='Information to be shown on backstage screens'
|
|
resize={false}
|
|
value={formData.backstageInfo}
|
|
onChange={(event) =>
|
|
handleChange('backstageInfo', event.target.value)
|
|
}
|
|
/>
|
|
</div>
|
|
<div className={style.spacedEntry}>
|
|
<FormLabel htmlFor='endMessage'>
|
|
End Message
|
|
<span className={style.labelNote}>
|
|
<br />
|
|
Shown on presenter view when time is finished
|
|
</span>
|
|
</FormLabel>
|
|
<Input
|
|
{...inputProps}
|
|
maxLength={30}
|
|
name='endMessage'
|
|
placeholder='Empty message shows elapsed time'
|
|
value={formData.endMessage}
|
|
onChange={(event) =>
|
|
handleChange('endMessage', event.target.value)
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<SubmitContainer
|
|
revert={revert}
|
|
submitting={submitting}
|
|
changed={changed}
|
|
status={status}
|
|
/>
|
|
</form>
|
|
</ModalBody>
|
|
);
|
|
}
|