-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
184 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use client'; | ||
|
||
export default function GlobalError({ | ||
error, | ||
reset, | ||
}: { | ||
error: Error & { digest?: string }; | ||
reset: () => void; | ||
}) { | ||
return ( | ||
<html> | ||
<body> | ||
<h2>{error.message}</h2> | ||
<button onClick={() => reset()}>Try again</button> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// app/getQueryClient.jsx | ||
import { QueryClient } from '@tanstack/react-query'; | ||
import { cache } from 'react'; | ||
|
||
const getQueryClient = cache(() => new QueryClient()); | ||
export default getQueryClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client'; | ||
|
||
import { GenericErrorBoundary } from '@/components/error-boundaries/GenericErrorBoundary'; | ||
|
||
export default GenericErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client'; | ||
|
||
import { GenericErrorBoundary } from '@/components/error-boundaries/GenericErrorBoundary'; | ||
|
||
export default GenericErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client'; | ||
|
||
import { GenericErrorBoundary } from '@/components/error-boundaries/GenericErrorBoundary'; | ||
|
||
export default GenericErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client'; | ||
|
||
import { GenericErrorBoundary } from '@/components/error-boundaries/GenericErrorBoundary'; | ||
|
||
export default GenericErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use client'; | ||
|
||
import { Button } from '@nextui-org/react'; | ||
|
||
export const GenericErrorBoundary = ({ | ||
error, | ||
reset, | ||
}: { | ||
error: Error & { digest?: string }; | ||
reset: () => void; | ||
}) => { | ||
return ( | ||
<div | ||
className={ | ||
'flex flex-col w-full justify-center items-center h-full gap-4' | ||
} | ||
> | ||
<h2>{error.message}</h2> | ||
<Button onClick={() => reset()}>Try again</Button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use client'; | ||
|
||
import { Button } from '@nextui-org/react'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { deleteProduct } from '@/fetch-queries/products/delete-product'; | ||
import { useSession } from 'next-auth/react'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
interface Props { | ||
id: string; | ||
} | ||
export const DeleteProduct = ({ id }: Props) => { | ||
const { data: session } = useSession(); | ||
const { mutate: mutateDelete, isPending } = useMutation({ | ||
mutationFn: deleteProduct, | ||
throwOnError: true, | ||
}); | ||
|
||
const router = useRouter(); | ||
|
||
const onHandleDelete = () => { | ||
mutateDelete( | ||
// @ts-ignore | ||
{ id, token: session?.token.id_token }, | ||
{ | ||
onSuccess: () => router.push('/products'), | ||
} | ||
); | ||
}; | ||
|
||
if (!session) return null; | ||
return ( | ||
<Button isLoading={isPending} onClick={onHandleDelete}> | ||
Delete Product | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export async function deleteProduct({ | ||
id, | ||
token, | ||
}: { | ||
id: string; | ||
token: string; | ||
}) { | ||
const response = await fetch( | ||
`${process.env.NEXT_PUBLIC_BACKEND_URL}/products/${id}`, | ||
{ | ||
method: 'DELETE', | ||
headers: { | ||
Authorization: token, | ||
}, | ||
} | ||
); | ||
|
||
if (!response.ok) { | ||
const data: { message: string } = await response.json(); | ||
console.error(data); | ||
throw new Error(data.message || 'An error occurred'); | ||
} | ||
const data = await response.json(); | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters