Skip to content

Commit

Permalink
fix attribute add/display
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Apr 10, 2024
1 parent a71363b commit a17fcb5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/ui/modals/Service/processor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const processAttributes = ({
break
}
/** Target Population & Eligibility Requirements */
case 'tpop':
case 'eligibility': {
const type = tsKey.split('.').pop() as string
switch (type) {
Expand All @@ -161,6 +162,7 @@ export const processAttributes = ({
)
break
}
case 'other':
case 'other-describe': {
const { text } = attribute
if (!text) break
Expand Down
20 changes: 16 additions & 4 deletions packages/ui/modals/dataPortal/Attributes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { FormProvider, useForm } from 'react-hook-form'
import { type ApiOutput } from '@weareinreach/api'
import { generateId } from '@weareinreach/db/lib/idGen'
import { Button } from '~ui/components/core/Button'
import { useNewNotification } from '~ui/hooks/useNewNotification'
import { trpc as api } from '~ui/lib/trpcClient'
import { ModalTitle } from '~ui/modals/ModalTitle'

Expand All @@ -36,10 +37,10 @@ const AttributeModalBody = forwardRef<HTMLButtonElement, AttributeModalProps>(
({ restrictCategories, attachesTo, parentRecord, ...props }, ref) => {
const { t } = useTranslation(['attribute', 'common'])
const [opened, handler] = useDisclosure(false)

const showAddedNotification = useNewNotification({ icon: 'added', displayText: 'Added Attribute' })
const selectAttrRef = useRef<HTMLInputElement>(null)
// #region tRPC
// const utils = api.useUtils()
const apiUtils = api.useUtils()
const [attrCat, setAttrCat] = useState<string | null>()
const { data: attributesByCategory, ...attributesByCategoryApi } =
api.fieldOpt.attributesByCategory.useQuery(undefined, {
Expand Down Expand Up @@ -86,7 +87,15 @@ const AttributeModalBody = forwardRef<HTMLButtonElement, AttributeModalProps>(
null
)
const [supplements, setSupplements] = useState<SupplementFieldsNeeded>(supplementDefaults)
const saveAttributes = api.organization.attachAttribute.useMutation()
const saveAttributes = api.organization.attachAttribute.useMutation({
onSuccess: () => {
if (parentRecord.serviceId) {
apiUtils.service.forServiceEditDrawer.invalidate(parentRecord.serviceId)
}
showAddedNotification()
handler.close()
},
})
// #endregion

// #region Handlers
Expand Down Expand Up @@ -209,5 +218,8 @@ export const AttributeModal = createPolymorphicComponent<'button', AttributeModa
export interface AttributeModalProps extends ButtonProps {
restrictCategories?: string[]
attachesTo?: ApiOutput['fieldOpt']['attributesByCategory'][number]['canAttachTo']
parentRecord: { organizationId: string } | { serviceId: string } | { locationId: string }
parentRecord:
| { organizationId: string; serviceId?: never; locationId?: never }
| { serviceId: string; organizationId?: never; locationId?: never }
| { locationId: string; serviceId?: never; organizationId?: never }
}

0 comments on commit a17fcb5

Please sign in to comment.