Skip to content

Commit

Permalink
Merge branch 'dev' into renovate/all-minor-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow authored May 2, 2024
2 parents ad48352 + 5e81329 commit 05f1fb9
Show file tree
Hide file tree
Showing 42 changed files with 1,330 additions and 1,014 deletions.
4 changes: 2 additions & 2 deletions apps/app/sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
} from '@sentry/integrations'
import * as Sentry from '@sentry/nextjs'

const isVercelProd = process.env.VERCEL_ENV === 'production'
const isVercel = process.env.VERCEL === '1'
Sentry.init({
dsn: 'https://[email protected]/6751163',
enabled: isVercelProd,
enabled: isVercel,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: !!process.env.SENTRY_DEBUG,
Expand Down
4 changes: 2 additions & 2 deletions apps/app/sentry.edge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import * as Sentry from '@sentry/nextjs'

const isVercelProd = process.env.VERCEL_ENV === 'production'
const isVercel = process.env.VERCEL === '1'

Sentry.init({
dsn: 'https://[email protected]/6751163',
enabled: isVercelProd,
enabled: isVercel,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 0.5,

Expand Down
4 changes: 2 additions & 2 deletions apps/app/sentry.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { nodeProfilingIntegration } from '@sentry/profiling-node'

import { prisma } from '@weareinreach/db'

const isVercelProd = process.env.VERCEL_ENV === 'production'
const isVercel = process.env.VERCEL === '1'

Sentry.init({
dsn: 'https://[email protected]/6751163',
enabled: isVercelProd,
enabled: isVercel,
debug: !!process.env.SENTRY_DEBUG,
// Tracing rates
tracesSampleRate: 0.5,
Expand Down
5 changes: 1 addition & 4 deletions apps/app/src/pages/org/[slug]/[orgLocationId]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ const OrgLocationPage: NextPage<InferGetServerSidePropsType<typeof getServerSide
const [loading, setLoading] = useState(true)
const notifySave = useNewNotification({ displayText: 'Saved', icon: 'success' })
const { data, status } = api.location.forLocationPageEdits.useQuery({ id: orgLocationId })
const { data: isSaved } = api.savedList.isSaved.useQuery(data?.organization?.id ?? '', {
enabled: status === 'success' && Boolean(data?.organization?.id),
})

const { data: alertData } = api.location.getAlerts.useQuery(
{ id: orgLocationId },
{ enabled: router.isReady }
Expand Down Expand Up @@ -171,7 +169,6 @@ const OrgLocationPage: NextPage<InferGetServerSidePropsType<typeof getServerSide
},
}}
organizationId={data.organization.id}
saved={Boolean(isSaved)}
/>
<Stack pt={24} align='flex-start' spacing={40}>
{hasAlerts &&
Expand Down
5 changes: 1 addition & 4 deletions apps/app/src/pages/org/[slug]/[orgLocationId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ const OrgLocationPage: NextPage = () => {
{ id: orgLocationId },
{ enabled: router.isReady }
)
const { data: isSaved } = api.savedList.isSaved.useQuery(orgData?.id as string, {
enabled: orgDataStatus === 'success' && Boolean(orgData?.id),
})

const { data: alertData } = api.location.getAlerts.useQuery(
{ id: orgLocationId },
{ enabled: router.isReady }
Expand Down Expand Up @@ -110,7 +108,6 @@ const OrgLocationPage: NextPage = () => {
},
}}
organizationId={orgData.id}
saved={Boolean(isSaved)}
/>
<Stack pt={24} align='flex-start' spacing={40}>
{hasAlerts &&
Expand Down
3 changes: 1 addition & 2 deletions apps/app/src/pages/org/[slug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const OrganizationPage = ({
return <OrgPageLoading />
}

const { userLists, attributes, description, reviews, locations, isClaimed, id: organizationId } = data
const { attributes, description, reviews, locations, isClaimed, id: organizationId } = data

const body =
locations?.length <= 1 ? (
Expand Down Expand Up @@ -185,7 +185,6 @@ const OrganizationPage = ({
option: 'back',
backTo: 'search',
}}
saved={Boolean(userLists?.length)}
organizationId={organizationId}
/>
<Stack pt={24} align='flex-start' spacing={40}>
Expand Down
8 changes: 1 addition & 7 deletions packages/api/router/organization/query.forOrgPage.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type TRPCHandlerParams } from '~api/types/handler'

import { type TForOrgPageSchema } from './query.forOrgPage.schema'

const forOrgPage = async ({ ctx, input }: TRPCHandlerParams<TForOrgPageSchema>) => {
const forOrgPage = async ({ input }: TRPCHandlerParams<TForOrgPageSchema>) => {
const { slug } = input
const org = await prisma.organization.findUniqueOrThrow({
where: {
Expand All @@ -19,12 +19,6 @@ const forOrgPage = async ({ ctx, input }: TRPCHandlerParams<TForOrgPageSchema>)
lastVerified: true,
allowedEditors: { where: { authorized: true }, select: { userId: true } },
description: freeText,
userLists: ctx.session?.user.id
? {
where: { list: { ownedById: ctx.session.user.id } },
select: { list: { select: { id: true, name: true } } },
}
: undefined,

reviews: {
where: { visible: true, deleted: false },
Expand Down
17 changes: 7 additions & 10 deletions packages/api/router/savedLists/mutation.deleteItem.handler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getAuditedClient } from '@weareinreach/db'
import { getAuditedClient, isIdFor } from '@weareinreach/db'
import { checkListOwnership } from '~api/lib/checkListOwnership'
import { type TRPCHandlerParams } from '~api/types/handler'

import { type TDeleteItemSchema } from './mutation.deleteItem.schema'

const deleteItem = async ({ ctx, input }: TRPCHandlerParams<TDeleteItemSchema, 'protected'>) => {
const prisma = getAuditedClient(ctx.actorId)
const { id, organizationId, serviceId } = input
const { id, itemId } = input
checkListOwnership({ listId: id, userId: ctx.session.user.id })

const result = await prisma.userSavedList.update({
Expand All @@ -16,30 +16,27 @@ const deleteItem = async ({ ctx, input }: TRPCHandlerParams<TDeleteItemSchema, '
},

data: {
...(organizationId
...(isIdFor('organization', itemId)
? {
organizations: {
delete: {
listId_organizationId: {
listId: id,
organizationId,
organizationId: itemId,
},
},
},
}
: {}),
...(serviceId
? {
: {
services: {
delete: {
listId_serviceId: {
listId: id,
serviceId,
serviceId: itemId,
},
},
},
}
: {}),
}),
},
select: {
id: true,
Expand Down
21 changes: 16 additions & 5 deletions packages/api/router/savedLists/mutation.deleteItem.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ import { z } from 'zod'

import { prefixedId } from '~api/schemas/idPrefix'

export const ZDeleteItemSchema = z.object({
id: prefixedId('userSavedList'),
organizationId: prefixedId('organization').optional(),
serviceId: prefixedId('orgService').optional(),
})
export const ZDeleteItemSchema = z
.object({
id: prefixedId('userSavedList'),
organizationId: prefixedId('organization').optional(),
serviceId: prefixedId('orgService').optional(),
itemId: prefixedId('organization').or(prefixedId('orgService')).optional(),
})
.refine(({ organizationId, serviceId, itemId }) => Boolean(organizationId ?? serviceId ?? itemId), {
message: 'Must provide either organizationId, serviceId, or itemId',
})
.transform(({ id, organizationId, serviceId, itemId }) => {
if (itemId !== undefined) {
return { id, itemId }
}
return { id, itemId: (organizationId ?? serviceId) as string }
})

export type TDeleteItemSchema = z.infer<typeof ZDeleteItemSchema>
17 changes: 7 additions & 10 deletions packages/api/router/savedLists/mutation.saveItem.handler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getAuditedClient } from '@weareinreach/db'
import { getAuditedClient, isIdFor } from '@weareinreach/db'
import { checkListOwnership } from '~api/lib/checkListOwnership'
import { type TRPCHandlerParams } from '~api/types/handler'

import { type TSaveItemSchema } from './mutation.saveItem.schema'

const saveItem = async ({ ctx, input }: TRPCHandlerParams<TSaveItemSchema, 'protected'>) => {
const prisma = getAuditedClient(ctx.actorId)
const { id, organizationId, serviceId } = input
const { id, itemId } = input

checkListOwnership({ listId: id, userId: ctx.session.user.id })

Expand All @@ -16,24 +16,21 @@ const saveItem = async ({ ctx, input }: TRPCHandlerParams<TSaveItemSchema, 'prot
ownedById: ctx.session.user.id,
},
data: {
...(organizationId
...(isIdFor('organization', itemId)
? {
organizations: {
create: {
organizationId,
organizationId: itemId,
},
},
}
: {}),
...(serviceId
? {
: {
services: {
create: {
serviceId,
serviceId: itemId,
},
},
}
: {}),
}),
},
select: {
services: { select: { serviceId: true } },
Expand Down
21 changes: 16 additions & 5 deletions packages/api/router/savedLists/mutation.saveItem.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ import { z } from 'zod'

import { prefixedId } from '~api/schemas/idPrefix'

export const ZSaveItemSchema = z.object({
id: prefixedId('userSavedList'),
organizationId: prefixedId('organization').optional(),
serviceId: prefixedId('orgService').optional(),
})
export const ZSaveItemSchema = z
.object({
id: prefixedId('userSavedList'),
organizationId: prefixedId('organization').optional(),
serviceId: prefixedId('orgService').optional(),
itemId: prefixedId('organization').or(prefixedId('orgService')).optional(),
})
.refine(({ organizationId, serviceId, itemId }) => Boolean(organizationId ?? serviceId ?? itemId), {
message: 'Must provide either organizationId, serviceId, or itemId',
})
.transform(({ id, organizationId, serviceId, itemId }) => {
if (itemId !== undefined) {
return { id, itemId }
}
return { id, itemId: (organizationId ?? serviceId) as string }
})

export type TSaveItemSchema = z.infer<typeof ZSaveItemSchema>
2 changes: 1 addition & 1 deletion packages/api/router/savedLists/query.isSaved.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const isSaved = async ({ ctx, input }: TRPCHandlerParams<TIsSavedSchema>) => {
},
})
if (!result.length) {
return false
return null
}
return result
}
Expand Down
16 changes: 10 additions & 6 deletions packages/ui/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getAbsolutePath = (value: string) => {

const publicStatic = path.resolve(__dirname, '../../../apps/app/public')

const config: StorybookConfig = {
const storybookConfig: StorybookConfig = {
stories: [
'../components/**/*.stories.{ts,tsx}',
'../hooks/**/*.stories.{ts,tsx}',
Expand All @@ -41,12 +41,12 @@ const config: StorybookConfig = {
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@geometricpanda/storybook-addon-badges'),
getAbsolutePath('@storybook/addon-a11y'),
// eslint-disable-next-line storybook/no-uninstalled-addons
'@tomfreudenberg/next-auth-mock/storybook', // This addon doesn't like to be wrapped.
getAbsolutePath('@storybook/addon-designs'),
getAbsolutePath('storybook-addon-pseudo-states'),
getAbsolutePath('@storybook/addon-interactions'),
'@storybook/addon-webpack5-compiler-swc',
// eslint-disable-next-line storybook/no-uninstalled-addons
'@tomfreudenberg/next-auth-mock/storybook', // This addon doesn't like to be wrapped.
],
framework: {
name: '@storybook/nextjs',
Expand Down Expand Up @@ -105,15 +105,19 @@ const config: StorybookConfig = {
stats: {
colors: true,
},
devtool: options.configType === 'DEVELOPMENT' ? 'eval-source-map' : undefined,
// devtool: options.configType === 'DEVELOPMENT' ? 'eval-source-map' : undefined,
}

/** I18 HMR */
if (options.configType === 'DEVELOPMENT') {
const plugin = new I18NextHMRPlugin({
localesDir: path.resolve(__dirname, '../../../apps/app/public/locales'),
})
Array.isArray(config.plugins) ? config.plugins.push(plugin) : (config.plugins = [plugin])
if (Array.isArray(config.plugins)) {
config.plugins.push(plugin)
} else {
config.plugins = [plugin]
}
}

const mergedConfig = mergeAndConcat(config, configAdditions)
Expand All @@ -131,4 +135,4 @@ const config: StorybookConfig = {
STORYBOOK_PROJECT_ROOT: path.resolve(__dirname, '../'),
},
}
export default config
export default storybookConfig
11 changes: 6 additions & 5 deletions packages/ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './wdyr'
import './font.css'
import { type BADGE } from '@geometricpanda/storybook-addon-badges'
import { type ViewportAddonParameter } from '@storybook/addon-viewport'
import { type Preview } from '@storybook/react'
import { type WhyDidYouRenderOptions } from '@welldone-software/why-did-you-render'
import { http, passthrough, type RequestHandler } from 'msw'
Expand All @@ -24,7 +25,7 @@ import {
WithWhyDidYouRender,
} from './decorators'
import { i18n } from './i18next'
import { viewport, type ViewportConfig } from './viewports'
import { viewport } from './viewports'

import type authStates from './mockAuthStates'

Expand All @@ -35,7 +36,7 @@ initializeMsw({
},
},
onUnhandledRequest: ({ method, url }) => {
if (url.startsWith('/trpc' || '/api')) {
if (url.startsWith('/trpc') || url.startsWith('/api')) {
console.error(`Unhandled ${method} request to ${url}.
This exception has been only logged in the console, however, it's strongly recommended to resolve this error as you don't want unmocked data in Storybook stories.
Expand Down Expand Up @@ -64,8 +65,6 @@ const preview: Preview = {
excludeDecorators: true,
},
},
i18n,
viewport,
chromatic: {
delay: 1000,
},
Expand All @@ -80,6 +79,8 @@ const preview: Preview = {
}),
},
},
i18n,
viewport,
},
globalTypes: {
...i18NextGlobalTypes,
Expand Down Expand Up @@ -110,7 +111,7 @@ declare module '@storybook/react' {
}
locale?: LocaleCodes
i18n?: typeof i18n
viewport?: ViewportConfig
viewport?: ViewportAddonParameter
design?: DesignParams | DesignParams[]
msw?: RequestHandler[] | { handlers: RequestHandler[] | Record<string, RequestHandler> }
nextAuthMock?: { session: keyof typeof authStates }
Expand Down
12 changes: 2 additions & 10 deletions packages/ui/.storybook/viewports.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { type INITIAL_VIEWPORTS } from '@storybook/addon-viewport'
import { type ViewportAddonParameter } from '@storybook/addon-viewport'

import { type Viewports } from './types'

type ViewportMap = typeof INITIAL_VIEWPORTS
export interface ViewportConfig {
viewports?: ViewportMap
defaultViewport?: Viewports
}

export const viewport: ViewportConfig = {
export const viewport: ViewportAddonParameter = {
viewports: {
iphonex: {
name: 'iPhone X',
Expand Down
Loading

0 comments on commit 05f1fb9

Please sign in to comment.