import React, { HTMLProps, useEffect, useMemo, useState } from "react"; import { Button, FormControl, FormHelperText, Grid, Input, InputLabel, TextField, Typography } from "@material-ui/core"; import { KeyboardDatePicker as DatePicker } from "@material-ui/pickers"; import { CompanyForm } from "@/forms/company"; import { StudentForm } from "@/forms/student"; import { sampleStudent } from "@/provider/dummy/student"; import { Course, Internship, InternshipType, internshipTypeLabels } from "@/data"; import { Nullable } from "@/helpers"; import moment, { Moment } from "moment"; import { computeWorkingHours } from "@/utils/date"; import { Autocomplete } from "@material-ui/lab"; import { formFieldProps } from "@/forms/helpers"; import { emptyInternship } from "@/provider/dummy/internship"; import { InternshipProposalActions, useDispatch } from "@/state/actions"; import { useTranslation } from "react-i18next"; import { useSelector } from "react-redux"; import { AppState } from "@/state/reducer"; import { useHistory } from "react-router-dom"; import { route } from "@/routing"; import { useProxyState } from "@/hooks"; import { getInternshipProposal } from "@/state/reducer/proposal"; export type InternshipFormProps = {} export type InternshipFormSectionProps = { internship: Nullable, onChange: (internship: Nullable) => void, } export const InternshipTypeItem = ({ type, ...props }: { type: InternshipType } & HTMLProps) => { const info = internshipTypeLabels[type]; return (
{ info.label }
{ info.description && { info.description } }
) } const InternshipProgramForm = ({ internship, onChange }: InternshipFormSectionProps) => { const fieldProps = formFieldProps(internship, onChange); const course = internship.intern?.course as Course; return ( } getOptionLabel={ (option: InternshipType) => internshipTypeLabels[option].label } renderOption={ (option: InternshipType) => } options={ Object.values(InternshipType) as InternshipType[] } disableClearable { ...fieldProps("type", (event, value) => value) as any } /> { internship.type === InternshipType.Other && } {/**/} {/* */} {/* Realizowane punkty programu praktyk (minimum 3)*/} {/* { course.possibleProgramEntries.map(entry => {*/} {/* return (*/} {/* }*/} {/* />*/} {/* )*/} {/* }) }*/} {/* */} {/**/} ) } const InternshipDurationForm = ({ internship, onChange }: InternshipFormSectionProps) => { const [startDate, setStartDate] = useProxyState(internship.startDate, value => onChange({ ...internship, startDate: value })); const [endDate, setEndDate] = useProxyState(internship.endDate, value => onChange({ ...internship, endDate: value })); const [overrideHours, setHoursOverride] = useState(null) const [workingHours, setWorkingHours] = useState(40) const computedHours = useMemo(() => startDate && endDate && computeWorkingHours(startDate, endDate, workingHours / 5), [startDate, endDate, workingHours]); const hours = useMemo(() => overrideHours !== null ? overrideHours : computedHours || null, [overrideHours, computedHours]); const weeks = useMemo(() => hours !== null ? Math.floor(hours / 40) : null, [ hours ]); useEffect(() => onChange({ ...internship, hours }), [hours]) return ( Wymiar etatu setWorkingHours(parseInt(ev.target.value) || 0) } fullWidth /> Liczba godzin w tygodniu roboczym Łączna liczba godzin setHoursOverride(parseInt(ev.target.value) || 0) } fullWidth /> Liczba tygodni Wyliczona automatycznie ); } export const InternshipForm: React.FunctionComponent = props => { const initialInternshipState = useSelector>(state => getInternshipProposal(state.proposal) || { ...emptyInternship, intern: sampleStudent }); const [internship, setInternship] = useState>(initialInternshipState) const { t } = useTranslation(); const dispatch = useDispatch(); const history = useHistory(); const handleSubmit = () => { dispatch({ type: InternshipProposalActions.Send, internship: internship as Internship }); history.push(route("home")) } return (
Dane osoby odbywającej praktykę Rodzaj i program praktyki Czas trwania praktyki Miejsce odbywania praktyki
) }