Skip to content

Commit

Permalink
Merge branch 'feat/request-hooks' of https://github.com/UoaWDCC/auis-…
Browse files Browse the repository at this point in the history
…portal into feat/request-hooks
  • Loading branch information
gmat224 committed Dec 21, 2024
2 parents d803021 + 6b7ff94 commit 39051b2
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 64 deletions.
2 changes: 1 addition & 1 deletion api/controller/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { insertUserBySuperToken } from "../gateway/userGateway";
export const updateUserTicketInfo = asyncHandler(
async (req: Request, res: Response) => {
// console.log(process.env.DOMAIN_DB);
console.log(req.body)
console.log(req.body);
try {
const { name, email, phoneNumber, ticketId, answers } = req.body;

Expand Down
2 changes: 1 addition & 1 deletion api/gateway/userGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export async function insertUserTicket(data: {
"insertUserTicket: userTicketsPeopleIdLink: ticketId: ",
data.ticketId
);

// let userTicketsPeopleIdLink = await db
// .insert(userTicketsPeopleIdLinks)
// .values({
Expand Down
34 changes: 16 additions & 18 deletions web/src/api/apiRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const getUserMetaData = async (): Promise<AxiosResponse> => {
"Content-Type": "application/json",
},
});
console.log("getUserMetatdat")
console.log(response)
console.log("getUserMetatdat");
console.log(response);
return response;
};

Expand All @@ -35,33 +35,31 @@ export const updateUserInfo = async (data: object): Promise<AxiosResponse> => {
data: { data },
});

console.log("update user info")
console.log(response)
console.log("update user info");
console.log(response);
return response;
};

export const updateUserTicketInfo = async (

ticketId: number,
name: string,
email: string,
phoneNumber: string,
answers: AnswerList[]

ticketId: number,
name: string,
email: string,
phoneNumber: string,
answers: AnswerList[]
): Promise<UpdateUserInfoOrNewUser> => {
const data = {
ticketId,
name,
email,
phoneNumber,
answers
}
answers,
};
const response = await apiClient.post("/api/user/user-ticket-info", data, {
headers: {
"Content-Type": "application/json",
},
})
console.log("update user ticket info worked")
});
console.log("update user ticket info worked");
return response.data;
};

Expand Down Expand Up @@ -115,8 +113,8 @@ export const getSessionStatus = async (
}
);

console.log("get session id")
console.log(response)
console.log("get session id");
console.log(response);

return response.data;
};
Expand All @@ -134,7 +132,7 @@ export const fetchEventOrMembershipCheckoutSecret = async (payload: {
headers: { "Content-Type": "application/json" },
}
);
console.log("FETCH EVENT OR MEBERSHcK CHECKOUT SECRETYE")
console.log("FETCH EVENT OR MEBERSHcK CHECKOUT SECRETYE");
return response.data.clientSecret;
};

Expand Down
39 changes: 22 additions & 17 deletions web/src/components/forms/CheckoutInformation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { AnswerList, QuestionAnswer, TicketAndQuestion } from "../../types/types";
import {
AnswerList,
QuestionAnswer,
TicketAndQuestion,
} from "../../types/types";
import { useEffect, useState } from "react";
import { useQuery } from "@apollo/client";
import { getTicketQuestions } from "../../graphql/queries";
Expand Down Expand Up @@ -57,7 +61,6 @@ export default function CheckoutInformation({
window.scrollTo(0, 0);
}, []);


// States
const [ticketAndQuestions, setTicketAndQuestions] =
useState<TicketAndQuestion>();
Expand All @@ -67,23 +70,25 @@ export default function CheckoutInformation({
const [submitError, setSubmitError] = useState(false);
const [submitLoading, setSubmitLoading] = useState(false);


const { data : updateUserTicketInfoData, mutateAsync, status } = useUpdateUserTicketInfo();
const {
data: updateUserTicketInfoData,
mutateAsync,
status,
} = useUpdateUserTicketInfo();
// Update status text as it changes
useEffect(() => {
if (status === "success") {
navigateToPaymentScreen(
updateUserTicketInfoData.updateUserInfoOrNewUser.userTicketId
)
);
}

if (status == "pending") {
setSubmitLoading(true);
}else {
setSubmitLoading(false)
} else {
setSubmitLoading(false);
}


if (status == "error") {
setSubmitError(true);
}
Expand All @@ -103,16 +108,16 @@ export default function CheckoutInformation({
const answerList = answers.map(({ question, indexId, ...rest }) => {
return rest;
});

// Mutation hook

mutateAsync({
ticketId: ticketId,
name: name,
email: email,
phoneNumber: phoneNumber,
answers: answerList,
})
ticketId: ticketId,
name: name,
email: email,
phoneNumber: phoneNumber,
answers: answerList,
});
// const temp = await mutateAsync(data)
// call post request
// onSubmit({
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/forms/CheckoutInformationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ export default function CheckoutInformationForm({
<br />
If this is a double ticket, both ticket holders must be members.
<br />
If this is a Member ticket, make sure you haven't already purchased a Member ticket.
If this is a Member ticket, make sure you haven't already purchased
a Member ticket.
</p>
) : (
<></>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function PurchaseMembershipCard({
}

return (
<div className="drop-shadow-all w-[30rem] m-5 rounded-lg bg-white">
<div className="drop-shadow-all m-5 w-[30rem] rounded-lg bg-white">
<div>
<div className="flex items-center justify-center">
<img
Expand Down
2 changes: 1 addition & 1 deletion web/src/hooks/api/useSessionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";
import { getSessionStatus } from "../../api/apiRequests";
import { stripeSessionStatus } from "../../types/types";

export const useSessionStatus = (sessionId : string) => {
export const useSessionStatus = (sessionId: string) => {
return useQuery<stripeSessionStatus, Error>({
queryKey: ["attendanceList"],
queryFn: () => getSessionStatus(sessionId),
Expand Down
27 changes: 8 additions & 19 deletions web/src/hooks/api/useUpdateUserTicketInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,14 @@ export const useUpdateUserTicketInfo = () => {
UpdateUserInfoOrNewUser,
Error,
{
ticketId: number;
name: string;
email: string;
phoneNumber: string;
answers: AnswerList[];
}
ticketId: number;
name: string;
email: string;
phoneNumber: string;
answers: AnswerList[];
}
>({
mutationFn: ({
ticketId,
name,
email,
phoneNumber,
answers
}) => updateUserTicketInfo(
ticketId,
name,
email,
phoneNumber,
answers
),
mutationFn: ({ ticketId, name, email, phoneNumber, answers }) =>
updateUserTicketInfo(ticketId, name, email, phoneNumber, answers),
});
};
4 changes: 3 additions & 1 deletion web/src/screens/AboutUsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ export default function AboutUsScreen({ navbar }: { navbar: JSX.Element }) {
<div className="max-w-screen from-AUIS-dark-teal to-AUIS-teal flex h-auto flex-col items-center bg-gradient-to-b px-5 py-5 md:px-20">
<h1 className="text-4xl font-bold text-white">Our Values</h1>
{errorValues ? (
<div className="text-white py-10">There are no values to display</div>
<div className="py-10 text-white">
There are no values to display
</div>
) : (
<div className="flex flex-wrap justify-center">
{values.map((value) => (
Expand Down
6 changes: 3 additions & 3 deletions web/src/screens/AttendanceScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default function AttendanceScreen({ navbar }: { navbar: JSX.Element }) {
if (loadingAttendanceList) {
return <LoadingSpinner />;
}

return (
<div className="from-AUIS-dark-teal to-AUIS-teal min-h-[calc(100vh)] bg-gradient-to-b">
{navbar}
Expand All @@ -159,7 +159,7 @@ export default function AttendanceScreen({ navbar }: { navbar: JSX.Element }) {
onScan={(result) => onQRcodeScanned(result)}
allowMultiple={true}
scanDelay={1000}
constraints={{deviceId: cameraId}}
constraints={{ deviceId: cameraId }}
onError={() => setCameraError(true)}
styles={{}}
/>
Expand Down Expand Up @@ -229,7 +229,7 @@ export default function AttendanceScreen({ navbar }: { navbar: JSX.Element }) {
Attendance: {totalCheckedIn} {" / "} {totalAttendees}
</p>
<div className="flex items-center justify-center">
<div className="w-[40rem] pb-10 px-3">
<div className="w-[40rem] px-3 pb-10">
<p className="text-center text-lg text-white">
Select the camera you wish to use
</p>
Expand Down
2 changes: 1 addition & 1 deletion web/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ export interface SubmitUpdateUserInfoOrNewUser {
export interface AnswerList {
questionId: number;
answer: string;
}
}

0 comments on commit 39051b2

Please sign in to comment.