diff --git a/.vscode/settings.json b/.vscode/settings.json index 0e96dfc..4c24215 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,7 @@ "editor.codeActionsOnSave": { "source.fixAll": true }, + "editor.formatOnSave": true, + "editor.defaultFormatter": "esbenp.prettier-vscode", "typescript.tsdk": "node_modules/typescript/lib" } \ No newline at end of file diff --git a/src/features/application/applicationSlice.ts b/src/features/application/applicationSlice.ts new file mode 100644 index 0000000..ea7b6f8 --- /dev/null +++ b/src/features/application/applicationSlice.ts @@ -0,0 +1,34 @@ +/* eslint-disable camelcase */ +/* eslint-disable no-param-reassign */ +import { PayloadAction, createSlice } from "@reduxjs/toolkit"; + +import { RootState } from "store"; + +interface Application { + finnish: boolean; +} + +interface ApplicationState { + application: Application | null; +} + +export const initialState: ApplicationState = { + application: null, +}; + +const applicationSlice = createSlice({ + name: "application", + initialState, + reducers: { + applicationSuccess(state, action: PayloadAction) { + state.application = action.payload; + }, + }, +}); + +export const selectIsFinnish = (state: RootState): boolean | undefined => + state.application.application?.finnish; + +export const { applicationSuccess } = applicationSlice.actions; + +export default applicationSlice.reducer; diff --git a/src/features/auth/AuthenticatedLayer.tsx b/src/features/auth/AuthenticatedLayer.tsx index 2832e46..1ccf001 100644 --- a/src/features/auth/AuthenticatedLayer.tsx +++ b/src/features/auth/AuthenticatedLayer.tsx @@ -9,6 +9,7 @@ import Axios from "axios"; import { TokenStorage } from "utils/tokenInterceptor"; import { useDispatch } from "react-redux"; import { useSelector } from "react-redux"; +import { applicationSuccess } from "features/application/applicationSlice"; interface AuthenticatedLayerProps { children: React.ReactElement; @@ -22,8 +23,11 @@ export default function AuthenticatedLayer( useEffect(() => { Axios.get("/user/@me") .then((res) => { - dispatch(authSuccess()); - dispatch(userInfoSuccess(res.data)); + Axios.get("/application/@me").then(r2 => { + dispatch(authSuccess()); + dispatch(userInfoSuccess(res.data)); + dispatch(applicationSuccess(r2.data)) + }) }) .catch(console.error); }, [isAuthenticated]); diff --git a/src/features/auth/register/index.tsx b/src/features/auth/register/index.tsx index e8f90eb..d11c73b 100644 --- a/src/features/auth/register/index.tsx +++ b/src/features/auth/register/index.tsx @@ -33,7 +33,7 @@ const Register: React.FC = ({ t }) => { const { push } = useHistory(); const toastId = React.useRef(null); const applicationHasClosed = - moment.utc().month(2).endOf("month").diff(Date.now()) < 0; + moment("04-23", "MM-DD").utc().diff(Date.now()) < 0; return (
@@ -203,6 +203,7 @@ const Register: React.FC = ({ t }) => { type="radio" id="custom-inline-radio-2" name="finnish" + disabled /> @@ -232,6 +233,12 @@ const Register: React.FC = ({ t }) => { {t(errors.dummy)} )} + + {t("Application has closed for Sweden")} +