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

Fix/last min fixes #84

Merged
merged 3 commits into from
Dec 13, 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
12 changes: 2 additions & 10 deletions suncityla/app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@ import { authOptions } from '@/lib/auth';
import { getServerSession } from 'next-auth';
import { redirect } from 'next/navigation';
import { getBookings } from './action';
import { cancelledBookings, pendingBookings } from './action';
import { DataTable } from '@/components/data-table/data-table';
import { columns } from '@/components/data-table/columns';

export const dynamic = 'force-dynamic';

export default async function AdminsPage () {
const bookings = await getBookings();
const totalBookings = bookings.length;
const pendingBooking = await pendingBookings();
const cancelledBooking = await cancelledBookings();
const session = await getServerSession(authOptions);
if (!session || !session.user)
{
if (!session || !session.user) {
redirect('/admin/signin');
}
return (
<div>
<h1 className="text-center font-semibold text-xl">
Welcome back <span className=" capitalize">{session.user.username}</span>
Welcome back <span className=" capitalize">{session.user.username ? session.user.username : session.user.name}</span>
</h1>
<p>Number of Bookings: {totalBookings}</p>
<p>Pending Bookings: {pendingBooking.length}</p>
<p>Cancelled Bookings: {cancelledBooking.length}</p>
<DataTable columns={columns} data={bookings} />
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions suncityla/app/booking/new/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import BookingForm from '../components/BookingForm/BookingForm';

export default function NewBooking() {
export default function NewBooking () {
return (
<div>
<h1>New Booking</h1>
<div className='flex flex-col items-center justify-center'>
<h1 className=' font-bold mb-4'>New Booking</h1>
<BookingForm />
</div>
);
Expand Down
11 changes: 9 additions & 2 deletions suncityla/app/booking/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import FindBookingForm from './components/BookingForm/FindBookingForm';

export default function Page() {
return <FindBookingForm />;
export default function Page () {
return (
<div className='flex flex-col items-center justify-center'>
<div>
<h1 className=' font-bold mb-4'>Please enter your booking reference</h1>
</div>
<FindBookingForm />;
</div>
)
}
6 changes: 3 additions & 3 deletions suncityla/components/NavbarToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ export default function NavbarToggle ({ session }: { session: Session | null })
<Link href="/" className="hover:text-[#7F95D1]">
Home
</Link>
<Link href="/about" className="hover:text-[#7F95D1]">
About
<Link href="/booking/new" className="hover:text-[#7F95D1]">
New Request
</Link>
<Link href="/booking" className="hover:text-[#7F95D1]">
Booking
Verify Booking
</Link>
<Link href="/admin/signin">
<Button className="font-bold">Admin Login</Button>
Expand Down
2 changes: 1 addition & 1 deletion suncityla/components/data-table/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const columns: ColumnDef<BookingTableProps>[] = [
</button>
)
},
cell: ({ getValue }) => <span>{new Date(getValue() as string).toDateString()}</span>,
cell: ({ getValue }) => <span>{new Date(getValue() as string).toDateString()} {new Date(getValue() as string).toLocaleTimeString()}</span>,
},
{
accessorKey: "streetAddress",
Expand Down
18 changes: 10 additions & 8 deletions suncityla/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export const authOptions: NextAuthOptions = {
password: { label: "Password", type: "password" },
},
async authorize (credentials) {
if (!credentials?.username || !credentials?.password)
{
if (!credentials?.username || !credentials?.password) {
return null;
}

Expand All @@ -38,20 +37,17 @@ export const authOptions: NextAuthOptions = {
},
});

if (!existingAdmin)
{
if (!existingAdmin) {
return null;
}
console.log(credentials.password, existingAdmin.password);

if (existingAdmin.password)
{
if (existingAdmin.password) {
const passwordMatch = await compare(
credentials.password,
existingAdmin.password
);
if (!passwordMatch)
{
if (!passwordMatch) {
return null;
}
}
Expand All @@ -62,4 +58,10 @@ export const authOptions: NextAuthOptions = {
},
}),
],
callbacks: {
async jwt ({ token, user }) {
if (user && user.username) token.username = user.username;
return token;
},
},
};
Loading