Skip to content

Commit 1b92841

Browse files
authored
✨ add 404 page, and add network-only for statistics profile (#126)
* ✨ add 404 page, and add network-only for statistics profile * ⚡ add page not found url * 🔨 add some conditions to view loading or page not found page
1 parent ecd36bb commit 1b92841

File tree

6 files changed

+125
-65
lines changed

6 files changed

+125
-65
lines changed

i18n/en.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export default {
2+
error: {
3+
title404: "We are sorry, Page not found!",
4+
text404: "The page you are looking for might have been removed had its name changed or is temporarily unavailable.",
5+
button404: "Back to home"
6+
},
27
nav: {
38
mySkills: "My skills",
49
zenikaSkills: "Zenika skills",

i18n/fr.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export default {
2+
error: {
3+
title404: "Nous sommes désolé, page invalide !",
4+
text404: "L'URL de la page que vous avez demandé n'existe probablement pas ou est temporairement indisponible.",
5+
button404: "Retour au menu"
6+
},
27
nav: {
38
mySkills: "Compétences",
49
zenikaSkills: "Zenika",

src/pages/404.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { i18nContext } from "../utils/i18nContext";
2+
import React, { useContext } from "react";
3+
4+
export default function Custom404() {
5+
const { t } = useContext(i18nContext);
6+
return (
7+
<div className="container mx-auto px-4">
8+
<section className="py-8 px-4 text-center">
9+
<div className="max-w-auto mx-auto">
10+
<div className="md:max-w-lg mx-auto"></div>
11+
<h2 className="mt-8 uppercase text-xl lg:text-5xl font-black">
12+
{t("error.title404")}
13+
</h2>
14+
<p className="mt-6 uppercase text-sm lg:text-base text-gray-900">
15+
{t("error.text404")}
16+
</p>
17+
<a
18+
href="/"
19+
className="mt-6 bg-blue-500 hover:bg-blue-700 text-white font-light py-4 px-6 rounded-full inline-block uppercase shadow-md"
20+
>
21+
{t("error.button404")}
22+
</a>
23+
</div>
24+
</section>
25+
</div>
26+
);
27+
}

src/pages/profile/[email]/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext } from "react";
1+
import React, { useContext, useEffect, useState } from "react";
22
import { i18nContext } from "../../../utils/i18nContext";
33
import { useAuth0, withAuthenticationRequired } from "@auth0/auth0-react";
44
import CommonPage from "../../../components/CommonPage";
@@ -11,7 +11,7 @@ import {
1111
} from "../../../graphql/queries/userInfos";
1212
import ViewAgency from "../../../components/profile/ViewAgency";
1313
import PreferedTopics from "../../../components/profile/PreferedTopics";
14-
14+
import Custom404 from "../../404";
1515
type GetUserAgencyAndAllAgenciesResult = {
1616
User: {
1717
email: string;
@@ -53,7 +53,7 @@ const Profile = () => {
5353
const router = useRouter();
5454
const { t } = useContext(i18nContext);
5555
const { context, email: userEmail } = router.query;
56-
const { data, error } = useQuery<GetUserAgencyAndAllAgenciesResult>(
56+
const { data, error, loading } = useQuery<GetUserAgencyAndAllAgenciesResult>(
5757
USER_INFOS,
5858
{
5959
variables: { email: userEmail },
@@ -69,7 +69,6 @@ const Profile = () => {
6969
},
7070
});
7171
}
72-
7372
const infoUser = data?.User[0];
7473
const userAgency =
7574
error || infoUser?.UserLatestAgency?.agency
@@ -82,7 +81,7 @@ const Profile = () => {
8281

8382
return (
8483
<div>
85-
{infoUser ? (
84+
{data?.User?.length > 0 && !error && !loading ? (
8685
<CommonPage page={"profile"} faded={false} context={context}>
8786
<div className="flex flex-row justify-center mt-4 mb-20">
8887
<div className="flex flex-col justify-center max-w-screen-md w-full p-4">
@@ -120,8 +119,10 @@ const Profile = () => {
120119
</div>
121120
</div>
122121
</CommonPage>
122+
) : loading ? (
123+
t("loading.loadingText")
123124
) : (
124-
<p>{t(`loading.loadingText`)}</p>
125+
<Custom404 />
125126
)}
126127
</div>
127128
);

src/pages/profile/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const Profile = () => {
6363
USER_INFOS,
6464
{
6565
variables: { email: user?.email },
66+
fetchPolicy: "network-only",
6667
}
6768
);
6869
const [insertUser] = useMutation(INSERT_USER_MUTATION);

src/pages/skills/[context]/[category]/add.tsx

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { FetchResult } from ".";
1313
import CommonPage from "../../../../components/CommonPage";
1414
import { useNotification } from "../../../../utils/useNotification";
1515
import { i18nContext } from "../../../../utils/i18nContext";
16+
import Custom404 from "../../../404";
1617

1718
type Skill = {
1819
id: string;
@@ -144,21 +145,30 @@ const AddSkill = () => {
144145
const [selectedSkill, setSelectedSkill] = useState<Skill | undefined>(
145146
undefined
146147
);
147-
const { data, refetch } = useQuery<FetchResult>(SKILLS_AND_APPETITE_QUERY, {
148+
const {
149+
data,
150+
error: errorSkillsApetite,
151+
refetch,
152+
loading: loadingSkillsApetite,
153+
} = useQuery<FetchResult>(SKILLS_AND_APPETITE_QUERY, {
148154
variables: { email: user.email, category: category || "" },
149155
fetchPolicy: "network-only",
150156
});
151157
const [debouncedSearchValue] = useDebounce(search, 500);
152-
const { data: skillsData, refetch: refetchSearch } =
153-
useQuery<SkillSearchResult>(SKILL_SEARCH_QUERY, {
154-
variables: {
155-
category,
156-
search: `%${debouncedSearchValue}%`,
157-
email: user?.email,
158-
didYouMeanSearch: computeDidYouMeanSearchString(debouncedSearchValue),
159-
},
160-
fetchPolicy: "network-only",
161-
});
158+
const {
159+
data: skillsData,
160+
refetch: refetchSearch,
161+
loading: loadingSearchSkill,
162+
error: errorSearchSkills,
163+
} = useQuery<SkillSearchResult>(SKILL_SEARCH_QUERY, {
164+
variables: {
165+
category,
166+
search: `%${debouncedSearchValue}%`,
167+
email: user?.email,
168+
didYouMeanSearch: computeDidYouMeanSearchString(debouncedSearchValue),
169+
},
170+
fetchPolicy: "network-only",
171+
});
162172
const [addSkill, { error: mutationError }] = useMutation(ADD_SKILL_MUTATION, {
163173
onCompleted: (_) => {
164174
useNotification(
@@ -205,58 +215,69 @@ const AddSkill = () => {
205215
})
206216
);
207217
const categoryId = data?.Category[0]?.["id"];
208-
209218
return (
210-
<CommonPage page={category} faded={modaleOpened} context={context}>
211-
<PageWithSkillList
212-
context={context}
213-
category={category}
214-
add={true}
215-
faded={modaleOpened}
216-
data={radarData}
217-
color={data?.Category[0].color}
218-
>
219-
<div>
220-
<div
221-
className={`z-20 fixed inset-y-0 right-0 h-screen w-full ${
222-
modaleOpened ? "" : "hidden"
223-
}`}
219+
<div>
220+
{radarData &&
221+
!errorSkillsApetite &&
222+
!loadingSearchSkill &&
223+
!loadingSkillsApetite &&
224+
!errorSearchSkills ? (
225+
<CommonPage page={category} faded={modaleOpened} context={context}>
226+
<PageWithSkillList
227+
context={context}
228+
category={category}
229+
add={true}
230+
faded={modaleOpened}
231+
data={radarData}
232+
color={data?.Category[0].color}
224233
>
225-
{selectedSkill ? (
226-
<div className="flex flex-row justify-center">
227-
<AddOrEditSkillModale
228-
skill={selectedSkill}
229-
cancel={() => setModaleOpened(false)}
230-
callback={addAction}
234+
<div>
235+
<div
236+
className={`z-20 fixed inset-y-0 right-0 h-screen w-full ${
237+
modaleOpened ? "" : "hidden"
238+
}`}
239+
>
240+
{selectedSkill ? (
241+
<div className="flex flex-row justify-center">
242+
<AddOrEditSkillModale
243+
skill={selectedSkill}
244+
cancel={() => setModaleOpened(false)}
245+
callback={addAction}
246+
/>
247+
</div>
248+
) : (
249+
<></>
250+
)}
251+
</div>
252+
<div
253+
className={`flex flex-col ${
254+
isDesktop ? "h-radar" : ""
255+
} p-2 z-10 ${modaleOpened ? "opacity-25" : ""}`}
256+
>
257+
<SearchBar setSearch={setSearch} />
258+
<AddSkillListSelector
259+
action={preAddAction}
260+
skills={skillsData?.Skill.filter(
261+
(skill) =>
262+
skill.UserSkillDesires_aggregate.aggregate.count === 0
263+
)}
264+
categoryId={categoryId}
265+
search={debouncedSearchValue}
266+
didYouMeanSkills={skillsData?.didYouMeanSearch.filter(
267+
(skill) =>
268+
skill.UserSkillDesires_aggregate.aggregate.count === 0
269+
)}
231270
/>
232271
</div>
233-
) : (
234-
<></>
235-
)}
236-
</div>
237-
<div
238-
className={`flex flex-col ${isDesktop ? "h-radar" : ""} p-2 z-10 ${
239-
modaleOpened ? "opacity-25" : ""
240-
}`}
241-
>
242-
<SearchBar setSearch={setSearch} />
243-
<AddSkillListSelector
244-
action={preAddAction}
245-
skills={skillsData?.Skill.filter(
246-
(skill) =>
247-
skill.UserSkillDesires_aggregate.aggregate.count === 0
248-
)}
249-
categoryId={categoryId}
250-
search={debouncedSearchValue}
251-
didYouMeanSkills={skillsData?.didYouMeanSearch.filter(
252-
(skill) =>
253-
skill.UserSkillDesires_aggregate.aggregate.count === 0
254-
)}
255-
/>
256-
</div>
257-
</div>
258-
</PageWithSkillList>
259-
</CommonPage>
272+
</div>
273+
</PageWithSkillList>
274+
</CommonPage>
275+
) : loadingSkillsApetite && loadingSearchSkill ? (
276+
t("loading.loadingText")
277+
) : (
278+
<Custom404 />
279+
)}
280+
</div>
260281
);
261282
};
262283

0 commit comments

Comments
 (0)