Skip to content

Commit

Permalink
fix: Visit/Contact card conditional rendering (#1336)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

# Pull Request type

<!-- Please try to limit your pull request to one type; submit multiple
pull requests if needed. -->

Please check the type of change your PR introduces:

- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no API changes)
- [ ] Build-related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->

Issue Number: N/A

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

-
-
-

## Does this introduce a breaking change?

- [ ] Yes
- [ ] No

<!-- If this does introduce a breaking change, please describe the
impact and migration path for existing applications below. -->

## Other information

<!-- Any other information that is important to this PR, such as
screenshots of how the component looks before and after the change. -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
  - Added display of operational hours in the visit card if available.

- **Bug Fixes**
- Improved contact information logic to accurately reflect the presence
of contact details.
  
- **Enhancements**
- Enhanced `ContactSection` and `VisitCard` components to better handle
the absence of key data, improving user experience.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
JoeKarow authored Jul 18, 2024
1 parent ee20a26 commit 4b33d7a
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 4b33d7a

Please sign in to comment.