From 824af8b740743de738e326e344e672cc5cb3df0b Mon Sep 17 00:00:00 2001 From: Joe Karow <58997957+JoeKarow@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:10:30 -0500 Subject: [PATCH 1/4] cherry-pick migration from IN-831-edit-organization-page --- packages/db/prisma/migrations/20230928155156_/migration.sql | 2 ++ packages/db/prisma/schema.prisma | 1 + 2 files changed, 3 insertions(+) create mode 100644 packages/db/prisma/migrations/20230928155156_/migration.sql diff --git a/packages/db/prisma/migrations/20230928155156_/migration.sql b/packages/db/prisma/migrations/20230928155156_/migration.sql new file mode 100644 index 0000000000..894418f6eb --- /dev/null +++ b/packages/db/prisma/migrations/20230928155156_/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "OrgPhone" ADD COLUMN "countryCode" TEXT; diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index d07833831e..f17d3bf837 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -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) From f2d2e947de9951a522a8366a91fc95fe89aa54fc Mon Sep 17 00:00:00 2001 From: Joe Karow <58997957+JoeKarow@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:13:34 -0500 Subject: [PATCH 2/4] update bool defaults --- .../migration.sql | 37 +++++++++++++++++++ packages/db/prisma/schema.prisma | 6 +-- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 packages/db/prisma/migrations/20231211210937_boolean_defaults_for_location/migration.sql diff --git a/packages/db/prisma/migrations/20231211210937_boolean_defaults_for_location/migration.sql b/packages/db/prisma/migrations/20231211210937_boolean_defaults_for_location/migration.sql new file mode 100644 index 0000000000..ab2af21f3e --- /dev/null +++ b/packages/db/prisma/migrations/20231211210937_boolean_defaults_for_location/migration.sql @@ -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; diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index f17d3bf837..5fc329e11f 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -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 From e4c7cd3209d5df2b840ed0352c3c12a98501f760 Mon Sep 17 00:00:00 2001 From: Joe Karow <58997957+JoeKarow@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:32:10 -0500 Subject: [PATCH 3/4] fix hours styling --- packages/ui/components/data-display/Hours.tsx | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/ui/components/data-display/Hours.tsx b/packages/ui/components/data-display/Hours.tsx index 9919b43871..e6574ded5a 100644 --- a/packages/ui/components/data-display/Hours.tsx +++ b/packages/ui/components/data-display/Hours.tsx @@ -17,6 +17,14 @@ 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', }, })) @@ -34,19 +42,23 @@ export const Hours = ({ parentId, label = 'regular' }: HoursProps) => { const hourTable = Object.entries(data).map(([dayIdx, data]) => { return ( - {dayMap.get(parseInt(dayIdx))} - + + {dayMap.get(parseInt(dayIdx))} + + {data.map(({ id, interval: intervalISO, closed }) => { const interval = Interval.fromISO(intervalISO) return ( - {closed - ? t('hours.closed') - : interval.toDuration('hours').valueOf() === OPEN_24_MILLISECONDS - ? t('hours.open24') - : interval.toFormat('hh:mm a')} + + {closed + ? t('hours.closed') + : interval.toDuration('hours').valueOf() === OPEN_24_MILLISECONDS + ? t('hours.open24') + : interval.toFormat('hh:mm a')} + ) })} From d0ab4d7b461a3559e51547772644498f18cbc7f7 Mon Sep 17 00:00:00 2001 From: Joe Karow <58997957+JoeKarow@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:46:09 -0500 Subject: [PATCH 4/4] add loading state, fix no-result state --- .../orgHours/query.forHoursDisplay.handler.ts | 3 +- packages/ui/components/data-display/Hours.tsx | 34 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/packages/api/router/orgHours/query.forHoursDisplay.handler.ts b/packages/api/router/orgHours/query.forHoursDisplay.handler.ts index 51582d6801..3b1edd6421 100644 --- a/packages/api/router/orgHours/query.forHoursDisplay.handler.ts +++ b/packages/api/router/orgHours/query.forHoursDisplay.handler.ts @@ -32,6 +32,7 @@ export const forHoursDisplay = async ({ input }: TRPCHandlerParams { @@ -42,7 +43,7 @@ export const forHoursDisplay = async ({ input }: TRPCHandlerParams end ? dayIndex + 1 : dayIndex, weekYear, weekNumber, }) diff --git a/packages/ui/components/data-display/Hours.tsx b/packages/ui/components/data-display/Hours.tsx index e6574ded5a..dab539a75e 100644 --- a/packages/ui/components/data-display/Hours.tsx +++ b/packages/ui/components/data-display/Hours.tsx @@ -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' @@ -28,18 +28,28 @@ const useStyles = createStyles(() => ({ }, })) +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 ( @@ -70,13 +80,15 @@ export const Hours = ({ parentId, label = 'regular' }: HoursProps) => { return ( -
- {t(labelKey)} - {timezone} -
- - {hourTable} -
+ +
+ {t(labelKey)} + {timezone} +
+ + {hourTable} +
+
) }