Skip to content

Commit

Permalink
Attribute modal
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Feb 15, 2024
1 parent ad8d544 commit baf803a
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 218 deletions.
10 changes: 5 additions & 5 deletions packages/db/zod_util/attributeSupplement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,25 @@ export enum FieldType {
number = 'number',
currency = 'currency',
}
interface BaseFieldAttributes {
export interface BaseFieldAttributes {
key: string
label: string
name: string
type: FieldType
required?: boolean
}

interface TextFieldAttributes extends BaseFieldAttributes {
export interface TextFieldAttributes extends BaseFieldAttributes {
type: FieldType.text
}
interface SelectFieldAttributes extends BaseFieldAttributes {
export interface SelectFieldAttributes extends BaseFieldAttributes {
type: FieldType.select
options: { value: string; label: string }[]
}
interface NumberFieldAttributes extends BaseFieldAttributes {
export interface NumberFieldAttributes extends BaseFieldAttributes {
type: FieldType.number
}
interface CurrencyFieldAttributes extends BaseFieldAttributes {
export interface CurrencyFieldAttributes extends BaseFieldAttributes {
type: FieldType.currency
}
export type FieldAttributes =
Expand Down
12 changes: 5 additions & 7 deletions packages/ui/modals/dataPortal/Attributes/fields.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Group, Select as MantineSelect, Stack, Text } from '@mantine/core'
import { useTranslation } from 'next-i18next'
import { type ComponentPropsWithoutRef, forwardRef, useState } from 'react'
import { type FieldPath, useFormContext } from 'react-hook-form'
import { useFormContext } from 'react-hook-form'
import { NumberInput, Radio, Select, TextInput } from 'react-hook-form-mantine'
import { type TupleToUnion } from 'type-fest'

import { type ApiOutput } from '@weareinreach/api'
import { type FieldAttributes, FieldType } from '@weareinreach/db/zod_util/attributeSupplement'
Expand All @@ -26,7 +25,6 @@ const SuppBoolean = () => {

const SuppText = () => {
const { control } = useFormContext<FormSchema>()
const { t } = useTranslation('common')
return (
<Stack>
<TextInput {...{ control, name: 'text' }} />
Expand Down Expand Up @@ -118,10 +116,10 @@ const SuppGeo = ({ countryOnly }: SuppGeoProps) => {
const [secondarySearch, onSecondarySearch] = useState<string | null>(null)
const [tertiarySearch, onTertiarySearch] = useState<string | null>(null)

const [finalValue, setFinalValue] = useState<string | null>(null)
const [fieldName, setFieldName] = useState<FieldPath<FormSchema> | undefined>(
countryOnly ? 'countryId' : undefined
)
// const [finalValue, setFinalValue] = useState<string | null>(null)
// const [fieldName, setFieldName] = useState<FieldPath<FormSchema> | undefined>(
// countryOnly ? 'countryId' : undefined
// )

const { data: countryList, ...countries } = api.fieldOpt.countries.useQuery(undefined, {
enabled: countryOnly ?? false,
Expand Down
12 changes: 10 additions & 2 deletions packages/ui/modals/dataPortal/Attributes/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { type Meta } from '@storybook/react'
import { type Meta, type StoryObj } from '@storybook/react'

import { Button } from '~ui/components/core/Button'
import { allFieldOptHandlers } from '~ui/mockData/fieldOpt'

import { AttributeModal } from './index'

type StoryDef = StoryObj<typeof AttributeModal>
export default {
title: 'Data Portal/Modals/Attributes',
component: AttributeModal,
Expand All @@ -18,7 +19,14 @@ export default {
component: Button,
children: 'Open Modal',
variant: 'inlineInvertedUtil1',
restrictCategories: undefined,
attachesTo: undefined,
},
} satisfies Meta<typeof AttributeModal>

export const Modal = {}
export const AllCategories = {} satisfies StoryDef
export const AttachesToService = {
args: {
attachesTo: ['SERVICE'],
},
} satisfies StoryDef
Loading

0 comments on commit baf803a

Please sign in to comment.