Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirmation pages #262

Merged
merged 8 commits into from
Nov 4, 2024
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
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import EventsLanding from "./pages/Landing/EventsLanding";
import LegalInfoLanding from "./pages/Landing/LegalInfoLanding";
import Error404Landing from "./pages/Landing/Error404Landing";
import "src/styles/styles.css";
import ConfirmAssistancePage from "./pages/hackeps/Confirm";

export default function App() {
useEffect(() => {
Expand Down Expand Up @@ -94,6 +95,7 @@ export default function App() {
/>
<Route path="/forgot-password" element={<PasswordForget />} />
<Route path="/user-verification" element={<LoginVerify />} />
<Route path="/assistance" element={<ConfirmAssistancePage />} />
<Route path="*" element={<Error404 />} />
</Routes>
</Router>
Expand Down
50 changes: 50 additions & 0 deletions src/components/hackeps/ConfirmAssistance/ConfirmAssistance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useEffect, useState } from "react";
import { confirmAssistance } from "src/services/EventService";
import SuccessFeedback from "../Feedbacks/SuccesFeedback";
import TitleGeneralized from "../TitleGeneralized/TitleGeneralized";
import FailFeedback from "../Feedbacks/FailFeedback";

const ConfirmAssistance = ({ confirm, token }) => {
const [sending, setSending] = useState(true);
const [result, setResult] = useState(null);
useEffect(async () => {
if (confirm) {
setResult(await confirmAssistance(token));
setSending(false);
}
}, []);
return (
<div>
{confirm == "false" ? (
<TitleGeneralized>{"Pos ok:("}</TitleGeneralized>
) : (
<>
{!sending ? (
result && result.success ? (
<SuccessFeedback
title="Assistencia confirmada"
text="Ha confirmat la seva assistencia a la HackEps."
hasButton={true}
buttonText="Torna a l'inici"
buttonLink="/"
/>
) : (
<FailFeedback
title="Ha hagut un error"
text="El error és amb el missatge:"
italic={result.errMssg || "No hi ha hagut codi, contactans!"}
hasButton={true}
buttonText="Torna a l'inici"
buttonLink="/"
/>
)
) : (
<></>
)}
</>
)}
</div>
);
};

export default ConfirmAssistance;
12 changes: 8 additions & 4 deletions src/modules/fetchModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ export async function fetchPlus({
refresh_token = false,
loginAuth,
apiVersion = 1,
token,
forceDebug = false,
}) {
const headers = { "Content-Type": "application/json" };
if (hasUserauth || refresh_token || loginAuth)
if (hasUserauth || refresh_token || loginAuth || token)
headers.Authorization = loginAuth
? "Basic " + b64EncodeUnicode(`${loginAuth.email}:${loginAuth.password}`)
: hasUserauth
? "Bearer " + localStorage.getItem("userToken")
: "Bearer " + localStorage.getItem("refreshToken");
: "Bearer " +
(hasUserauth
? localStorage.getItem("userToken")
: refresh_token
? localStorage.getItem("refreshToken")
: token);
const args = {
method: Method,
headers: headers,
Expand Down
35 changes: 35 additions & 0 deletions src/pages/hackeps/Confirm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useEffect } from "react";
import Header from "src/components/hackeps/Header/Header.js";
import ConfirmAssistance from "src/components/hackeps/ConfirmAssistance/ConfirmAssistance";
import Footer from "src/components/hackeps/Footer/Footer.js";
import { useLocation, useNavigate } from "react-router-dom";

const ConfirmAssistancePage = (props) => {
const { state } = useLocation();
const navigate = useNavigate();
const params = new URLSearchParams(window.location.search);
const confirm = state?.confirm || params.get("confirm");
const token = state?.token || params.get("token");

useEffect(() => {
if (!confirm || !token) {
navigate("/");
}
}, [confirm, token, navigate]);

return (
<div>
{confirm && token ? (
<>
<Header />
<ConfirmAssistance confirm={confirm} token={token} />
<Footer />
</>
) : (
<></>
)}
</div>
);
};

export default ConfirmAssistancePage;
4 changes: 2 additions & 2 deletions src/services/EventService.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ export async function getUnregisteredHackersCount(event_id) {
});
}

export async function confirmAssistance() {
export async function confirmAssistance(confirm_token) {
return fetchPlus({
Url: `/event/confirm-assistance`,
hasUserauth: true,
token: confirm_token,
});
}

Expand Down
Loading