Skip to content

Commit

Permalink
Merge branch 'rearrange-properties'
Browse files Browse the repository at this point in the history
  • Loading branch information
Julia Helena Reuter committed Jan 28, 2024
2 parents a853312 + 0f60270 commit 436a3ff
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions locales/de/designer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ BooleanDefaultProperty:
label: Default
BorderProperty:
label: Begrenzung
DateDefaultProperty:
label: Default
DisabledProperty:
label: Deaktiviert
modalTitle: Deaktiviert
Expand Down
2 changes: 2 additions & 0 deletions locales/en/designer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ BooleanDefaultProperty:
label: Default
BorderProperty:
label: Border
DateDefaultProperty:
label: Default
DisabledProperty:
label: Disabled
modalTitle: Disabled
Expand Down
2 changes: 1 addition & 1 deletion src/components/adapters/DateFieldAdapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const DateFieldAdapter = ({ node }: DateFieldAdapterProps) => {
disabled={evalCodeToBoolean(node.disabled)}
hidden={evalCodeToBoolean(node.hidden)}
format={node.format}
defaultValue={node.default ? dayjs(node.default, node.format).toISOString() : undefined}
defaultValue={node.default ? dayjs(node.default).toISOString() : undefined}
/>
)
}
28 changes: 28 additions & 0 deletions src/components/designer/properties/DateDefaultProperty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { DateInput } from "@mantine/dates"
import { Controller } from "react-hook-form"
import { useSiteTranslation } from "~/hooks/useSiteTranslation"
import { DateFieldNode } from "~/schemas/structure"

interface DateDefaultPropertyProps {
node: DateFieldNode
}
export const DateDefaultProperty = ({
node,
}: DateDefaultPropertyProps & { node: DateFieldNode }) => {
const { t } = useSiteTranslation()
return (
<Controller
name="default"
render={({ field: { value, onChange }, fieldState: { error } }) => (
<DateInput
label={t("DateDefaultProperty.label")}
value={value ? new Date(value) : null}
onChange={(newValue) => onChange(newValue?.toISOString() ?? null)}
error={error?.message}
clearable
valueFormat={node.format}
/>
)}
/>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TextInput } from "@mantine/core"
import { Controller } from "react-hook-form"
import { DateFieldNode, dateFieldNodeSchema } from "~/schemas/structure"
import { DateDefaultProperty } from "../properties/DateDefaultProperty"
import { DisabledProperty } from "../properties/DisabledProperty"
import { FieldIdProperty } from "../properties/FieldIdProperty"
import { HiddenProperty } from "../properties/HiddenProperty"
Expand Down Expand Up @@ -29,11 +30,6 @@ export const DateFieldPropertiesForm = ({ node }: DateFieldPropertiesFormProps)
<TextInput label="Format" value={value} onChange={onChange} error={error?.message} />
)}
/>
<Controller
name="default"
render={({ field: { value, onChange }, fieldState: { error } }) => (
<TextInput label="Default value" value={value} onChange={onChange} error={error?.message} />
)}
/>
<DateDefaultProperty node={node} />
</PropertiesForm>
)
1 change: 0 additions & 1 deletion src/schemas/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const numberFieldNodeSchema = nodeSchema.extend({

export type NumberFieldNode = z.infer<typeof numberFieldNodeSchema>

// TODO: refine default
export const dateFieldNodeSchema = nodeSchema.extend({
type: z.literal("DateField"),
...fieldProperties,
Expand Down

0 comments on commit 436a3ff

Please sign in to comment.