From c7fa02d5882582743806e01a206abab09c285282 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Tue, 18 Aug 2020 20:31:18 +0200 Subject: [PATCH] Add fake login page until CAS access is granted --- src/app.tsx | 10 +------ src/forms/internship.tsx | 4 ++- src/pages/main.tsx | 53 +++++++++++++++++++++------------- src/pages/steps/insurance.tsx | 5 ---- src/pages/user/login.tsx | 35 ++++++++++++++++++++++ src/routing.tsx | 5 ++++ src/state/reducer/insurance.ts | 15 +++++++++- translations/pl.yaml | 7 +++-- 8 files changed, 95 insertions(+), 39 deletions(-) create mode 100644 src/pages/user/login.tsx diff --git a/src/app.tsx b/src/app.tsx index cfdb347..1758fdb 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -4,7 +4,6 @@ import { route, routes } from "@/routing"; import { useSelector } from "react-redux"; import { AppState, isReady } from "@/state/reducer"; import { StudentActions } from "@/state/actions/student"; -import { sampleStudent } from "@/provider/dummy/student"; import { Trans, useTranslation } from "react-i18next"; import { Student } from "@/data"; import '@/styles/overrides.scss' @@ -26,13 +25,6 @@ const UserMenu = (props: HTMLProps) => { const dispatch = useDispatch(); const { t } = useTranslation(); - const handleUserLogin = () => { - dispatch({ - type: StudentActions.Login, - student: sampleStudent, - }) - } - const handleUserLogout = () => { dispatch({ type: StudentActions.Logout }) } @@ -44,7 +36,7 @@ const UserMenu = (props: HTMLProps) => { { ' ' } ({ t('logout') }) : <> - { t('login') } + { t('login') } } ; diff --git a/src/forms/internship.tsx b/src/forms/internship.tsx index 7f0b103..10fb302 100644 --- a/src/forms/internship.tsx +++ b/src/forms/internship.tsx @@ -284,7 +284,7 @@ export const InternshipForm: React.FunctionComponent = () => { postalCode: Yup.string().required(t("validation.required")), building: Yup.string().required(t("validation.required")), kindOther: Yup.string().when("kind", { - is: (values: InternshipFormValues) => values?.kind !== InternshipType.Other, + is: (values: InternshipFormValues) => values?.kind === InternshipType.Other, then: Yup.string().required(t("validation.required")) }) }) @@ -312,6 +312,8 @@ export const InternshipForm: React.FunctionComponent = () => { if (Object.keys(errors).length == 0) { setConfirmDialogOpen(true); + } else { + console.warn(errors); } } diff --git a/src/pages/main.tsx b/src/pages/main.tsx index f03e9b3..70ee9b4 100644 --- a/src/pages/main.tsx +++ b/src/pages/main.tsx @@ -1,7 +1,7 @@ import React, { useMemo } from "react"; import { Page } from "@/pages/base"; import { Button, Container, Stepper, Typography } from "@material-ui/core"; -import { Link as RouterLink } from "react-router-dom"; +import { Link as RouterLink, Redirect } from "react-router-dom"; import { route } from "@/routing"; import { useTranslation } from "react-i18next"; import { useSelector } from "react-redux"; @@ -11,40 +11,53 @@ import { Deadlines, Edition, getEditionDeadlines } from "@/data/edition"; import { Step } from "@/components"; import { ProposalStep } from "@/pages/steps/proposal"; import { PlanStep } from "@/pages/steps/plan"; -import { InsuranceStep } from "@/pages/steps/insurance"; import { InsuranceState } from "@/state/reducer/insurance"; +import { InsuranceStep } from "@/pages/steps/insurance"; export const MainPage = () => { const { t } = useTranslation(); const student = useSelector(state => state.student); + const deadlines = useSelector(state => getEditionDeadlines(state.edition as Edition)); // edition cannot be null at this point const insurance = useSelector(root => root.insurance); const missingStudentData = useMemo(() => student ? getMissingStudentData(student) : [], [student]); + if (!student) { + return ; + } + + function *getSteps() { + yield + { missingStudentData.length > 0 && <> +

{ t('steps.personal-data.info') }

+ +
    + { missingStudentData.map(field =>
  • { t(`student.${ field }`) }
  • ) } +
+ + + } +
; + + yield ; + yield ; + + if (insurance.required) + yield ; + + yield + yield + } + return { t("pages.my-internship.header") } - - { missingStudentData.length > 0 && <> -

{ t('steps.personal-data.info') }

- -
    - { missingStudentData.map(field =>
  • { t(`student.${ field }`) }
  • ) } -
- - - } -
- - - { insurance.required && } - - + { Array.from(getSteps()) }
diff --git a/src/pages/steps/insurance.tsx b/src/pages/steps/insurance.tsx index 2245c53..56e1a41 100644 --- a/src/pages/steps/insurance.tsx +++ b/src/pages/steps/insurance.tsx @@ -13,11 +13,6 @@ export const InsuranceStep = () => { const deadline = useSelector(state => getEditionDeadlines(state.edition as Edition).insurance); // edition cannot be null at this point const { t } = useTranslation(); - // we don't want to show this step unless it's required - if (!insurance.required) { - return null; - } - return

{ t(`steps.insurance.instructions`) }

diff --git a/src/pages/user/login.tsx b/src/pages/user/login.tsx new file mode 100644 index 0000000..d9cfe8c --- /dev/null +++ b/src/pages/user/login.tsx @@ -0,0 +1,35 @@ +import React from "react"; +import { Page } from "@/pages/base"; +import { Button, Container, Typography } from "@material-ui/core"; +import { StudentActions, useDispatch } from "@/state/actions"; +import { sampleStudent } from "@/provider/dummy"; +import { useHistory } from "react-router-dom"; +import { route } from "@/routing"; +import { useVerticalSpacing } from "@/styles"; + +export const UserLoginPage = () => { + const dispatch = useDispatch(); + const history = useHistory(); + + const handleSampleLogin = () => { + dispatch({ + type: StudentActions.Login, + student: sampleStudent, + }) + + history.push(route("home")); + } + + const classes = useVerticalSpacing(3); + + return + + Tu miało być przekierowanie do logowania PG... + + + ... ale wciąż czekamy na dostęp :( + + + + ; +} diff --git a/src/routing.tsx b/src/routing.tsx index c0e3e2e..6520bb8 100644 --- a/src/routing.tsx +++ b/src/routing.tsx @@ -4,10 +4,12 @@ import { RouteProps } from "react-router-dom"; import { InternshipProposalFormPage, InternshipProposalPreviewPage } from "@/pages/internship/proposal"; import { NotFoundPage } from "@/pages/errors/not-found"; import SubmitPlanPage from "@/pages/internship/plan"; +import { UserLoginPage } from "@/pages/user/login"; type Route = { name?: string; content: () => ReactComponentElement, + condition?: () => boolean, } & RouteProps; export const routes: Route[] = [ @@ -17,6 +19,9 @@ export const routes: Route[] = [ { name: "internship_proposal_preview", path: "/internship/preview/proposal", exact: true, content: () => }, { name: "internship_plan", path: "/internship/plan", exact: true, content: () => }, + // user + { name: "user_login", path: "/user/login", exact: true, content: () => }, + // fallback route for 404 pages { name: "fallback", path: "*", content: () => } ] diff --git a/src/state/reducer/insurance.ts b/src/state/reducer/insurance.ts index d5aaa4f..fded761 100644 --- a/src/state/reducer/insurance.ts +++ b/src/state/reducer/insurance.ts @@ -1,5 +1,7 @@ import { Reducer } from "react"; import { InsuranceAction, InsuranceActions } from "@/state/actions/insurance"; +import { InternshipProposalAction, InternshipProposalActions } from "@/state/actions"; +import { InternshipType } from "@/data"; export type InsuranceState = { required: boolean; @@ -12,10 +14,21 @@ const initialInsuranceState: InsuranceState = { signed: false, } -export const insuranceReducer: Reducer = (state = initialInsuranceState, action) => { +export const insuranceReducer: Reducer = (state = initialInsuranceState, action) => { const { type, ...payload } = action; switch (action.type) { + case InternshipProposalActions.Send: + return { + ...state, + required: [ + InternshipType.FreeApprenticeship, + InternshipType.FreeInternship, + InternshipType.PaidApprenticeship, + InternshipType.GraduateInternship, + ].includes(action.internship.type) + } + case InsuranceActions.Signed: return { ...state, signed: true } case InsuranceActions.Update: diff --git a/translations/pl.yaml b/translations/pl.yaml index 9bc83eb..5adbb13 100644 --- a/translations/pl.yaml +++ b/translations/pl.yaml @@ -31,7 +31,7 @@ pages: my-internship: header: "Moja praktyka" proposal-form: - header: "Propose internship" + header: "Zgłoszenie praktyki" forms: internship: @@ -138,7 +138,8 @@ steps: header: "Indywidualny Program Praktyki" info: draft: > - TODO + W porozumieniu z firmą w której odbywają się praktyki należy sporządzić Indywidualny Plan Praktyk zgodnie z + załączonym szablonem a następnie wysłać go do weryfikacji. (TODO) awaiting: > Twój indywidualny program praktyki został poprawnie zapisany w systemie. Musi on jeszcze zostać zweryfikowany i zatwierdzony. Po weryfikacji zostaniesz poinformowany o akceptacji bądź konieczności wprowadzenia zmian. @@ -157,7 +158,7 @@ steps: insurance: header: "Ubezpieczenie NNW" instructions: > - papierki do podpisania... + Należy zgłosić się do pełnomocnika ds. praktyk Twojego kierunku i podpisać umowę ubezpieczenia. (TODO) validation: required: "To pole jest wymagane" -- 2.45.2