feat: atoms as npm package (#14160)

* fix: getEnv not returning fallback API_URL breaking examples app

* refactor: use vite as the only way to build atoms

* refactor: web use atoms from web.ts and rest from dist

* refactor: update atoms version, description and set privacy to public

* fix: lib and ui import from web atoms

* refactor: rename @calcom/platform-atoms to @calcom/atoms

* feat: atoms as npm works with example app outside monorepo

* start atoms from v1.0.0

* refactor: monorepo atoms for internal use

* document atoms publishing

* refactor: remove unused import in v2

* fix: mistakes made during main merge

* refactor: move back examples app while still having it in atoms-examples repo

* refactor: monorepo examples readme

* feat: atoms yarn publish command

* refactor: atoms css file simplify

* fix: mocking atoms in ui unit test

* fix: mocking atoms in app-store unit test
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2024-03-21 14:33:10 -03:00
1 parent 61a8543e08
commit 74e5f4bf37
34 files changed
+234 -183

No files matched your search

+1 -1
View File
@@ -1 +1 @@
Contains the platform atoms
Atoms - customizable UI components to integrate scheduling into products.
-32
View File
@@ -1,32 +0,0 @@
import path from "path";
import { fileURLToPath } from "url";
import { build } from "vite";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// @TODO: Do we want to automate this by checking all dirs for export.ts?
const libraries = [
{
entry: path.resolve(__dirname, "./booker/export.ts"),
fileName: "booker",
},
];
const promises = libraries.map(async (lib) => {
await build({
build: {
outDir: `./dist/${lib.fileName}`,
lib: {
...lib,
formats: ["es", "cjs"],
},
emptyOutDir: false,
},
resolve: {
alias: {
crypto: require.resolve("rollup-plugin-node-builtins"),
},
},
});
});
await Promise.all(promises);
-6
View File
@@ -1,6 +0,0 @@
export { CalProvider } from "./cal-provider";
export { GcalConnect } from "./gcal-connect";
export { PlatformAvailabilitySettingsWrapper as AvailabilitySettings } from "./availability";
export { BookerPlatformWrapper as Booker } from "./booker";
export { useIsPlatform } from "./hooks/useIsPlatform";
export { useAtomsContext } from "./hooks/useAtomsContext";
@@ -1,4 +1,3 @@
import { cn } from "@/lib/utils";
import type { FC } from "react";
import { Button } from "@calcom/ui";
@@ -6,6 +5,7 @@ import { CalendarDays } from "@calcom/ui/components/icon";
import { useAtomsContext } from "../hooks/useAtomsContext";
import { useGcal } from "../hooks/useGcal";
import { cn } from "../src/lib/utils";
interface GcalConnectProps {
className?: string;
@@ -1,4 +1,4 @@
import { useAtomsContext } from "@calcom/platform-atoms";
import { useAtomsContext } from "./useAtomsContext";
export const useIsPlatform = () => {
const context = useAtomsContext();
+4 -6
View File
@@ -1,8 +1,6 @@
export { BookerWebWrapper as Booker } from "./booker";
export { WebAvailabilitySettingsWrapper as AvailabilitySettings } from "./availability/wrappers/WebAvailabilitySettingsWrapper";
export { CalProvider } from "./cal-provider/CalProvider";
export { CalProvider } from "./cal-provider";
export { GcalConnect } from "./gcal-connect";
export { PlatformAvailabilitySettingsWrapper as AvailabilitySettings } from "./availability";
export { BookerPlatformWrapper as Booker } from "./booker";
export { useIsPlatform } from "./hooks/useIsPlatform";
export { useAtomsContext } from "./hooks/useAtomsContext";
export { useHandleBookEvent } from "./hooks/useHandleBookEvent";
export * as Dialog from "./src/components/ui/dialog";
export { Timezone } from "./timezone";
+8
View File
@@ -0,0 +1,8 @@
export { BookerWebWrapper as Booker } from "./booker";
export { WebAvailabilitySettingsWrapper as AvailabilitySettings } from "./availability/wrappers/WebAvailabilitySettingsWrapper";
export { CalProvider } from "./cal-provider/CalProvider";
export { useIsPlatform } from "./hooks/useIsPlatform";
export { useAtomsContext } from "./hooks/useAtomsContext";
export { useHandleBookEvent } from "./hooks/useHandleBookEvent";
export * as Dialog from "./src/components/ui/dialog";
export { Timezone } from "./timezone";
+17 -18
View File
@@ -1,15 +1,14 @@
{
"name": "@calcom/platform-atoms",
"private": true,
"name": "@calcom/atoms",
"sideEffects": false,
"type": "module",
"description": "Cal.com Atoms",
"description": "Customizable UI components to integrate scheduling into your product.",
"authors": "Cal.com, Inc.",
"version": "0.0.0",
"version": "1.0.5",
"scripts": {
"build": "node build.mjs",
"vite-dev": "yarn vite build --watch & npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify --watch",
"vite-build": "yarn vite build && npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify"
"dev": "yarn vite build --watch & npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify --watch",
"build": "yarn vite build && npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify",
"publish": "rm -rf dist && yarn build && npm publish --access public"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.1",
@@ -23,25 +22,25 @@
"vite-plugin-dts": "^3.7.3"
},
"files": [
"dist"
"dist",
"globals.min.css"
],
"main": "index.ts",
"module": "index.ts",
"main": "./dist/cal-atoms.umd.cjs",
"module": "./dist/cal-atoms.js",
"exports": {
".": {
"import": "./index.ts",
"require": "./index.ts"
"require": "./dist/cal-atoms.umd.cjs",
"import": "./dist/cal-atoms.js"
},
"./components": {
"import": "./dist/cal-atoms.js",
"require": "./dist/cal-atoms.umd.cjs"
"./monorepo": {
"import": "./monorepo.ts",
"require": "./monorepo.ts"
},
"./dist/globals.min.css": "./globals.min.css",
"./globals.min.css": "./globals.min.css",
"./dist/index.ts": "./index.ts"
},
"types": "./dist/index.d.ts",
"dependencies": {
"@calcom/platform-constants": "*",
"@calcom/ui": "*",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.5",
+1 -1
View File
@@ -8,7 +8,7 @@ export default defineConfig({
plugins: [react(), dts()],
build: {
lib: {
entry: [resolve(__dirname, "components.ts")],
entry: [resolve(__dirname, "index.ts")],
name: "CalAtoms",
fileName: "cal-atoms",
},
@@ -0,0 +1,3 @@
NEXT_PUBLIC_X_CAL_ID=""
X_CAL_SECRET_KEY=""
NEXT_PUBLIC_CALCOM_API_URL="http://localhost:5555/api/v2"
+28 -33
View File
@@ -1,40 +1,35 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# Atoms examples
Example apps using atoms - customizable UI components to integrate scheduling into your product.
## Getting Started
## Running examples apps locally
First, run the development server:
1. Cal's backend is required to run example apps, so clone `https://github.com/calcom/cal.com` and follow setup instructions in the readme. Importantly, you need to have Google credentials setup by following [this section](https://github.com/calcom/cal.com?tab=readme-ov-file#obtaining-the-google-api-credentials) in the docs.
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
2. Open "apps/api/v2/.env" and copy environment variables below, and then copy `NEXTAUTH_SECRET` from the root ".env" of repository cloned in step 1.
```jsx
NODE_ENV="development"
API_PORT=5555
DATABASE_READ_URL="postgresql://postgres:@localhost:5450/calendso"
DATABASE_WRITE_URL="postgresql://postgres:@localhost:5450/calendso"
API_URL="http://localhost"
NEXTAUTH_SECRET="copy from .env of root of repository cloned in step 1"
DATABASE_URL="postgresql://postgres:@localhost:5450/calendso"
JWT_SECRET="asjdijI1JIO12I3O89198jojioSAJDU"
REDIS_URL="redis://localhost:6379"
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
3. Start "apps/api/v2" api using `yarn dev`.
4. Start "packages/platform/atoms" atoms package with `yarn dev`.
5. Start "apps/web" cal web app using `yarn dx`.
6. Open your browser at "http://localhost:3000/" and login with admin username `[email protected]` and password `ADMINadmin2022!`.
7. In the web app navigate to `http://localhost:3000/settings/organizations/new` and create a sample organization. When asked for phone verification code enter `111111`.
8. In the web app navigate to `http://localhost:3000/settings/organizations/platform/oauth-clients` and create a new oAuth client - give all permissions and set redirect uri to `http://localhost:4321` which points to example app.
9. Setup environment for the example app you want to run:
1. First, copy ".env.example" into ".env".
2. Open ".env" file and paste client id from step 8 in `NEXT_PUBLIC_X_CAL_ID` and client secret in `X_CAL_SECRET_KEY`. If in step 2 you used the same environment variables, then `NEXT_PUBLIC_CALCOM_API_URL` can stay as is. Otherwise adjust the port to point to the same `API_PORT` as you used in step 2.
10. Navigate to example app and setup database by running `rm -f prisma/dev.db && yarn prisma db push`.
11. Start the example app by running `yarn dev` and go to `http://localhost:4321`.
12. In the Google Cloud Console "API & Services" "Credentials" `https://console.cloud.google.com/apis/credentials` open web project setup in step 1 and add `http://localhost:5555/api/v2/platform/gcal/oauth/save` to the authorized redirect URIs.
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
<img width="1000" alt="Screenshot 2024-03-21 at 09 42 36" src="https://github.com/calcom/atoms-examples/assets/42170848/82ce4d7a-fc08-489a-ab06-a8eb41a68a2a">
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
+1 -1
View File
@@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@calcom/platform-atoms": "*",
"@calcom/atoms": "*",
"@prisma/client": "5.4.2",
"next": "14.0.4",
"prisma": "^5.7.1",
@@ -3,8 +3,8 @@ import type { AppProps } from "next/app";
import { Poppins } from "next/font/google";
import { useEffect, useState } from "react";
import { CalProvider } from "@calcom/platform-atoms/components";
import "@calcom/platform-atoms/dist/globals.min.css";
import { CalProvider } from "@calcom/atoms";
import "@calcom/atoms/globals.min.css";
const poppins = Poppins({ subsets: ["latin"], weight: ["400", "800"] });
@@ -1,7 +1,7 @@
import { Navbar } from "@/components/Navbar";
import { Inter } from "next/font/google";
import { AvailabilitySettings } from "@calcom/platform-atoms/components";
import { AvailabilitySettings } from "@calcom/atoms";
const inter = Inter({ subsets: ["latin"] });
@@ -28,7 +28,6 @@ export default function Availability(props: { calUsername: string; calEmail: str
onDeleteSuccess={() => {
console.log("Deleted successfully");
}}
translations={{ timezone: "Select your timezone" }}
/>
</div>
</main>
@@ -2,7 +2,7 @@ import { Navbar } from "@/components/Navbar";
import { Inter } from "next/font/google";
import { useState } from "react";
import { Booker } from "@calcom/platform-atoms/components";
import { Booker } from "@calcom/atoms";
const inter = Inter({ subsets: ["latin"] });
@@ -1,7 +1,7 @@
import { Navbar } from "@/components/Navbar";
import { Inter, Poppins } from "next/font/google";
import { GcalConnect } from "@calcom/platform-atoms/components";
import { GcalConnect } from "@calcom/atoms";
const inter = Inter({ subsets: ["latin"] });
const poppins = Poppins({ subsets: ["latin"], weight: ["400", "800"] });
@@ -15,7 +15,8 @@
"incremental": true,
"paths": {
"@/*": ["./src/*"]
}
},
"forceConsistentCasingInFileNames": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]