Skip to content

Commit

Permalink
feat: migrate forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagebakers committed Nov 20, 2024
1 parent 15139b6 commit f5a8bdf
Show file tree
Hide file tree
Showing 272 changed files with 3,432 additions and 17,826 deletions.
1 change: 0 additions & 1 deletion apps/palette/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@saas-ui/next-workspaces": "^0.3.0",
"@saas-ui/palette": "workspace:*",
"@saas-ui/react": "workspace:*",
"@saas-ui/theme-glass": "workspace:*",
"@svgr/webpack": "^5.5.0",
"@types/lodash.debounce": "^4.0.9",
"framer-motion": "^11.3.28",
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@
"tooling/storybook-addon"
],
"devDependencies": {
"@chakra-ui/cli": "^3.0.2",
"@chakra-ui/cli": "^3.1.2",
"@changesets/cli": "^2.27.9",
"@manypkg/get-packages": "^2.2.2",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/node": "^18.19.63",
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
"@types/node": "^18.19.64",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
"browserslist": "^4.24.2",
"cross-env": "^7.0.3",
"eslint": "^9.13.0",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-storybook": "^0.10.1",
"eslint-plugin-storybook": "^0.10.2",
"framer-motion": "^11.11.11",
"husky": "^9.1.6",
"husky": "^9.1.7",
"hygen": "^6.2.11",
"jsdom": "^25.0.1",
"lint-staged": "^15.2.10",
Expand All @@ -96,10 +96,10 @@
"ts-node": "^10.9.2",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
"turbo": "2.2.3",
"turbo": "2.3.0",
"typescript": "^5.6.3",
"vercel-submodules": "^1.0.10",
"vitest": "^2.1.4"
"vitest": "^2.1.5"
},
"resolutions": {
"unist-util-visit": "4.0.0",
Expand Down
135 changes: 61 additions & 74 deletions packages/saas-ui-auth0/src/auth0.ts
Original file line number Diff line number Diff line change
@@ -1,87 +1,74 @@
import type { AuthOptions, AuthProviderProps } from '@saas-ui/auth-provider'

import type {
Auth0Client,
RedirectLoginOptions,
User,
} from '@auth0/auth0-spa-js'
import type { AuthOptions, AuthProviderProps } from '@saas-ui/auth-provider'

export const createAuthService = <Client extends Auth0Client>(
auth0Client: Client
auth0Client: Client,
): AuthProviderProps<User> => {
const onRestoreAuthState = async () => {
if (
typeof window !== 'undefined' &&
window.location?.search?.includes('code=') &&
window.location?.search?.includes('state=')
) {
const { appState } = await auth0Client.handleRedirectCallback(
window.location.href
)
return {
onRestoreAuthState: async () => {
if (
typeof window !== 'undefined' &&
window.location?.search?.includes('code=') &&
window.location?.search?.includes('state=')
) {
const { appState } = await auth0Client.handleRedirectCallback(
window.location.href,
)

if (appState && appState.targetUrl) {
window.location?.assign(appState.targetUrl)
} else {
history.replaceState({}, document.title, window.location.pathname)
if (appState && appState.targetUrl) {
window.location?.assign(appState.targetUrl)
} else {
history.replaceState({}, document.title, window.location.pathname)
}
}
}
}

const onLogin = async (
params?: object,
options: AuthOptions<RedirectLoginOptions> = {}
) => {
const { redirectTo, ...loginOptions } = options

await auth0Client.loginWithRedirect({
...loginOptions,
authorizationParams: {
redirect_uri: redirectTo ?? window.location.href,
},
})
return null
}
},
onLogin: async (
_params?: object,
options: AuthOptions<RedirectLoginOptions> = {},
) => {
const { redirectTo, ...loginOptions } = options

const onSignup = async (
params?: object,
options: AuthOptions<RedirectLoginOptions> = {}
) => {
const { redirectTo, ...loginOptions } = options
await auth0Client.loginWithRedirect({
...loginOptions,
authorizationParams: {
redirect_uri: redirectTo ?? window.location.href,
},
})
return null
},
onSignup: async (
_params?: object,
options: AuthOptions<RedirectLoginOptions> = {},
) => {
const { redirectTo, ...loginOptions } = options

await auth0Client.loginWithRedirect({
...loginOptions,
authorizationParams: {
screen_hint: 'signup',
prompt: 'login',
redirect_uri: options?.redirectTo ?? window.location.href,
},
})
return null
}

const onLogout = async () => {
return await auth0Client.logout({
logoutParams: { returnTo: window.location.origin },
})
}

const onLoadUser = async () => {
const user = await auth0Client.getUser()
return user || null
}

const onGetToken = async () => {
return auth0Client.getTokenSilently({
timeoutInSeconds: 2,
})
}

return {
onRestoreAuthState,
onLogin,
onSignup,
onLogout,
onLoadUser,
onGetToken,
}
await auth0Client.loginWithRedirect({
...loginOptions,
authorizationParams: {
screen_hint: 'signup',
prompt: 'login',
redirect_uri: options?.redirectTo ?? window.location.href,
},
})
return null
},
onLogout: async () => {
return await auth0Client.logout({
logoutParams: { returnTo: window.location.origin },
})
},
onLoadUser: async () => {
const user = await auth0Client.getUser()
return user || null
},
onGetToken: async () => {
return auth0Client.getTokenSilently({
timeoutInSeconds: 2,
})
},
} satisfies AuthProviderProps<User>
}
6 changes: 3 additions & 3 deletions packages/saas-ui-charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@chakra-ui/styled-system": "^2.12.1",
"recharts": "^2.13.0"
"recharts": "^2.13.3"
},
"peerDependencies": {
"@chakra-ui/react": ">=2.9.0 <3",
Expand All @@ -38,8 +38,8 @@
"react-dom": ">=18"
},
"devDependencies": {
"date-fns": "^3.6.0",
"date-fns": "^4.1.0",
"prop-types": "^15.8.1",
"tsup": "^8.3.0"
"tsup": "^8.3.5"
}
}
41 changes: 21 additions & 20 deletions packages/saas-ui-charts/stories/sparkline.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import * as React from 'react'

import {
Card,
CardBody,
CardHeader,
Container,
HStack,
Heading,
SimpleGrid,
Stat,
StatHelpText,
StatLabel,
} from '@chakra-ui/react'
import { Card, Container, SimpleGrid, Stat } from '@chakra-ui/react'
import { StoryObj } from '@storybook/react'

import { Sparkline } from '../src'
Expand All @@ -31,7 +20,9 @@ export default {

type Story = StoryObj<typeof Sparkline>

const currencyFormatter = (value) => {
const currencyFormatter = (
value: number | bigint | Intl.StringNumericLiteral,
) => {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
Expand All @@ -55,7 +46,9 @@ export const Basic: Story = {
<Stat.Root>
<Stat.Label>Revenue</Stat.Label>
<Stat.ValueText>
{currencyFormatter(args.data[args.data.length - 1].value ?? 0)}
{currencyFormatter(
Number(args.data[args.data.length - 1].value ?? 0),
)}
</Stat.ValueText>
<Sparkline {...args} height="60px" mx="-4" />
</Stat.Root>
Expand All @@ -82,7 +75,9 @@ export const SolidVariant: Story = {
<Stat.Root>
<Stat.Label>Revenue</Stat.Label>
<Stat.ValueText>
{currencyFormatter(args.data[args.data.length - 1].value ?? 0)}
{currencyFormatter(
Number(args.data[args.data.length - 1].value ?? 0),
)}
</Stat.ValueText>
<Sparkline
{...args}
Expand Down Expand Up @@ -128,7 +123,9 @@ export const Multiple: Story = {
<Stat.UpIndicator /> {percentage}%
</Stat.HelpText>
<Stat.ValueText>
{currencyFormatter(args.data[args.data.length - 1].value ?? 0)}
{currencyFormatter(
Number(args.data[args.data.length - 1].value ?? 0),
)}
</Stat.ValueText>
<Sparkline {...args} height="60px" mx="-6" />
</Stat.Root>
Expand Down Expand Up @@ -164,12 +161,14 @@ export const Stacked: Story = {
<Card.Root maxW="300px" size="sm">
<Card.Body>
<Stat.Root pos="relative">
<StatLabel>Revenue</StatLabel>
<Stat.Label>Revenue</Stat.Label>
<Stat.HelpText pos="absolute" top="0" right="0">
<Stat.UpIndicator /> {percentage}%
</Stat.HelpText>
<Stat.ValueText>
{currencyFormatter(args.data[args.data.length - 1].value ?? 0)}
{currencyFormatter(
Number(args.data[args.data.length - 1].value ?? 0),
)}
</Stat.ValueText>
<Sparkline {...args} height="60px" mx="-4" />
</Stat.Root>
Expand Down Expand Up @@ -219,7 +218,7 @@ export const Metrics = () => {
<Stat.Label color="muted">Revenue</Stat.Label>
<Stat.ValueText>
{currencyFormatter(
revenueData[revenueData.length - 1].value ?? 0,
Number(revenueData[revenueData.length - 1].value ?? 0),
)}
</Stat.ValueText>
<Sparkline
Expand Down Expand Up @@ -268,7 +267,9 @@ export const Metrics = () => {
<Stat.Root>
<Stat.Label color="muted">Average customer value</Stat.Label>
<Stat.ValueText>
{currencyFormatter(valueData[valueData.length - 1].value ?? 0)}
{currencyFormatter(
Number(valueData[valueData.length - 1].value ?? 0),
)}
</Stat.ValueText>
<Sparkline
data={valueData}
Expand Down
2 changes: 1 addition & 1 deletion packages/saas-ui-clerk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"url": "https://storybook.saas-ui.dev"
},
"dependencies": {
"@clerk/types": "^4.28.0",
"@clerk/types": "^4.34.0",
"@saas-ui/auth-provider": "workspace:*"
},
"peerDependencies": {
Expand Down
Loading

0 comments on commit f5a8bdf

Please sign in to comment.