Skip to content

Commit

Permalink
better conditional rendering checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Jul 18, 2024
1 parent ee20a26 commit ad1046b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/api/router/location/query.forVisitCard.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ const forVisitCard = async ({ input }: TRPCHandlerParams<TForVisitCardSchema>) =
latitude: true,
longitude: true,
addressVisibility: true,
hours: { where: { active: true }, select: { id: true } },
},
})
if (!result) {
return null
}
const { attributes, ...rest } = result
const { attributes, hours, ...rest } = result
const transformed = {
...rest,
...formatAddressVisiblity(rest),
remote: attributes.find(({ attribute }) => attribute.tsKey === 'additional.offers-remote-services')
?.attribute,
hasHours: hours.length > 0,
}
return transformed
} catch (err) {
Expand Down
9 changes: 6 additions & 3 deletions packages/api/router/misc/query.hasContactInfo.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ const whereId = (
locations: { some: { location: { id: input, ...isPublic } } },
...isPublic,
},
socialMedia: { locations: { every: { location: { id: input, ...isPublic } } }, ...isPublic },
website: { locations: { every: { location: { id: input, ...isPublic } } }, ...isPublic },
socialMedia: { locations: { some: { location: { id: input, ...isPublic } } }, ...isPublic },
website: { locations: { some: { location: { id: input, ...isPublic } } }, ...isPublic },
}
}
case isIdFor('orgService', input): {
Expand Down Expand Up @@ -120,7 +120,10 @@ const hasContactInfo = async ({ input }: TRPCHandlerParams<THasContactInfoSchema
? prisma.orgWebsite.count({ where: whereId(input, isSingleLoc).website })
: 0,
])
return email + phone + socialMedia + website !== 0 // ? 'true' : 'false'

const totalCount = email + phone + socialMedia + website

return totalCount !== 0
} catch (error) {
return handleError(error)
}
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/components/sections/ContactSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export const ContactSection = ({ parentId, edit }: ContactSectionProps) => {
const { isMobile, isTablet } = useScreenSize()
const { data: hasContactInfo } = api.misc.hasContactInfo.useQuery(parentId)

if (!hasContactInfo && !edit) return null
if (!hasContactInfo && !edit) {
return null
}

const body = (
<Stack spacing={isMobile ? 32 : 40}>
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/components/sections/VisitCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const VisitCardDisplay = ({ locationId }: VisitCardProps) => {
</Stack> */}
</Stack>
)
if (!formattedAddress && !data.hasHours) {
return null
}

return isTablet ? body : <Card>{body}</Card>
}
Expand Down

0 comments on commit ad1046b

Please sign in to comment.