Skip to content

Commit

Permalink
allowed admin to change emails in form
Browse files Browse the repository at this point in the history
  • Loading branch information
joywin2003 committed Dec 11, 2024
1 parent a56ba4c commit 047bee6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
13 changes: 10 additions & 3 deletions src/app/api/verify-order/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ export async function POST(request: NextRequest) {
if (!session) {
return NextResponse.json({ message: "No session", isOk: false }, { status: 400 });
}
const { orderId, razorpayPaymentId, razorpaySignature, amount } = await request.json();
const { email, orderId, razorpayPaymentId, razorpaySignature, amount } = await request.json();
if (!email || !orderId || !razorpayPaymentId || !razorpaySignature || !amount) {
return NextResponse.json({ message: "Invalid data", isOk: false }, { status : 400 });
}
const userEmail = session.user?.role === "ADMIN" || session.user?.email !== email
? email
: session.user?.email!;


const signature = generatedSignature(orderId, razorpayPaymentId);
if (signature !== razorpaySignature) {
Expand All @@ -18,13 +25,13 @@ export async function POST(request: NextRequest) {
if (signature === razorpaySignature) {
const user = await prisma.user.findUnique({
where: {
email: session.user?.email!,
email: userEmail,
},
});

try {
await sendRegistrationEmail({
email: session.user?.email!,
email: userEmail,
name: session.user?.name!,
registrationLink: `${process.env.NEXT_PUBLIC_SITE_URL}/admin/verify/${razorpayPaymentId}`,
});
Expand Down
13 changes: 7 additions & 6 deletions src/components/common/registration-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export default function RegistrationForm() {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: form.getValues("email"),
orderId: response.razorpay_order_id,
razorpayPaymentId: response.razorpay_payment_id,
razorpaySignature: response.razorpay_signature,
Expand Down Expand Up @@ -218,7 +219,7 @@ export default function RegistrationForm() {
},
notes: {
name: form.getValues("name"),
email: session?.user?.email,
email: form.getValues("email"),
contact: form.getValues("phone"),
designation: form.getValues("designation"),
foodPreference: form.getValues("foodPreference"),
Expand All @@ -233,7 +234,7 @@ export default function RegistrationForm() {
},
prefill: {
name: form.getValues("name"),
email: session?.user?.email,
email: form.getValues("email"),
contact: form.getValues("phone"),
},
theme: {
Expand Down Expand Up @@ -299,7 +300,7 @@ export default function RegistrationForm() {
const handleNext = async () => {
let isValid = false;
if (step === 1) {
isValid = await form.trigger(["designation", "foodPreference", "name"]);
isValid = await form.trigger(["designation", "foodPreference", "name", "email"]);
} else if (step === 2) {
const designation = form.getValues("designation");
if (designation === "student") {
Expand Down Expand Up @@ -380,10 +381,10 @@ export default function RegistrationForm() {
<div className="flex items-center space-x-2">
<FormControl>
<Input
placeholder="[email protected]"
placeholder=""
{...field}
disabled
value={session?.user.email!}
disabled={!(session?.user.role === "ADMIN")}
className="cursor-not-allowed"
/>
</FormControl>
<Button
Expand Down

0 comments on commit 047bee6

Please sign in to comment.