Skip to content

Commit

Permalink
Merge branch 'dev' into IN-831-edit-organization-page
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Dec 11, 2023
2 parents 6840b0e + 6bc0499 commit 4edd369
Show file tree
Hide file tree
Showing 4 changed files with 84 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
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;
6 changes: 3 additions & 3 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -631,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 4edd369

Please sign in to comment.