From 9070b1d9451dc75705302198003234fcf1d10578 Mon Sep 17 00:00:00 2001 From: Joe Karow <58997957+JoeKarow@users.noreply.github.com> Date: Tue, 9 Jan 2024 17:02:36 -0500 Subject: [PATCH] create edit mode ContactSection --- apps/app/src/pages/org/[slug]/edit.tsx | 3 +- .../data-display/ContactInfo/PhoneNumbers.tsx | 69 +++++++++++++++++-- .../data-display/ContactInfo/types.ts | 1 + .../sections/ContactSection/index.tsx | 5 +- 4 files changed, 70 insertions(+), 8 deletions(-) diff --git a/apps/app/src/pages/org/[slug]/edit.tsx b/apps/app/src/pages/org/[slug]/edit.tsx index 91d91a8244..0325f66395 100644 --- a/apps/app/src/pages/org/[slug]/edit.tsx +++ b/apps/app/src/pages/org/[slug]/edit.tsx @@ -87,7 +87,7 @@ const OrganizationPage: NextPageWithOptions - + {width && ( { +export const PhoneNumbers = ({ edit, ...props }: PhoneNumbersProps) => + edit ? : + +const PhoneNumbersDisplay = ({ parentId = '', passedData, direct, locationOnly }: PhoneNumbersProps) => { const output: ReactElement[] = [] const slug = useSlug() const { data: orgId } = api.organization.getIdFromSlug.useQuery({ slug }) const { t } = useTranslation(orgId?.id ? ['common', 'phone-type', orgId.id] : ['common', 'phone-type']) const variants = useCustomVariant() const { data } = api.orgPhone.forContactInfo.useQuery({ parentId, locationOnly }, { enabled: !passedData }) - let k = 0 const componentData = passedData ? passedData : data @@ -52,9 +55,9 @@ export const PhoneNumbers = ({ parentId = '', passedData, direct, locationOnly } : undefined const item = ( - + {isExternal(dialURL) ? ( - + {phoneNumber} ) : ( @@ -64,7 +67,63 @@ export const PhoneNumbers = ({ parentId = '', passedData, direct, locationOnly } ) primary ? output.unshift(item) : output.push(item) - k++ + } + return ( + + {t('words.phone')} + {output} + + ) +} + +const PhoneNumbersEdit = ({ parentId = '', passedData, direct }: PhoneNumbersProps) => { + const output: ReactElement[] = [] + const slug = useSlug() + const { data: orgId } = api.organization.getIdFromSlug.useQuery({ slug }) + const { t } = useTranslation(orgId?.id ? ['common', 'phone-type', orgId.id] : ['common', 'phone-type']) + const variants = useCustomVariant() + const { data } = api.orgPhone.forContactInfoEdit.useQuery({ parentId }, { enabled: !passedData }) + + const componentData = passedData ? passedData : data + + if (!componentData?.length) return null + + for (const phone of componentData) { + const { country, ext, number, phoneType, primary, description } = phone + const parsedPhone = parsePhoneNumber(number, country) + if (!parsedPhone) continue + if (ext) parsedPhone.setExt(ext) + const dialURL = parsedPhone.getURI() + const phoneNumber = parsedPhone.formatNational() + if (direct) { + return ( + + {t('direct.phone')} + {isExternal(dialURL) ? ( + + {phoneNumber} + + ) : ( + {phoneNumber} + )} + + ) + } + const desc = description + ? t(description.key, { ns: orgId?.id, defaultValue: description.defaultText }) + : phoneType?.key + ? t(phoneType.key, { ns: 'phone-type' }) + : undefined + + const item = ( + + + {phoneNumber} + + {desc && {desc}} + + ) + primary ? output.unshift(item) : output.push(item) } return ( diff --git a/packages/ui/components/data-display/ContactInfo/types.ts b/packages/ui/components/data-display/ContactInfo/types.ts index a58a90864d..3020041dbf 100644 --- a/packages/ui/components/data-display/ContactInfo/types.ts +++ b/packages/ui/components/data-display/ContactInfo/types.ts @@ -18,6 +18,7 @@ interface CommonProps { locationOnly?: boolean serviceOnly?: boolean websiteDesc?: boolean + edit?: boolean } export type PhoneNumbersProps = CommonProps & (ApiData | PassedData<'orgPhone', 'forContactInfo'>) diff --git a/packages/ui/components/sections/ContactSection/index.tsx b/packages/ui/components/sections/ContactSection/index.tsx index bb380309dc..bf00e4a5e1 100644 --- a/packages/ui/components/sections/ContactSection/index.tsx +++ b/packages/ui/components/sections/ContactSection/index.tsx @@ -5,7 +5,7 @@ import { ContactInfo } from '~ui/components/data-display/ContactInfo' import { useScreenSize } from '~ui/hooks' import { trpc as api } from '~ui/lib/trpcClient' -export const ContactSection = ({ parentId }: ContactSectionProps) => { +export const ContactSection = ({ parentId, edit }: ContactSectionProps) => { const { t } = useTranslation(['common']) const { isMobile, isTablet } = useScreenSize() const { data: hasContactInfo } = api.misc.hasContactInfo.useQuery(parentId) @@ -15,7 +15,7 @@ export const ContactSection = ({ parentId }: ContactSectionProps) => { const body = ( {t('contact')} - + ) return isTablet || isMobile ? body : {body} @@ -24,4 +24,5 @@ export const ContactSection = ({ parentId }: ContactSectionProps) => { export type ContactSectionProps = { role: 'org' | 'location' parentId: string + edit?: boolean }