Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { useDispatch, useSelector } from "react-redux";
import { useParams } from "react-router-dom";
import classNames from "classnames";

import { Loader, Share, UserAvatar } from "../../../../shared/components";
import {
Loader,
NotFound,
Share,
UserAvatar,
} from "../../../../shared/components";
import { Modal } from "../../../../shared/components/Modal";
import {
useAuthorizedModal,
Expand Down Expand Up @@ -31,7 +36,6 @@ import {
} from "../../components/CommonDetailContainer";
import { MembershipRequestModal } from "../../components/CommonDetailContainer/MembershipRequestModal";
import { ProposalDetailModal } from "../../components/CommonDetailContainer/ProposalDetailModal";
import "./index.scss";
import {
BASE_URL,
Colors,
Expand Down Expand Up @@ -60,6 +64,7 @@ import {
} from "../../store/actions";
import CheckIcon from "../../../../shared/icons/check.icon";
import { selectUser } from "../../../Auth/store/selectors";
import "./index.scss";

interface CommonDetailRouterParams {
id: string;
Expand Down Expand Up @@ -99,6 +104,7 @@ export default function CommonDetail() {
const [tab, setTab] = useState("about");
const [imageError, setImageError] = useState(false);
const [isCreationStageReached, setIsCreationStageReached] = useState(false);
const [isCommonFetched, setIsCommonFetched] = useState(false);

const common = useSelector(selectCommonDetail());
const currentDisscussion = useSelector(selectCurrentDisscussion());
Expand Down Expand Up @@ -159,7 +165,14 @@ export default function CommonDetail() {
const isMobileView = screenSize === ScreenSize.Mobile;

useEffect(() => {
dispatch(getCommonDetail.request(id));
dispatch(
getCommonDetail.request({
payload: id,
callback: () => {
setIsCommonFetched(true);
},
})
);
return () => {
dispatch(closeCurrentCommon());
};
Expand Down Expand Up @@ -349,7 +362,7 @@ export default function CommonDetail() {
}, [showJoinModal, shouldAllowJoiningToCommon, closeJoinModal]);

if (!common) {
return <Loader />;
return isCommonFetched ? <NotFound /> : <Loader />;
}

const sharingURL = `${BASE_URL}${ROUTE_PATHS.COMMON_LIST}/${common.id}`;
Expand Down
7 changes: 6 additions & 1 deletion src/containers/Common/store/actions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createAsyncAction, createStandardAction } from "typesafe-actions";

import { PayloadWithOptionalCallback } from "../../../shared/interfaces";
import { ProposalJoinRequestData } from "../../../shared/interfaces/api/proposal";
import { Common, Proposal, Discussion } from "../../../shared/models";
import { CommonsActionTypes } from "./constants";
Expand All @@ -14,7 +15,11 @@ export const getCommonDetail = createAsyncAction(
CommonsActionTypes.GET_COMMON_DETAIL,
CommonsActionTypes.GET_COMMON_DETAIL_SUCCESS,
CommonsActionTypes.GET_COMMON_DETAIL_FAILURE
)<string, Common | null, Error>();
)<
PayloadWithOptionalCallback<string, Common | null, Error>,
Common | null,
Error
>();

export const updatePage = createStandardAction(
CommonsActionTypes.UPDATE_PAGE
Expand Down
23 changes: 15 additions & 8 deletions src/containers/Common/store/saga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,32 @@ export function* getCommonsList(): Generator {
}
}

export function* getCommonDetail(
action: ReturnType<typeof actions.getCommonDetail.request>
): Generator {
export function* getCommonDetail({
payload,
}: ReturnType<typeof actions.getCommonDetail.request>): Generator {
try {
yield put(startLoading());
const common = yield call(fetchCommonDetail, action.payload);
const common = (yield call(fetchCommonDetail, payload.payload)) as Common;

const [discussions, proposals] = (yield Promise.all([
fetchCommonDiscussions((common as Common).id),
fetchCommonProposals((common as Common).id),
fetchCommonDiscussions(common.id),
fetchCommonProposals(common.id),
])) as any[];

yield put(actions.getCommonDetail.success(common as Common));
yield put(actions.getCommonDetail.success(common));
yield put(actions.setDiscussion(discussions));
yield put(actions.setProposals(proposals));

yield put(stopLoading());
if (payload.callback) {
payload.callback(null, common);
}
} catch (e) {
yield put(actions.getCommonDetail.failure(e));

if (payload.callback) {
payload.callback(e);
}
} finally {
yield put(stopLoading());
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/shared/components/NotFound.tsx

This file was deleted.

11 changes: 11 additions & 0 deletions src/shared/components/NotFound/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { FC } from "react";
import "./index.scss";

const NotFound: FC = () => (
<div className="page-not-found">
<span className="page-not-found__code">404</span>
<h3 className="page-not-found__message">This page could not be found.</h3>
</div>
);

export default NotFound;
27 changes: 27 additions & 0 deletions src/shared/components/NotFound/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@import "../../../constants";
@import "../../../styles/sizes";

.page-not-found {
margin-top: 4rem;
display: flex;
justify-content: center;
align-items: center;
color: $secondary-blue;

.page-not-found__code {
padding: 0.5rem 1.5rem 0.5rem 0;
font-size: $moderate-med;
font-weight: bold;
border-right: 2px solid $light-gray-3;
}

.page-not-found__message {
margin: 0 0 0 1.5rem;
font-size: $small;
font-weight: normal;
}

@include big-phone {
margin-top: 2.5rem;
}
}
1 change: 1 addition & 0 deletions src/shared/components/NotFound/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as NotFound } from "./NotFound";
2 changes: 1 addition & 1 deletion src/shared/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export * from "./ButtonLink";
export * from "./Common";
export { default as Content } from "./Content";
export * from "./FilesCarousel";
export { default as NotFound } from "./NotFound";
export * from "./NotFound";
export * from "./SocialLogin";
export * from "./Footer";
export * from "./Header";
Expand Down