Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: schema updates #953

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading