-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/AB#16730' into dev
- Loading branch information
Showing
13 changed files
with
501 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Button, FieldLabel, Text } from '@pzh-ui/components' | ||
import { Plus, Xmark } from '@pzh-ui/icons' | ||
import { | ||
ArrayHelpers, | ||
FieldArray as FormikFieldArray, | ||
FormikValues, | ||
useFormikContext, | ||
} from 'formik' | ||
|
||
import DynamicObjectField from '@/components/DynamicObject/DynamicObjectForm/DynamicField' | ||
import { Model } from '@/config/objects/types' | ||
import { DynamicField } from '@/config/types' | ||
|
||
const FieldArray = ({ | ||
name, | ||
label, | ||
arrayLabel, | ||
description, | ||
required, | ||
fields, | ||
model, | ||
}: Omit<Extract<DynamicField, { type: 'array' }>, 'type'> & { | ||
model: Model | ||
}) => { | ||
const { values } = useFormikContext<FormikValues>() | ||
|
||
const groupChildren: any[] = values?.[name] | ||
|
||
return ( | ||
<> | ||
{label && ( | ||
<FieldLabel | ||
name={name} | ||
label={label} | ||
description={description} | ||
required={required} | ||
/> | ||
)} | ||
|
||
<FormikFieldArray | ||
name={name} | ||
render={(arrayHelpers: ArrayHelpers) => ( | ||
<div className="flex flex-col gap-2"> | ||
{groupChildren?.map((child, childIndex) => ( | ||
<div | ||
key={name + child.type + childIndex} | ||
className="flex flex-col gap-2 bg-pzh-gray-100 p-4"> | ||
<div className="flex justify-between"> | ||
{!!arrayLabel && ( | ||
<Text bold>{arrayLabel}</Text> | ||
)} | ||
<button | ||
className="text-s text-pzh-green underline" | ||
onClick={() => | ||
arrayHelpers.remove(childIndex) | ||
} | ||
type="button"> | ||
<Xmark | ||
className="text-pzh-blue-dark" | ||
size={16} | ||
/> | ||
</button> | ||
</div> | ||
{fields.map(field => ( | ||
<DynamicObjectField | ||
key={field.name + childIndex} | ||
model={model} | ||
isFirst | ||
{...field} | ||
name={`${name}.${childIndex}.${field.name}`} | ||
/> | ||
))} | ||
</div> | ||
))} | ||
|
||
<div className="mt-2"> | ||
<Button | ||
icon={Plus} | ||
onPress={() => arrayHelpers.push({})}> | ||
Toevoegen | ||
</Button> | ||
</div> | ||
</div> | ||
)} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default FieldArray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './FieldArray' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...es/protected/PublicationTemplates/PublicationTemplateCreate/PublicationTemplateCreate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Heading } from '@pzh-ui/components' | ||
import { useMemo } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import DynamicObjectForm from '@/components/DynamicObject/DynamicObjectForm' | ||
import MutateLayout from '@/templates/MutateLayout' | ||
|
||
import { model } from '../model' | ||
|
||
const PublicationTemplateCreate = () => { | ||
const navigate = useNavigate() | ||
|
||
const { plural, pluralCapitalize, singularCapitalize } = model.defaults | ||
|
||
/** | ||
* Format initialData based on object fields | ||
*/ | ||
const initialData = useMemo(() => { | ||
const fields = model.dynamicSections.flatMap(section => | ||
section.fields.map(field => field.name) | ||
) | ||
|
||
const objectData = {} as { [key in (typeof fields)[number]]: any } | ||
|
||
fields?.forEach(field => { | ||
return (objectData[field] = null) | ||
}) | ||
|
||
return objectData | ||
}, []) | ||
|
||
const handleSubmit = () => {} | ||
|
||
const breadcrumbPaths = [ | ||
{ name: 'Dashboard', path: '/muteer' }, | ||
{ | ||
name: pluralCapitalize, | ||
path: `/muteer/${plural}`, | ||
}, | ||
{ name: `${singularCapitalize} toevoegen`, isCurrent: true }, | ||
] | ||
|
||
return ( | ||
<MutateLayout | ||
title={`${singularCapitalize} toevoegen`} | ||
breadcrumbs={breadcrumbPaths}> | ||
<div className="col-span-6"> | ||
<Heading level="1" size="xxl" className="mb-8"> | ||
{singularCapitalize} toevoegen | ||
</Heading> | ||
|
||
<DynamicObjectForm | ||
model={model} | ||
initialData={initialData} | ||
handleSubmit={handleSubmit} | ||
onCancel={() => navigate(`/muteer/${plural}`)} | ||
isLoading={false} | ||
/> | ||
</div> | ||
</MutateLayout> | ||
) | ||
} | ||
|
||
export default PublicationTemplateCreate |
1 change: 1 addition & 0 deletions
1
src/pages/protected/PublicationTemplates/PublicationTemplateCreate/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './PublicationTemplateCreate' |
66 changes: 66 additions & 0 deletions
66
src/pages/protected/PublicationTemplates/PublicationTemplateEdit/PublicationTemplateEdit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Heading } from '@pzh-ui/components' | ||
import { useMemo } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import DynamicObjectForm from '@/components/DynamicObject/DynamicObjectForm' | ||
import MutateLayout from '@/templates/MutateLayout' | ||
|
||
import { model } from '../model' | ||
|
||
const PublicationTemplateEdit = () => { | ||
const navigate = useNavigate() | ||
|
||
const { plural, pluralCapitalize, singularCapitalize } = model.defaults | ||
|
||
const data = useMemo(() => {}, []) | ||
|
||
/** | ||
* Format initialData based on object fields | ||
*/ | ||
const initialData = useMemo(() => { | ||
const fields = model.dynamicSections.flatMap(section => | ||
section.fields.map(field => field.name) | ||
) | ||
|
||
const objectData = {} as { [key in (typeof fields)[number]]: any } | ||
|
||
fields?.forEach(field => { | ||
return (objectData[field] = data?.[field as keyof typeof data]) | ||
}) | ||
|
||
return objectData | ||
}, [data]) | ||
|
||
const handleSubmit = () => {} | ||
|
||
const breadcrumbPaths = [ | ||
{ name: 'Dashboard', path: '/muteer' }, | ||
{ | ||
name: pluralCapitalize, | ||
path: `/muteer/${plural}`, | ||
}, | ||
{ name: `${singularCapitalize} bewerken`, isCurrent: true }, | ||
] | ||
|
||
return ( | ||
<MutateLayout | ||
title={`${singularCapitalize} bewerken`} | ||
breadcrumbs={breadcrumbPaths}> | ||
<div className="col-span-6"> | ||
<Heading level="1" size="xxl" className="mb-8"> | ||
{singularCapitalize} bewerken | ||
</Heading> | ||
|
||
<DynamicObjectForm | ||
model={model} | ||
initialData={initialData} | ||
handleSubmit={handleSubmit} | ||
onCancel={() => navigate(`/muteer/${plural}`)} | ||
isLoading={false} | ||
/> | ||
</div> | ||
</MutateLayout> | ||
) | ||
} | ||
|
||
export default PublicationTemplateEdit |
1 change: 1 addition & 0 deletions
1
src/pages/protected/PublicationTemplates/PublicationTemplateEdit/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './PublicationTemplateEdit' |
Oops, something went wrong.