Skip to content
Open
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
22 changes: 22 additions & 0 deletions app/(main)/incoming-tickets/[storeId]/[ticketId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createClient } from '@/app/lib/supabase/server-client';
import { notFound } from 'next/navigation';
import TicketDetails from '@/app/(main)/components/TicketDetails';
import Breadcrumbs from '@/app/(main)/components/Breadcrumbs';

Expand All @@ -10,6 +11,27 @@ export default async function IncomingTicketDetailsPage({
const { storeId, ticketId } = await params;
const supabase = await createClient();

const {
data: { user },
} = await supabase.auth.getUser();

if (!user) {
return notFound();
}

// Check if user can manage the store
const { data: canManage, error: canManageError } = await supabase.rpc(
'can_manage_store',
{ store_to_manage_id: storeId },
);

if (canManageError || !canManage) {
if (canManageError) {
console.error('Error checking store access:', canManageError);
}
return notFound();
}

const { data: store, error: storeError } = await supabase
.from('stores')
.select('name')
Expand Down
25 changes: 25 additions & 0 deletions app/(main)/manage/[storeId]/[storeItemId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Image from 'next/image';
import { notFound } from 'next/navigation';
import Breadcrumbs from '@/app/(main)/components/Breadcrumbs';
import DeleteStoreItemButton from '@/app/(main)/manage/[storeId]/[storeItemId]/components/DeleteStoreItemButton';
import StoreItemForm from '@/app/(main)/manage/[storeId]/[storeItemId]/components/StoreItemForm';
Expand All @@ -16,6 +17,30 @@ export default async function ManageStoreItemPage({
const { storeId, storeItemId } = await params;

const supabase = await createClient();

const {
data: { user },
} = await supabase.auth.getUser();

if (!user) {
return notFound();
}

// Check if user can manage the store
const { data: canManage, error: canManageError } = await supabase.rpc(
'can_manage_store',
{ store_to_manage_id: storeId },
);

if (canManageError) {
console.error('Error checking store access:', canManageError);
return notFound();
}

if (!canManage) {
return notFound();
}

const [{ data: store }, { data: itemData, error: itemError }] =
await Promise.all([
supabase.from('stores').select('name').eq('store_id', storeId).single(),
Expand Down
20 changes: 20 additions & 0 deletions app/(main)/manage/[storeId]/add/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ export default async function AddStoreItemsPage({
const {
data: { user },
} = await supabase.auth.getUser();

if (!user) {
return notFound();
}

// Check if user can manage the store
const { data: canManage, error: canManageError } = await supabase.rpc(
'can_manage_store',
{ store_to_manage_id: storeId },
);

if (canManageError) {
console.error('Error checking store access:', canManageError);
return notFound();
}

if (!canManage) {
return notFound();
}

// extract user id
const userId = user?.id;
// fetch user's entry from users table
Expand Down
25 changes: 25 additions & 0 deletions app/(main)/manage/[storeId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createClient } from '@/app/lib/supabase/server-client';
import { notFound } from 'next/navigation';
import ItemCard from '@/app/(main)/components/ItemCard';
import ItemSearch from '@/app/(main)/components/ItemSearch';
import Link from 'next/link';
Expand All @@ -24,6 +25,30 @@ export default async function ManageStorePage({

const supabase = await createClient();

// Get the current user
const {
data: { user },
} = await supabase.auth.getUser();

if (!user) {
return notFound();
}

// Check if user can manage the store
const { data: canManage, error: canManageError } = await supabase.rpc(
'can_manage_store',
{ store_to_manage_id: storeId },
);

if (canManageError) {
console.error('Error checking store access:', canManageError);
return notFound();
}

if (!canManage) {
return notFound();
}

const { data: categories } = await supabase
.from('categories')
.select('category_id, name')
Expand Down
21 changes: 21 additions & 0 deletions app/(main)/outgoing-tickets/[ticketId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
import TicketDetails from '@/app/(main)/components/TicketDetails';
import Breadcrumbs from '@/app/(main)/components/Breadcrumbs';
import { createClient } from '@/app/lib/supabase/server-client';
import { notFound } from 'next/navigation';

export default async function OutgoingTicketDetailsPage({
params,
}: {
params: Promise<{ ticketId: string }>;
}) {
const { ticketId } = await params;
const supabase = await createClient();

const {
data: { user },
} = await supabase.auth.getUser();

if (!user) {
return notFound();
}

const { data: ticket, error } = await supabase
.from('tickets')
.select('requestor_user_id')
.eq('ticket_id', ticketId)
.single();

if (error || !ticket || ticket.requestor_user_id !== user.id) {
return notFound();
}

return (
<div>
Expand Down
Loading