Merge branch 'main' into feature/saml-login

feature/saml-login
Deepak Prabhakara 2021-12-31 14:23:12 +00:00
commit d055873689
5 changed files with 22 additions and 14 deletions

View File

@ -97,7 +97,7 @@ function DatePicker({
return [];
}
// Create placeholder elements for empty days in first week
let weekdayOfFirst = browsingDate.startOf("month").day();
let weekdayOfFirst = browsingDate.date(1).day();
if (weekStart === "Monday") {
weekdayOfFirst -= 1;
if (weekdayOfFirst < 0) weekdayOfFirst = 6;

View File

@ -1,3 +1,4 @@
import { Prisma } from "@prisma/client";
import type { NextApiRequest, NextApiResponse } from "next";
import stripe from "@ee/lib/stripe/server";
@ -23,6 +24,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
select: {
email: true,
name: true,
metadata: true,
},
});
@ -31,26 +33,29 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
message: "User email not found",
});
/**
* TODO: We need to find a better way to get our users customer id from Stripe,
* since the email is not an unique field in Stripe and we don't save them
* in our DB as of now.
**/
const customersReponse = await stripe.customers.list({
email: user?.email || "",
limit: 1,
});
let customerId = "";
const [customer] = customersReponse.data;
if (user?.metadata && typeof user.metadata === "object" && "stripeCustomerId" in user.metadata) {
customerId = (user?.metadata as Prisma.JsonObject).stripeCustomerId as string;
} else {
/* We fallback to finding the customer by email (which is not optimal) */
const customersReponse = await stripe.customers.list({
email: user.email,
limit: 1,
});
if (customersReponse.data[0]?.id) {
customerId = customersReponse.data[0].id;
}
}
if (!customer?.id)
if (!customerId)
return res.status(404).json({
message: "Stripe customer id not found",
});
const return_url = `${process.env.BASE_URL}/settings/billing`;
const stripeSession = await stripe.billingPortal.sessions.create({
customer: customer.id,
customer: customerId,
return_url,
});

View File

@ -64,7 +64,7 @@ export default function Success(props: inferSSRProps<typeof getServerSideProps>)
const event = createEvent({
start: [
date.toDate().getUTCFullYear(),
date.toDate().getUTCMonth(),
(date.toDate().getUTCMonth() as number) + 1,
date.toDate().getUTCDate(),
date.toDate().getUTCHours(),
date.toDate().getUTCMinutes(),

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "users" ADD COLUMN "metadata" JSONB;

View File

@ -127,6 +127,7 @@ model User {
brandColor String @default("#292929")
// the location where the events will end up
destinationCalendar DestinationCalendar?
metadata Json?
@@map(name: "users")
}