-
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
1 parent
22d39c9
commit 4007b85
Showing
16 changed files
with
418 additions
and
222 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
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,50 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
import getCurrentUser from "@/app/actions/getCurrentUser"; | ||
import prisma from "@/app/libs/prismadb"; | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const currentUser = await getCurrentUser(); | ||
|
||
if (!currentUser) { | ||
return new Response('User not found', { status: 404 }); | ||
} | ||
|
||
const body = await request.json(); | ||
const { registrationId } = body; | ||
console.log(registrationId) | ||
|
||
|
||
if (isNaN(registrationId)) { | ||
return new Response('Invalid Registration ID', { status: 400 }); | ||
} | ||
const registration = await prisma.registration.findUnique({ | ||
where: { | ||
id: registrationId, | ||
}, | ||
}); | ||
|
||
if (!registration) { | ||
return new Response('Registration not found', { status: 404 }); | ||
} | ||
await prisma.registration.update({ | ||
where: { | ||
id: registrationId, | ||
}, | ||
data: { | ||
hasPaid: !registration.hasPaid, // Toggle the hasPaid status | ||
}, | ||
}); | ||
|
||
|
||
return new Response('Registration payment status updated successfully', { status: 200 }); | ||
|
||
} catch (error) { | ||
if (error instanceof Error) { | ||
return new Response(error.message, { status: 500 }); | ||
} else { | ||
return new Response('An unknown error occurred', { status: 500 }); | ||
} | ||
} | ||
} |
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
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,48 @@ | ||
"use client" | ||
|
||
import { SafeEvent, SafeRegistration } from "@/app/types"; | ||
import axios from "axios"; | ||
import { useState } from "react"; | ||
import toast from "react-hot-toast"; | ||
|
||
interface ToggleProps{ | ||
registration?: SafeRegistration; | ||
} | ||
|
||
const Toggle: React.FC<ToggleProps> = ({ | ||
registration | ||
}) => { | ||
const [paidStatus, setPaidStatus] = useState(registration?.hasPaid); | ||
|
||
const handlePaymentStatusChange = () => { | ||
axios.post('/api/payment', { registrationId: registration?.id }) | ||
.then(response => { | ||
console.log(response.data); | ||
}) | ||
.catch(error => { | ||
console.error('Error updating payment status:', error); | ||
}); | ||
}; | ||
|
||
const handleChange = () => { | ||
const newPaidStatus = !paidStatus; | ||
setPaidStatus(newPaidStatus); | ||
|
||
if (registration?.id) { | ||
handlePaymentStatusChange(); | ||
} | ||
}; | ||
return ( | ||
<div> | ||
<select | ||
value= {paidStatus?.toString()} | ||
onChange={handleChange} | ||
> | ||
<option value={true.toString()}>Paid</option> | ||
<option value={false.toString()}>Not paid</option> | ||
</select> | ||
</div> | ||
); | ||
} | ||
|
||
export default Toggle; |
Oops, something went wrong.