Skip to content

Commit

Permalink
release: 2024-07-18 (#1335)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced error handling with Sentry integration for better issue
tracking and diagnostics.
  
- **Improvements**
- Address formatting logic now includes an edit mode, providing more
flexible handling of address visibility.

- **UI Updates**
- VisitCard component now displays an icon with a tooltip when the
address is hidden.
- Simplified mutation handling for the AddressDrawer component for
improved performance.
- Updated Icon component to better handle refs, improving responsiveness
and usability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
kodiakhq[bot] committed Jul 18, 2024
2 parents dbeaf3b + 42c8127 commit ee20a26
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 50 deletions.
32 changes: 12 additions & 20 deletions apps/app/src/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,28 @@ const isServer = typeof window === 'undefined'
export default createNextApiHandler({
createContext,
router: appRouter,
onError: ({ path, error, type }) => {
onError: ({ path, error, type, ctx }) => {
Sentry.setUser(ctx?.session?.user ?? null)
if (error.code !== 'NOT_FOUND') {
Sentry.captureException(error, (scope) => {
scope.setTags({
'tRPC.path': path,
'tRPC.operation': type,
})
return scope
})
}
switch (true) {
case isDev: {
if (error.code === 'INTERNAL_SERVER_ERROR') {
Sentry.captureException(error, (scope) => {
scope.setTags({
'tRPC.path': path,
'tRPC.operation': type,
})
return scope
})
}
log.error(`❌ tRPC ${type} failed on ${path}:`, error)
break
}
case isServer: {
if (error.code === 'INTERNAL_SERVER_ERROR') {
Sentry.captureException(error, (scope) => {
scope.setTags({
'tRPC.path': path,
'tRPC.operation': type,
})
return scope
})
}
log.error({ type, path, error })
break
}
default: {
return
break
}
}
},
Expand Down
8 changes: 5 additions & 3 deletions packages/api/router/location/lib.formatAddressVisibility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PrismaEnums } from '@weareinreach/db'

export const formatAddressVisiblity = (location: ProvidedAddress) => {
export const formatAddressVisiblity = (location: ProvidedAddress, isEditMode = false) => {
const address: ReformattedAddress = {
street1: location.street1,
street2: location.street2,
Expand All @@ -23,11 +23,13 @@ export const formatAddressVisiblity = (location: ProvidedAddress) => {
default: {
address.street1 = null
address.street2 = null
address.city = null
address.postCode = null
address.govDist = null
address.latitude = null
address.longitude = null
if (!isEditMode) {
address.city = null
address.govDist = null
}
return address
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const forVisitCardEdits = async ({ input }: TRPCHandlerParams<TForVisitCardEdits
if (!result) {
return null
}
const formattedAddress = formatAddressVisiblity(result)
const formattedAddress = formatAddressVisiblity(result, true)

const { attributes, ...rest } = result
const transformed = {
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/components/data-portal/AddressDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ const _AddressDrawer = forwardRef<HTMLButtonElement, AddressDrawerProps>(({ loca
// #region Mutation handling
const updateLocation = api.location.update.useMutation({
onSuccess: () => {
apiUtils.location.getAddress.invalidate(locationId ?? '')
apiUtils.location.forVisitCard.invalidate()
apiUtils.location.invalidate()
setIsSaved(true)
notifySave()
setTimeout(() => handler.close(), 500)
Expand Down
32 changes: 21 additions & 11 deletions packages/ui/components/sections/VisitCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Card, createStyles, rem, Stack, Text, Title, useMantineTheme } from '@mantine/core'
import { Card, createStyles, Group, rem, Stack, Text, Title, Tooltip, useMantineTheme } from '@mantine/core'
import { useElementSize, useMediaQuery } from '@mantine/hooks'
import { useTranslation } from 'next-i18next'
import { useEffect } from 'react'
import invariant from 'tiny-invariant'

import { AddressVisibility } from '@weareinreach/db/enums'
import { Badge } from '~ui/components/core/Badge'
import { GoogleMap } from '~ui/components/core/GoogleMap'
import { Link } from '~ui/components/core/Link'
Expand All @@ -12,7 +13,7 @@ import { AddressDrawer } from '~ui/components/data-portal/AddressDrawer'
import { useCustomVariant, useFormattedAddress, useScreenSize } from '~ui/hooks'
import { useGoogleMapMarker } from '~ui/hooks/useGoogleMapMarker'
import { useGoogleMaps } from '~ui/hooks/useGoogleMaps'
import { validateIcon } from '~ui/icon'
import { Icon, validateIcon } from '~ui/icon'
import { trpc as api } from '~ui/lib/trpcClient'

export const VisitCard = ({ edit = false, ...props }: VisitCardProps & { edit?: boolean }) =>
Expand Down Expand Up @@ -171,18 +172,27 @@ const VisitCardEdit = ({ locationId }: VisitCardProps) => {
return null
}

const addressHiddenIcon = (
<Tooltip label='Address is hidden' withinPortal>
<Icon icon='carbon:view-off' />
</Tooltip>
)

const address = formattedAddress && (
<Stack spacing={12} ref={ref}>
<Title order={3}>{t('address', { context: data.remote ? 'physical' : undefined })}</Title>
<AddressDrawer
locationId={locationId}
external
component={Link}
variant={variants.Link.inlineInverted}
className={classes.overlay}
>
<Text className={classes.overlayInner}>{formattedAddress}</Text>
</AddressDrawer>
<Group>
{data.addressVisibility === AddressVisibility.HIDDEN && addressHiddenIcon}
<AddressDrawer
locationId={locationId}
external
component={Link}
variant={variants.Link.inlineInverted}
className={classes.overlay}
>
<Text className={classes.overlayInner}>{formattedAddress}</Text>
</AddressDrawer>
</Group>
<GoogleMap locationIds={data.id} height={Math.floor(width * 0.625)} width={width} />
</Stack>
)
Expand Down
28 changes: 15 additions & 13 deletions packages/ui/icon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Icon as Iconify, type IconifyIconHTMLElement, type IconifyIconProps } from '@iconify-icon/react'
import { createStyles } from '@mantine/core'
import { memo, type Ref, type SVGProps } from 'react'
import { forwardRef, memo, type Ref, type SVGProps } from 'react'
import { type LiteralUnion } from 'type-fest'

import { iconList } from './iconList'
Expand All @@ -22,18 +22,20 @@ const useStyles = createStyles((_theme, { block, color }: IconStylesParams) => (
},
}))

export const Icon = memo(({ icon, block, className, ref, color, ...props }: CustomIconProps) => {
const { classes, cx } = useStyles({ block, color })
Iconify.displayName = 'Iconify'
return (
<Iconify
ref={ref}
icon={validateIcon(icon)}
className={`${cx(classes.root, className)} iconify-icon-root`}
{...props}
/>
)
})
export const Icon = memo(
forwardRef<IconifyIconHTMLElement, CustomIconProps>(({ icon, block, className, color, ...props }, ref) => {
const { classes, cx } = useStyles({ block, color })
Iconify.displayName = 'Iconify'
return (
<Iconify
ref={ref}
icon={validateIcon(icon)}
className={`${cx(classes.root, className)} iconify-icon-root`}
{...props}
/>
)
})
)

Icon.displayName = '@weareinreach/ui/icon'
export type IconList = (typeof iconList)[number]
Expand Down

1 comment on commit ee20a26

@vercel
Copy link

@vercel vercel bot commented on ee20a26 Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.