Skip to content

Commit

Permalink
refactor: more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Jan 30, 2024
1 parent af55731 commit a835ae1
Showing 1 changed file with 43 additions and 47 deletions.
90 changes: 43 additions & 47 deletions src/components/sectionList/listView/ManageListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type FormValues = {
columns: string[]
filters: string[]
}

const validate = (values: FormValues) => {
const errors: Record<string, string> = {}

Expand Down Expand Up @@ -91,53 +92,48 @@ export const ManageListView = ({
}, [savedFilters, savedColumns, filtersConfig, columnsConfig])

return (
<>
<Form
onSubmit={handleSave}
initialValues={initialValues}
validate={validate}
>
{({ handleSubmit, submitting, submitError }) => (
<form onSubmit={handleSubmit}>
<TransferField
name={'columns'}
availableLabel={i18n.t('Available columns')}
selectedLabel={i18n.t('Selected columns')}
loading={query.isLoading}
defaultOptions={columnsConfig.default.map(toPath)}
availableOptions={columnsConfig.available.map(
(c) => ({ label: c.label, value: c.path })
)}
/>
<TransferField
name={'filters'}
availableLabel={i18n.t('Available filters')}
selectedLabel={i18n.t('Selected filters')}
loading={query.isLoading}
defaultOptions={filtersConfig.default.map(
toFilterKey
)}
availableOptions={filtersConfig.available.map(
(f) => ({ label: f.label, value: f.filterKey })
)}
/>
{submitError && (
<p>
<NoticeBox
error
title={i18n.t('Failed to save')}
>
{submitError}
</NoticeBox>
</p>
)}
{children({
submitting,
})}
</form>
)}
</Form>
</>
<Form
onSubmit={handleSave}
initialValues={initialValues}
validate={validate}
>
{({ handleSubmit, submitting, submitError }) => (
<form onSubmit={handleSubmit}>
<TransferField
name={'columns'}
availableLabel={i18n.t('Available columns')}
selectedLabel={i18n.t('Selected columns')}
loading={query.isLoading}
defaultOptions={columnsConfig.default.map(toPath)}
availableOptions={columnsConfig.available.map((c) => ({
label: c.label,
value: c.path,
}))}
/>
<TransferField
name={'filters'}
availableLabel={i18n.t('Available filters')}
selectedLabel={i18n.t('Selected filters')}
loading={query.isLoading}
defaultOptions={filtersConfig.default.map(toFilterKey)}
availableOptions={filtersConfig.available.map((f) => ({
label: f.label,
value: f.filterKey,
}))}
/>
{submitError && (
<p>
<NoticeBox error title={i18n.t('Failed to save')}>
{submitError}
</NoticeBox>
</p>
)}
{children({
submitting,
})}
</form>
)}
</Form>
)
}

Expand Down

0 comments on commit a835ae1

Please sign in to comment.