import React from "react"; import styled from "styled-components"; import { IChangeEvent, ISubmitEvent, ErrorSchema } from "react-jsonschema-form"; import { SignupForm } from "@models/Signup"; import Checkboxes from "@components/Widgets/Checkbox/Checkboxes"; import RadioButtonWidget from "@components/Widgets/RadioButton/RadioButtonWidget"; import { TextSection, ChangeLanguageButton } from "@components/index"; import { colors } from "@theme/colors"; import FormWrapper from "@views/common/FormWrapper"; import Loader from "@components/Loader"; import { buildFormSchema, buildUISchema } from "./FormUtils"; import { useTranslation } from "../../i18n"; const customWidgets = { radio: RadioButtonWidget, checkboxes: Checkboxes, }; interface SignUpPageViewProps { signUpForm?: SignupForm; formData: any; onChange: (e: IChangeEvent, es?: ErrorSchema) => unknown; onSubmit: (e: ISubmitEvent) => unknown; } const StyledSection = styled(TextSection)` & > div { & > span { color: ${colors.orange1}; } } & > aside { justify-content: start; li { padding-bottom: 0.3rem; } .reserved { color: ${colors.blue1}; } } ${Loader} { margin: auto; } `; const LngButton = styled(ChangeLanguageButton)` align-self: flex-end; margin-right: 1rem; `; const SignUpPageView: React.FC = ({ signUpForm, formData, onChange, onSubmit, }) => { const { i18n, t } = useTranslation(); const startDate = new Date(signUpForm?.start_time); const endDate = new Date(signUpForm?.end_time); const isFi = i18n.language === "fi"; const { title, startDateStr, endDateStr, } = { title: isFi ? signUpForm?.title_fi : signUpForm?.title_en, startDateStr: startDate.toLocaleString(isFi ? "fi-FI" : "en-GB"), endDateStr: endDate.toLocaleString(isFi ? "fi-FI" : "en-GB"), }; const renderList = () => ( ); let form: JSX.Element; let signups: JSX.Element = null; if (!signUpForm) { // Show loader if in edit mode and form has not yet loaded. // For normal signup page, form is always defined on this level. form = ( ); } else if (startDate > new Date()) { form = ( <>

{t("Ilmoittautuminen ei ole vielä auki!")}

{`${t("Se aukeaa")} ${startDateStr}`}.

); } else if (new Date() > endDate) { form = (

{t("Ilmoittauminen on umpeutunut!")}

); signups = renderList(); } else { form = ( <>

{`${t("Ilmoittauminen sulkeutuu")} ${endDateStr}`}.

); signups = renderList(); } return ( <>

{title}

{form}
{signups}
); }; export default SignUpPageView;