
* Crypto events (#1390) * update schemas, functions & ui to allow creating and updating events with a smart contract property * remove adding sc address in the dialog that first pops-up when creating a new event, since its an advanced option * add sc to booking ui * some more ts && error handling * fetch erc20s and nfts list in event-type page * some cleanup within time limit * ts fix 1 * more ts fixes * added web3 section to integrations * added web3 wrapper, needs connection to user_settings db * extract to api * Update eventType.ts * Update components/CryptoSection.tsx Change comment from // to /** as @zomars suggested Co-authored-by: Omar López <zomars@me.com> * convert axios to fetch, change scAddress to smartContractAddress, load bloxy from next_public_env * Fix branch conflict * add enable/disable btn web3 * fixed away user causing duplicate entries * Remove web3 validation * renamed web3 button in integrations * remove unused variable * Add metadata column * added loader and showToast to the web3 btn * fix: remove smartContractAddress from info sended * send to user events when the contract is missing * use window.web3 instead of web3 * use NEXT_PUBLIC_WEB3_AUTH_MSG * remove web3 auth from .env * wip * wip * Add metamask not installed msg and success redirect * add redirect when verified * styled web3 button and added i18n to web3 * fixed redirect after verification * wip * wip * moved crypto section to ee Co-authored-by: Yuval Drori <53199044+yuvd@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@richelsen.net> Co-authored-by: Yuval Drori <yuvald29@protonmail.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Edward Fernandez <edward.fernandez@rappi.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>
200 lines
4.6 KiB
TypeScript
200 lines
4.6 KiB
TypeScript
import { Prisma } from "@prisma/client";
|
|
import { GetServerSidePropsContext } from "next";
|
|
import { JSONObject } from "superjson/dist/types";
|
|
|
|
import { asStringOrNull } from "@lib/asStringOrNull";
|
|
import { getWorkingHours } from "@lib/availability";
|
|
import prisma from "@lib/prisma";
|
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
|
|
|
import AvailabilityPage from "@components/booking/pages/AvailabilityPage";
|
|
|
|
import { ssrInit } from "@server/lib/ssr";
|
|
|
|
export type AvailabilityPageProps = inferSSRProps<typeof getServerSideProps>;
|
|
|
|
export default function Type(props: AvailabilityPageProps) {
|
|
return <AvailabilityPage {...props} />;
|
|
}
|
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
|
const ssr = await ssrInit(context);
|
|
// get query params and typecast them to string
|
|
// (would be even better to assert them instead of typecasting)
|
|
const userParam = asStringOrNull(context.query.user);
|
|
const typeParam = asStringOrNull(context.query.type);
|
|
const dateParam = asStringOrNull(context.query.date);
|
|
|
|
if (!userParam || !typeParam) {
|
|
throw new Error(`File is not named [type]/[user]`);
|
|
}
|
|
|
|
const eventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
|
id: true,
|
|
title: true,
|
|
availability: true,
|
|
description: true,
|
|
length: true,
|
|
price: true,
|
|
currency: true,
|
|
periodType: true,
|
|
periodStartDate: true,
|
|
periodEndDate: true,
|
|
periodDays: true,
|
|
periodCountCalendarDays: true,
|
|
schedulingType: true,
|
|
minimumBookingNotice: true,
|
|
timeZone: true,
|
|
metadata: true,
|
|
slotInterval: true,
|
|
users: {
|
|
select: {
|
|
avatar: true,
|
|
name: true,
|
|
username: true,
|
|
hideBranding: true,
|
|
plan: true,
|
|
timeZone: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: {
|
|
username: userParam.toLowerCase(),
|
|
},
|
|
select: {
|
|
id: true,
|
|
username: true,
|
|
name: true,
|
|
email: true,
|
|
bio: true,
|
|
avatar: true,
|
|
startTime: true,
|
|
endTime: true,
|
|
timeZone: true,
|
|
weekStart: true,
|
|
availability: true,
|
|
hideBranding: true,
|
|
brandColor: true,
|
|
theme: true,
|
|
plan: true,
|
|
eventTypes: {
|
|
where: {
|
|
AND: [
|
|
{
|
|
slug: typeParam,
|
|
},
|
|
{
|
|
teamId: null,
|
|
},
|
|
],
|
|
},
|
|
select: eventTypeSelect,
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!user) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
|
|
if (user.eventTypes.length !== 1) {
|
|
const eventTypeBackwardsCompat = await prisma.eventType.findFirst({
|
|
where: {
|
|
AND: [
|
|
{
|
|
userId: user.id,
|
|
},
|
|
{
|
|
slug: typeParam,
|
|
},
|
|
],
|
|
},
|
|
select: eventTypeSelect,
|
|
});
|
|
if (!eventTypeBackwardsCompat) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
|
|
eventTypeBackwardsCompat.users.push({
|
|
avatar: user.avatar,
|
|
name: user.name,
|
|
username: user.username,
|
|
hideBranding: user.hideBranding,
|
|
plan: user.plan,
|
|
timeZone: user.timeZone,
|
|
});
|
|
|
|
user.eventTypes.push(eventTypeBackwardsCompat);
|
|
}
|
|
|
|
const [eventType] = user.eventTypes;
|
|
|
|
// check this is the first event
|
|
|
|
// TEMPORARILY disabled because of a bug during event create - during which users were able
|
|
// to create event types >n1.
|
|
/*if (user.plan === "FREE") {
|
|
const firstEventType = await prisma.eventType.findFirst({
|
|
where: {
|
|
OR: [
|
|
{
|
|
userId: user.id,
|
|
},
|
|
{
|
|
users: {
|
|
some: {
|
|
id: user.id,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
select: {
|
|
id: true,
|
|
},
|
|
});
|
|
if (firstEventType?.id !== eventType.id) {
|
|
return {
|
|
notFound: true,
|
|
} as const;
|
|
}
|
|
}*/
|
|
|
|
const eventTypeObject = Object.assign({}, eventType, {
|
|
metadata: (eventType.metadata || {}) as JSONObject,
|
|
periodStartDate: eventType.periodStartDate?.toString() ?? null,
|
|
periodEndDate: eventType.periodEndDate?.toString() ?? null,
|
|
});
|
|
|
|
const workingHours = getWorkingHours(
|
|
{
|
|
timeZone: eventType.timeZone || user.timeZone,
|
|
},
|
|
eventType.availability.length ? eventType.availability : user.availability
|
|
);
|
|
|
|
eventTypeObject.availability = [];
|
|
|
|
return {
|
|
props: {
|
|
profile: {
|
|
name: user.name,
|
|
image: user.avatar,
|
|
slug: user.username,
|
|
theme: user.theme,
|
|
weekStart: user.weekStart,
|
|
brandColor: user.brandColor,
|
|
},
|
|
date: dateParam,
|
|
eventType: eventTypeObject,
|
|
workingHours,
|
|
trpcState: ssr.dehydrate(),
|
|
},
|
|
};
|
|
};
|