Redirect to previous path after login

This commit is contained in:
Kacper Donat 2020-11-18 19:29:58 +01:00
parent 9bf5412b0d
commit 4148a78627
9 changed files with 33 additions and 14 deletions

7
deploy-stg.sh Normal file
View File

@ -0,0 +1,7 @@
BASEDIR=$(dirname "$0")
npx webpack --mode production --progress || exit $?
rsync -azv $BASEDIR/public/* system-praktyk@kadet.net:~/stg/front
rsync -azv $BASEDIR/build/* system-praktyk@kadet.net:~/stg/front

View File

@ -2,7 +2,7 @@ import { InternshipType } from "@/data";
import { axios } from "@/api/index"; import { axios } from "@/api/index";
import { InternshipTypeDTO, internshipTypeDtoTransformer } from "@/api/dto/type"; import { InternshipTypeDTO, internshipTypeDtoTransformer } from "@/api/dto/type";
const AVAILABLE_INTERNSHIP_TYPES = '/internshipTypes'; const AVAILABLE_INTERNSHIP_TYPES = '/internshipTypes/current';
export async function available(): Promise<InternshipType[]> { export async function available(): Promise<InternshipType[]> {
const response = await axios.get<InternshipTypeDTO[]>(AVAILABLE_INTERNSHIP_TYPES); const response = await axios.get<InternshipTypeDTO[]>(AVAILABLE_INTERNSHIP_TYPES);

View File

@ -98,9 +98,12 @@ function App() {
</header> </header>
<main id="content"> <main id="content">
{ <Switch> { <Switch>
{ routes.map(({ name, content, middlewares = [], ...route }) => <Route { ...route } key={ name }> { routes.map(({ name, content, middlewares = [], ...route }) =>
{ processMiddlewares([ ...middlewares, content ]) } <Route { ...route } key={ name } render={ () => {
</Route>) } const Next = () => processMiddlewares([ ...middlewares, content ])
return <Next />
} } />
) }
</Switch> } </Switch> }
</main> </main>
<footer className="footer"> <footer className="footer">

View File

@ -1,8 +1,8 @@
import { Middleware, route } from "@/routing"; import { Middleware, route } from "@/routing";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { AppState, isReady } from "@/state/reducer"; import { AppState, isReady } from "@/state/reducer";
import { Redirect } from "react-router-dom"; import { Redirect, useRouteMatch } from "react-router-dom";
import React from "react"; import React, { useEffect } from "react";
import { UserState } from "@/state/reducer/user"; import { UserState } from "@/state/reducer/user";
export const isReadyMiddleware: Middleware<any, any> = Next => isLoggedInMiddleware(() => { export const isReadyMiddleware: Middleware<any, any> = Next => isLoggedInMiddleware(() => {
@ -22,5 +22,7 @@ export const isLoggedInMiddleware: Middleware<any, any> = Next => {
return <Next />; return <Next />;
} }
window.sessionStorage.setItem('back-path', window.location.pathname);
return <Redirect to={ route("user_login") } />; return <Redirect to={ route("user_login") } />;
} }

View File

@ -12,18 +12,19 @@ import { Alert } from "@material-ui/lab";
import { Subset } from "@/helpers"; import { Subset } from "@/helpers";
import { useDispatch } from "@/state/actions"; import { useDispatch } from "@/state/actions";
import { loginToEdition } from "@/pages/edition/pick"; import { loginToEdition } from "@/pages/edition/pick";
import { useHistory } from "react-router-dom"; import { useHistory, useRouteMatch } from "react-router-dom";
import { useDebouncedEffect } from "@/hooks/useDebouncedEffect"; import { useDebouncedEffect } from "@/hooks/useDebouncedEffect";
export const RegisterEditionPage = () => { export const RegisterEditionPage = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const [key, setKey] = useState<string>("");
const [{ value: edition, isLoading }, setEdition] = useAsyncState<Subset<Edition> | null>(undefined);
const classes = useVerticalSpacing(3); const classes = useVerticalSpacing(3);
const dispatch = useDispatch(); const dispatch = useDispatch();
const history = useHistory(); const history = useHistory();
const match = useRouteMatch<any>();
const [key, setKey] = useState<string>(match.params['edition'] || "");
const [{ value: edition, isLoading }, setEdition] = useAsyncState<Subset<Edition> | null>(undefined);
useDebouncedEffect(() => { useDebouncedEffect(() => {
setEdition(api.edition.get(key)); setEdition(api.edition.get(key));

View File

@ -45,6 +45,10 @@ export const UserLoginPage = () => {
const query = new URLSearchParams(useLocation().search); const query = new URLSearchParams(useLocation().search);
const { t } = useTranslation(); const { t } = useTranslation();
const redirectAfterLogin = () => {
history.push(window.sessionStorage.getItem('back-path') || "/");
}
const handleSampleAdminLogin = async () => { const handleSampleAdminLogin = async () => {
await dispatch(authorizeUser(undefined, { isManager: true })); await dispatch(authorizeUser(undefined, { isManager: true }));
@ -53,8 +57,7 @@ export const UserLoginPage = () => {
const handleSampleStudentLogin = async () => { const handleSampleStudentLogin = async () => {
await dispatch(authorizeUser()); await dispatch(authorizeUser());
redirectAfterLogin();
history.push(route("home"));
} }
const handlePgLogin = async () => { const handlePgLogin = async () => {
@ -67,7 +70,7 @@ export const UserLoginPage = () => {
(async function() { (async function() {
if (location.pathname === `${match.path}/check/pg`) { if (location.pathname === `${match.path}/check/pg`) {
await dispatch(authorizeUser(query.get("code") as string)); await dispatch(authorizeUser(query.get("code") as string));
history.push("/"); redirectAfterLogin();
} }
})(); })();
}, [ match.path ]); }, [ match.path ]);

View File

@ -37,6 +37,7 @@ export const routes: Route[] = [
// edition // edition
{ name: "edition_register", path: "/edition/register", exact: true, content: () => <RegisterEditionPage/>, middlewares: [ isLoggedInMiddleware ] }, { name: "edition_register", path: "/edition/register", exact: true, content: () => <RegisterEditionPage/>, middlewares: [ isLoggedInMiddleware ] },
{ name: "edition_register_exact", path: "/edition/register/:edition", exact: true, content: () => <RegisterEditionPage/>, middlewares: [ isLoggedInMiddleware ] },
{ name: "edition_pick", path: "/edition/pick", exact: true, content: () => <PickEditionPage/>, middlewares: [ isLoggedInMiddleware ] }, { name: "edition_pick", path: "/edition/pick", exact: true, content: () => <PickEditionPage/>, middlewares: [ isLoggedInMiddleware ] },
// internship // internship

View File

@ -224,6 +224,8 @@ validation:
api: api:
GreaterThanOrEqualValidator: Wartość pola "{{ PropertyName }}" musi być większa bądź równa {{ ComparisonValue }}. GreaterThanOrEqualValidator: Wartość pola "{{ PropertyName }}" musi być większa bądź równa {{ ComparisonValue }}.
NotEmptyValidator: Wartosć pola "{{ PropertyName }}" nie może być pusta. NotEmptyValidator: Wartosć pola "{{ PropertyName }}" nie może być pusta.
NotNullValidator: Wartosć pola "{{ PropertyName }}" nie może być pusta.
PredicateValidator: Wartosć pola "{{ PropertyName }}" nie spełnia warunków walidacji.
required: "To pole jest wymagane" required: "To pole jest wymagane"
email: "Wprowadź poprawny adres e-mail" email: "Wprowadź poprawny adres e-mail"
phone: "Wprowadź poprawny numer telefonu" phone: "Wprowadź poprawny numer telefonu"

View File

@ -59,7 +59,7 @@ const config = {
port: parseInt(process.env.APP_PORT || "3000"), port: parseInt(process.env.APP_PORT || "3000"),
proxy: { proxy: {
"/api": { "/api": {
target: "https://system-praktyk.stg.kadet.net/api/", target: "https://system-praktyk.dev.kadet.net/api/",
changeOrigin: true, changeOrigin: true,
pathRewrite: { pathRewrite: {
"^/api": '' "^/api": ''