Skip to content

Commit

Permalink
fix: schema updates (#953)
Browse files Browse the repository at this point in the history
- cherry-pick migration from IN-831-edit-organization-page
- update bool defaults

<!--- 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. -->

OrgLocation api query was excluding results due to boolean value allowed
to be null.

## 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. -->
  • Loading branch information
kodiakhq[bot] authored Dec 11, 2023
2 parents 14871c1 + d0ab4d7 commit 6bc0499
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const forHoursDisplay = async ({ input }: TRPCHandlerParams<TForHoursDisp
select: { id: true, dayIndex: true, start: true, end: true, closed: true, tz: true },
orderBy: [{ dayIndex: 'asc' }, { start: 'asc' }],
})
if (!result.length) return null

const { weekYear, weekNumber } = DateTime.now()
const intervalResults = result.map(({ start, end, tz, dayIndex, ...rest }) => {
Expand All @@ -42,7 +43,7 @@ export const forHoursDisplay = async ({ input }: TRPCHandlerParams<TForHoursDisp
weekNumber,
}),
DateTime.fromJSDate(end, { zone: tz ?? 'America/New_York' }).set({
weekday: dayIndex,
weekday: start > end ? dayIndex + 1 : dayIndex,
weekYear,
weekNumber,
})
Expand Down
2 changes: 2 additions & 0 deletions packages/db/prisma/migrations/20230928155156_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "OrgPhone" ADD COLUMN "countryCode" TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Warnings:
- Made the column `mailOnly` on table `OrgLocation` required. This step will fail if there are existing NULL values in that column.
- Made the column `mapCityOnly` on table `OrgLocation` required. This step will fail if there are existing NULL values in that column.
- Made the column `notVisitable` on table `OrgLocation` required. This step will fail if there are existing NULL values in that column.
*/
-- Update values for Location
UPDATE
"OrgLocation"
SET
"mailOnly" = FALSE
WHERE
"mailOnly" IS NULL;

UPDATE
"OrgLocation"
SET
"mapCityOnly" = FALSE
WHERE
"mapCityOnly" IS NULL;

UPDATE
"OrgLocation"
SET
"notVisitable" = FALSE
WHERE
"notVisitable" IS NULL;

-- AlterTable
ALTER TABLE "OrgLocation"
ALTER COLUMN "mailOnly" SET NOT NULL,
ALTER COLUMN "mailOnly" SET DEFAULT FALSE,
ALTER COLUMN "mapCityOnly" SET NOT NULL,
ALTER COLUMN "mapCityOnly" SET DEFAULT FALSE,
ALTER COLUMN "notVisitable" SET NOT NULL,
ALTER COLUMN "notVisitable" SET DEFAULT FALSE;
7 changes: 4 additions & 3 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ model OrgPhone {
id String @id @default(cuid())
legacyId String? @unique /// old ID from MongoDB
legacyDesc String?
countryCode String?
number String
ext String?
primary Boolean @default(false)
Expand Down Expand Up @@ -630,9 +631,9 @@ model OrgLocation {
postCode String?
primary Boolean @default(false)
mailOnly Boolean?
notVisitable Boolean?
mapCityOnly Boolean?
mailOnly Boolean @default(false)
notVisitable Boolean @default(false)
mapCityOnly Boolean @default(false)
description FreeText? @relation(fields: [descriptionId], references: [id], onDelete: SetNull, onUpdate: Cascade)
descriptionId String? @unique
Expand Down
60 changes: 42 additions & 18 deletions packages/ui/components/data-display/Hours.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createStyles, List, rem, Stack, Table, Text, Title } from '@mantine/core'
import { createStyles, List, rem, Skeleton, Stack, Table, Text, Title } from '@mantine/core'
import { Interval } from 'luxon'
import { useTranslation } from 'next-i18next'

Expand All @@ -17,36 +17,58 @@ const useStyles = createStyles(() => ({
dow: {
verticalAlign: 'baseline',
paddingRight: rem(4),
borderTopStyle: 'none !important' as 'none',
paddingTop: '0 !important',
paddingBottom: '0 !important',
},
hours: {
borderTopStyle: 'none !important' as 'none',
paddingTop: '0 !important',
paddingBottom: '0 !important',
},
}))

const nullObj = {
0: [],
1: [],
2: [],
3: [],
4: [],
5: [],
6: [],
}

export const Hours = ({ parentId, label = 'regular' }: HoursProps) => {
const { t, i18n } = useTranslation('common')
const variants = useCustomVariant()
const { classes } = useStyles()
const { data } = api.orgHours.forHoursDisplay.useQuery(parentId)
const { data, isLoading } = api.orgHours.forHoursDisplay.useQuery(parentId)
const dayMap = useLocalizedDays(i18n.resolvedLanguage)
if (!data) return null
if (!data && !isLoading) return null

const labelKey = labelKeys[label]
const timezone: string | null = null

const hourTable = Object.entries(data).map(([dayIdx, data]) => {
const hourTable = Object.entries(data ?? nullObj).map(([dayIdx, data]) => {
return (
<tr key={dayIdx}>
<td className={classes.dow}>{dayMap.get(parseInt(dayIdx))}</td>
<td>
<td className={classes.dow}>
<Text>{dayMap.get(parseInt(dayIdx))}</Text>
</td>
<td className={classes.hours}>
<List listStyleType='none'>
{data.map(({ id, interval: intervalISO, closed }) => {
const interval = Interval.fromISO(intervalISO)

return (
<List.Item key={id}>
{closed
? t('hours.closed')
: interval.toDuration('hours').valueOf() === OPEN_24_MILLISECONDS
? t('hours.open24')
: interval.toFormat('hh:mm a')}
<Text>
{closed
? t('hours.closed')
: interval.toDuration('hours').valueOf() === OPEN_24_MILLISECONDS
? t('hours.open24')
: interval.toFormat('hh:mm a')}
</Text>
</List.Item>
)
})}
Expand All @@ -58,13 +80,15 @@ export const Hours = ({ parentId, label = 'regular' }: HoursProps) => {

return (
<Stack spacing={12}>
<div>
<Title order={3}>{t(labelKey)}</Title>
<Text variant={variants.Text.utility4darkGray}>{timezone}</Text>
</div>
<Table>
<tbody>{hourTable}</tbody>
</Table>
<Skeleton visible={isLoading}>
<div>
<Title order={3}>{t(labelKey)}</Title>
<Text variant={variants.Text.utility4darkGray}>{timezone}</Text>
</div>
<Table>
<tbody>{hourTable}</tbody>
</Table>
</Skeleton>
</Stack>
)
}
Expand Down

0 comments on commit 6bc0499

Please sign in to comment.