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

Feat/same device #13

Merged
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
512 changes: 72 additions & 440 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@mui/material-nextjs": "^6.1.0",
"@mui/x-date-pickers": "^6.20.2",
"@prisma/client": "^5.19.1",
"@tailwindcss/forms": "^0.5.9",
"cbor-x": "^1.6.0",
"dayjs": "^1.11.13",
"jks-js": "^1.1.3",
Expand Down Expand Up @@ -51,7 +50,6 @@
"eslint-config-next": "14.2.5",
"postcss": "^8.4.45",
"prisma": "^5.19.1",
"tailwindcss": "^3.4.11",
"typescript": "^5"
}
}
3 changes: 1 addition & 2 deletions postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
plugins: {
autoprefixer: {},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/atoms/CopyIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const CopyIcon: React.FC<IconProps> = ({ className, ...props }) => {
className={className}
viewBox="0 0 24 24"
sx={{
fontSize: 24, // Default size equivalent to "size-6" in Tailwind
fontSize: 24,
...(props.sx || {}), // Allow custom sx prop to override styles
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/atoms/HeartIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const HeartIcon: React.FC<IconProps> = ({ className, ...props }) => {
className={className}
viewBox="0 0 24 24"
sx={{
fontSize: 24, // Default size (equivalent to Tailwind size-6)
fontSize: 24,
...(props.sx || {}), // Allow custom `sx` prop to override styles
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/atoms/PinIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const PinIcon: React.FC<IconProps> = ({ className, ...props }) => {
className={className}
viewBox="0 0 24 24"
sx={{
fontSize: 24, // Default size equivalent to "w-6 h-6" in Tailwind
fontSize: 24,
...(props.sx || {}), // Allow additional sx styles from props
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/atoms/PlusIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const PlusIcon: React.FC<IconProps> = ({ className, ...props }) => {
className={className}
viewBox="0 0 24 24"
sx={{
fontSize: 24, // Default size equivalent to Tailwind's "size-6"
fontSize: 24,
...(props.sx || {}), // Allow custom sx prop to override styles
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/atoms/ShareIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const ShareIcon: React.FC<IconProps> = ({ className, ...props }) => {
className={className}
viewBox="0 0 24 24"
sx={{
fontSize: 24, // Default size equivalent to "size-6" in Tailwind
fontSize: 24,
...(props.sx || {}), // Allow custom sx prop to override styles
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/atoms/StarIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const StarIcon: React.FC<IconProps> = ({ className, ...props }) => {
className={className}
viewBox="0 0 24 24"
sx={{
fontSize: 24, // Default size equivalent to "size-6" in Tailwind
fontSize: 24,
...(props.sx || {}), // Allow custom sx prop to override styles
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/atoms/TagIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const TagIcon: React.FC<IconProps> = ({ className, ...props }) => {
className={className}
viewBox="0 0 24 24"
sx={{
fontSize: 24, // Default size equivalent to "size-6" in Tailwind
fontSize: 24,
...(props.sx || {}), // Allow custom sx prop to override styles
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/atoms/ThumbUpIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const ThumbUpIcon: React.FC<IconProps> = ({ className, ...props }) => {
className={className}
viewBox="0 0 24 24"
sx={{
fontSize: 24, // Default size equivalent to Tailwind's "size-6"
fontSize: 24,
...(props.sx || {}), // Allow custom sx prop to override styles
}}
>
Expand Down
22 changes: 18 additions & 4 deletions src/client/components/organisms/BookingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { useForm, FormProvider } from "react-hook-form";
import { BookingGuestInfo } from "../molecules/BookingGuestInfo";
import HotelDescription from "../molecules/HotelDescription";
import { useBookingStore } from "@/client/store/bookingStore";
import { useAppStore } from "@/client/store";
import { ModalStatus, useAppStore } from "@/client/store";
import { zodResolver } from "@hookform/resolvers/zod";
import { bookingDtoSchema } from "@/server/schemas/booking";
import { BookingDto, Hotel } from "@/shared";
import Image from "next/image";
import { LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import router from "next/router";
import { useEffect } from "react";

export const BookingForm: React.FC = () => {
const methods = useForm<BookingDto>({
Expand All @@ -19,14 +21,26 @@ export const BookingForm: React.FC = () => {
location: Hotel.location,
},
});
const { isLoading, createBookingAsync } = useBookingStore();
const { changeModalStatus, modal } = useAppStore(); // Get modal state
const { isLoading, createBookingAsync, bookingCreateRes } = useBookingStore();
const deviceType = useAppStore((state) => state.deviceType);

const onSubmit = async (data: BookingDto) => {
console.log(data);
SmirlakisParis marked this conversation as resolved.
Show resolved Hide resolved
await createBookingAsync(data);
};

// Watch for changes in bookingCreateRes
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified as:

useEffect(() => {
  if (bookingCreateRes?.url) {
    deviceType === 'desktop' ? changeModalStatus(ModalStatus.OPEN) : (window.location.href = bookingCreateRes.url);
  }
}, [bookingCreateRes?.url, deviceType, changeModalStatus]);

if (bookingCreateRes?.url) {
if (deviceType === 'desktop') {
changeModalStatus(ModalStatus.OPEN);
} else {
window.location.href = bookingCreateRes?.url; // Navigate to the confirmation page
}
}
}, [bookingCreateRes?.url, deviceType, changeModalStatus]);

return (
<LocalizationProvider dateAdapter={AdapterDayjs}>

Expand Down Expand Up @@ -70,8 +84,8 @@ export const BookingForm: React.FC = () => {
}}
>
{deviceType === "mobile" ? (
<Button variant="contained" color="primary" sx={{ display: "flex", flexDirection: "column", alignItems: "center", p: 2 }}>
<Typography>Book using EUDI Wallet</Typography>
<Button variant="contained" color="primary" type="submit" sx={{ display: "flex", flexDirection: "column", alignItems: "center", p: 2 }}>
<Typography sx={{ color: "white" }} >Book using EUDI Wallet</Typography>
<Image loading="lazy" src="/images/eudiwallet.svg" alt="EUDI Wallet" width={48} height={48} />
</Button>
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/organisms/ConfirmationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const ConfirmationDetails = ({
reservationDate,
} = details;
const { isLoading, issueConfirmationAsync } = useBookingStore();

console.log(id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot this console.log?

return (
<Box sx={{
width:'100%',
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/organisms/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Header: React.FC = () => {
alt="Travel destination"
sx={{
width: '100%',
aspectRatio: '12.5', // Aspect ratio like the one in Tailwind
aspectRatio: '12.5',
maxWidth: '100%',
}}
/>
Expand Down
9 changes: 5 additions & 4 deletions src/client/hooks/useBookingVerify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ export const useBookingVerify = () => {
const { data, error } = useSWR(
bookingId,
fetcher,
{ refreshInterval: polling ? 1000 : 0 } // Poll every second if polling is true
{ refreshInterval: polling ? 3000 : 0 } // Poll every second if polling is true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be an env var

);

// Function to stop polling manually
const stopPolling = useCallback(() => {
changeModalStatus(ModalStatus.CLOSE);
setPolling(false); // Stop polling
resetBooking(); // Reset booking data
changeModalStatus(ModalStatus.CLOSE); // Close modal
// Close modal
}, [changeModalStatus, resetBooking]);

// Handle polling logic and state changes
Expand All @@ -55,14 +56,14 @@ export const useBookingVerify = () => {

if (data?.status && bookingId) {
setStatus(true); // Mark the status as verified
stopPolling(); // Stop polling after success
stopPolling();
router.push(PATHS.confirmation(bookingId)); // Navigate to confirmation page
}

// Timeout logic to stop polling after 30 seconds
const timeout = setTimeout(() => {
stopPolling(); // Stop polling after 30 seconds
}, 30000);
}, 60000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be an env var


return () => {
clearTimeout(timeout); // Clear timeout on unmount
Expand Down
1 change: 0 additions & 1 deletion src/client/store/bookingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const useBookingStore = create<IBookingStore>()((set) => ({
);
set({ isLoading: false, bookingCreateRes: res });

useAppStore.getState().changeModalStatus(ModalStatus.OPEN);
} catch (err) {
let errorMessage = "Unknown error occurred";
if (err instanceof Error) {
Expand Down
18 changes: 10 additions & 8 deletions src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ const server = z.object({
* built with invalid env vars. To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/
const client = z.object({
NEXT_PUBLIC_APP_NAME: z.string().optional(),
NEXT_PUBLIC_APP_URL: z.string().optional(),
VERIFIER_API_URL: z.string().optional(),
ISSUER_API_URL: z.string().optional(),
KEYSTORE_FILE: z.string().optional(),
KEYSTORE_PASS: z.string().optional(),
KEYSTORE_ALIAS: z.string().optional(),
POSTGRES_CONNECTION_STRING: z.string(),
NEXT_PUBLIC_APP_NAME: z.string(),
NEXT_PUBLIC_APP_URI: z.string(),
VERIFIER_API_URL: z.string(),
ISSUER_API_URL: z.string(),
KEYSTORE_FILE: z.string(),
KEYSTORE_PASS: z.string(),
KEYSTORE_ALIAS: z.string(),
});

/**
Expand All @@ -29,8 +30,9 @@ const client = z.object({
* @type {Record<keyof z.infer<typeof server> | keyof z.infer<typeof client>, string | undefined>}
*/
const processEnv = {
POSTGRES_CONNECTION_STRING: process.env.GRAPHQL_SERVER_URI,
POSTGRES_CONNECTION_STRING: process.env.POSTGRES_CONNECTION_STRING,
NEXT_PUBLIC_APP_NAME: process.env.NEXT_PUBLIC_APP_NAME,
NEXT_PUBLIC_APP_URI: process.env.NEXT_PUBLIC_APP_URI,
VERIFIER_API_URL: process.env.VERIFIER_API_URL,
ISSUER_API_URL: process.env.ISSUER_API_URL,
KEYSTORE_FILE: process.env.KEYSTORE_FILE,
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/deviceDetect.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GetServerSidePropsContext } from "next/types";
import DeviceDetector from "node-device-detector";
const deviceDetector = new DeviceDetector();

Expand All @@ -7,3 +8,9 @@ export function deviceDetect(userAgent: string = "") {

return deviceType;
}


export const getDeviceTypeProps = (context: GetServerSidePropsContext) => {
const deviceType = deviceDetect(context.req.headers['user-agent'] ?? '');
return { props: { deviceType } };
};
40 changes: 40 additions & 0 deletions src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Box, Typography, Button } from '@mui/material';
import { useRouter } from 'next/router';
import React from 'react';

const Custom404 = () => {
const router = useRouter();

const handleBackToHome = () => {
router.push('/'); // Redirect to the homepage
};

return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100vh',
textAlign: 'center',
p: 3,
}}
>
<Typography variant="h1" sx={{ fontWeight: 'bold', mb: 2 }}>
404
</Typography>
<Typography variant="h4" sx={{ mb: 4 }}>
Page Not Found
</Typography>
<Typography variant="body1" sx={{ mb: 4 }}>
The page you are looking for does not exist.
</Typography>
<Button variant="contained" color="primary" onClick={handleBackToHome}>
Back to Home
</Button>
</Box>
);
};

export default Custom404;
2 changes: 1 addition & 1 deletion src/pages/api/booking/verification/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default async function handler(

// Fetch the booking verification status from the service
const bookingVerificationStatus =
await bookingService.bookingVerificationStatus(id);
await bookingService.bookingVerificationStatus({bookingID:id});

// Handle cases where no status is returned (assuming this might happen)
if (
Expand Down
Loading
Loading