From aaa078cc70a90f09ac0c9fb0e1fa6cf2d102d95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlota=20Catot=20Brag=C3=B3s?= Date: Sat, 13 Jan 2024 02:13:16 +0100 Subject: [PATCH 1/6] Fix issue in view errors --- organizator_api/app/applications/infrastructure/http/views.py | 2 +- .../infrastructure/http/test_view_attend_application.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/organizator_api/app/applications/infrastructure/http/views.py b/organizator_api/app/applications/infrastructure/http/views.py index 400fa962..09067740 100644 --- a/organizator_api/app/applications/infrastructure/http/views.py +++ b/organizator_api/app/applications/infrastructure/http/views.py @@ -292,6 +292,6 @@ def attend_application(request: HttpRequest, application_id: uuid.UUID) -> HttpR except OnlyAuthorizedToOrganizer: return HttpResponse(status=401, content="Only authorized to organizer") except ApplicationCanNotBeAttended: - return HttpResponse(status=422, content="Application can not be confirmed") + return HttpResponse(status=422, content="Application should be in confirmed status") return HttpResponse(status=200, content="Application is correctly attended") diff --git a/organizator_api/tests/applications/infrastructure/http/test_view_attend_application.py b/organizator_api/tests/applications/infrastructure/http/test_view_attend_application.py index 3d76a420..03f7f657 100644 --- a/organizator_api/tests/applications/infrastructure/http/test_view_attend_application.py +++ b/organizator_api/tests/applications/infrastructure/http/test_view_attend_application.py @@ -126,7 +126,7 @@ def test__given_a_valid_organizer_token_and_a_application_in_wait_list_status__w # Then self.assertEqual(response.status_code, 422) - self.assertEqual(response.content, b"Application can not be confirmed") + self.assertEqual(response.content, b"Application should be in confirmed status") def test__given_a_valid_organizer_token_and_a_application_in_confirmed_status__when_attend_application__then_application_is_attended( self, From 660da842db9463307b331a90e2a67c6f14edf762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlota=20Catot=20Brag=C3=B3s?= Date: Sat, 13 Jan 2024 02:13:33 +0100 Subject: [PATCH 2/6] black --- organizator_api/app/applications/infrastructure/http/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/organizator_api/app/applications/infrastructure/http/views.py b/organizator_api/app/applications/infrastructure/http/views.py index 09067740..dd20801a 100644 --- a/organizator_api/app/applications/infrastructure/http/views.py +++ b/organizator_api/app/applications/infrastructure/http/views.py @@ -292,6 +292,8 @@ def attend_application(request: HttpRequest, application_id: uuid.UUID) -> HttpR except OnlyAuthorizedToOrganizer: return HttpResponse(status=401, content="Only authorized to organizer") except ApplicationCanNotBeAttended: - return HttpResponse(status=422, content="Application should be in confirmed status") + return HttpResponse( + status=422, content="Application should be in confirmed status" + ) return HttpResponse(status=200, content="Application is correctly attended") From 1259871f86284c2f3fbd5603f32e7fbacd7d11e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlota=20Catot=20Brag=C3=B3s?= Date: Sat, 13 Jan 2024 02:36:07 +0100 Subject: [PATCH 3/6] axios call for attend --- organizator/utils/api/axiosApplications.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/organizator/utils/api/axiosApplications.ts b/organizator/utils/api/axiosApplications.ts index cb8a52e1..fcce2669 100644 --- a/organizator/utils/api/axiosApplications.ts +++ b/organizator/utils/api/axiosApplications.ts @@ -182,3 +182,25 @@ export async function confirmApplication( }; } } + +export async function attendApplication( + token: string, + applicationId: string, +): Promise { + try { + await axios({ + method: "post", + url: `${applicationsAPI}/attend/${applicationId}`, + headers: { + Authorization: `${token}`, + }, + }); + return { + error: null, + }; + } catch (error: any) { + return { + error: error.response.data, + }; + } +} From a4d67bd52fe0d228a653186b5f40844217f5c09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlota=20Catot=20Brag=C3=B3s?= Date: Sat, 13 Jan 2024 02:36:24 +0100 Subject: [PATCH 4/6] add attended option for tags --- organizator/utils/util-functions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/organizator/utils/util-functions.ts b/organizator/utils/util-functions.ts index bde5e463..3c27949e 100644 --- a/organizator/utils/util-functions.ts +++ b/organizator/utils/util-functions.ts @@ -234,6 +234,7 @@ export function getColorForApplicationStatus(st: string): string { if (st === "Confirmed") return "#6cd27b"; if (st === "Invalid") return "#867f7f"; if (st === "Wait list") return "#b694f5"; + if (st === "Attended") return "#9df5ae"; return "#000000"; } From e4a678df9fc2d35f9265adedfab1cc9d7a21a0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlota=20Catot=20Brag=C3=B3s?= Date: Sat, 13 Jan 2024 02:36:41 +0100 Subject: [PATCH 5/6] attended button in confirmed participants --- organizator/app/(tabs)/manage/[id].tsx | 119 ++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/organizator/app/(tabs)/manage/[id].tsx b/organizator/app/(tabs)/manage/[id].tsx index 92445105..70cef75d 100644 --- a/organizator/app/(tabs)/manage/[id].tsx +++ b/organizator/app/(tabs)/manage/[id].tsx @@ -5,10 +5,12 @@ import FontAwesome from "@expo/vector-icons/FontAwesome"; import styled from "styled-components/native"; import Toast from "react-native-toast-message"; import { router, useLocalSearchParams } from "expo-router"; -import { Dialog } from "react-native-simple-dialogs"; +import { ConfirmDialog, Dialog } from "react-native-simple-dialogs"; import LoadingPage from "../../../components/LodingPage"; import { getToken, removeToken } from "../../../utils/sessionCalls"; import { + attendApplication, + confirmApplication, getParticipants, updateApplicationStatus, } from "../../../utils/api/axiosApplications"; @@ -42,7 +44,7 @@ const Username = styled(Text)` const ButtonAndRole = styled(View)` display: flex; flex-direction: row; - gap: 20px; + gap: 10px; align-items: center; `; @@ -80,6 +82,7 @@ export default function Id() { const [userToUpdate, setUserToUpdate] = useState(null); const [idToUpdate, setIdToUpdate] = useState(null); const [isAdmin, setIsAdmin] = useState(false); + const [isOrganizer, setIsOrganizer] = useState(false); const [applications, setApplications] = useState< ParticipantsInformation[] | null >(null); @@ -88,6 +91,11 @@ export default function Id() { ParticipantsInformation[] | null >(null); const [trigger, setTrigger] = useState(false); + const [showAttendAlert, setShowAttendAlert] = useState(false); + const [userToAttend, setUserToAttend] = useState(""); + const [idApplicationToAttend, setIdApplicationToAttend] = useState< + string | null + >(null); const [stats, setStats] = useState({ all: 0, confirmed: 0, @@ -159,6 +167,10 @@ export default function Id() { }); fetchAdminFunction().then((response) => { setIsAdmin(response.role === UserRoles.ORGANIZER_ADMIN); + setIsOrganizer( + response.role === UserRoles.ORGANIZER || + response.role === UserRoles.ORGANIZER_ADMIN, + ); }); }, [trigger]); @@ -214,6 +226,48 @@ export default function Id() { }); }; + const attendEvent = () => { + const fetchData = async () => { + const token = await getToken(); + return attendApplication(token || "", idApplicationToAttend || ""); + }; + + fetchData().then((response) => { + if (response.error) { + if ( + response.error === "Unauthorized" || + response.error === "Invalid token" + ) { + removeToken(); + router.replace("/login"); + } else { + setShowAttendAlert(false); + setUserToAttend(""); + setIdApplicationToAttend(null); + Toast.show({ + type: "error", + text1: "Error", + text2: `${response.error}`, + visibilityTime: 3000, + autoHide: true, + }); + } + } else { + Toast.show({ + type: "success", + text1: "Attended", + text2: `The user ${userToAttend} is attending`, + visibilityTime: 3000, + autoHide: true, + }); + setShowAttendAlert(false); + setUserToAttend(""); + setIdApplicationToAttend(null); + setTrigger(!trigger); + } + }); + }; + return ( @@ -440,6 +494,19 @@ export default function Id() { )} + {isOrganizer && application.status === "Confirmed" && ( + { + setUserToAttend( + `${application.user.first_name} ${application.user.last_name}`, + ); + setIdApplicationToAttend(application.id); + setShowAttendAlert(true); + }} + > + + + )} ))} @@ -499,6 +566,54 @@ export default function Id() { /> + + setShowAttendAlert(false)} + visible={showAttendAlert} + negativeButton={{ + title: "Cancel", + onPress: () => { + setShowAttendAlert(false); + setIdApplicationToAttend(null); + setUserToAttend(""); + }, + titleStyle: { + color: "red", + fontSize: 20, + }, + style: { + backgroundColor: "transparent", + paddingHorizontal: 10, + }, + }} + positiveButton={{ + title: "Confirm!", + onPress: () => { + attendEvent(); + console.log("Attend event"); + setShowAttendAlert(false); + setIdApplicationToAttend(null); + setUserToAttend(""); + }, + titleStyle: { + color: "blue", + fontSize: 20, + }, + style: { + backgroundColor: "transparent", + paddingHorizontal: 10, + }, + }} + contentInsetAdjustmentBehavior="automatic" + onRequestClose={() => { + setShowAttendAlert(false); + setIdApplicationToAttend(null); + setUserToAttend(""); + }} + /> + ); From f1e29353ee4bd73758c3a5dc12e3175147da8fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlota=20Catot=20Brag=C3=B3s?= Date: Sat, 13 Jan 2024 02:40:12 +0100 Subject: [PATCH 6/6] fix warning --- organizator/app/(tabs)/manage/[id].tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/organizator/app/(tabs)/manage/[id].tsx b/organizator/app/(tabs)/manage/[id].tsx index 70cef75d..2ac5a406 100644 --- a/organizator/app/(tabs)/manage/[id].tsx +++ b/organizator/app/(tabs)/manage/[id].tsx @@ -10,7 +10,6 @@ import LoadingPage from "../../../components/LodingPage"; import { getToken, removeToken } from "../../../utils/sessionCalls"; import { attendApplication, - confirmApplication, getParticipants, updateApplicationStatus, } from "../../../utils/api/axiosApplications";