Skip to content

Commit d7513d1

Browse files
committed
refactor: update importConfig function to accept File directly and enhance file input component in subscription page builder header
1 parent ed530d3 commit d7513d1

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/pages/dashboard/utils/subscription-page-builder/ui/components/subscription-page-builder.page.component.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ export const SubscriptionPageBuilderComponent = () => {
115115
linkElement.click()
116116
}
117117

118-
const importConfig = (event: React.ChangeEvent<HTMLInputElement>) => {
119-
setLoading(true)
120-
121-
const file = event.target.files?.[0]
118+
const importConfig = (file: File | null) => {
122119
if (!file) {
123-
setLoading(false)
124120
return
125121
}
126122

123+
setLoading(true)
124+
127125
const reader = new FileReader()
128126
reader.onload = (e) => {
129127
try {
@@ -270,14 +268,14 @@ export const SubscriptionPageBuilderComponent = () => {
270268
</Grid.Col>
271269
</Grid>
272270

273-
<Modal onClose={close} opened={opened} size="lg" title="Validation errors">
271+
<Modal centered onClose={close} opened={opened} size="lg" title="Validation errors">
274272
<Alert
275273
color="red"
276274
icon={<IconAlertCircle size="1rem" />}
277275
mb="md"
278276
title="Invalid configuration"
279277
>
280-
The configuration did not pass validation. The following errors are listed.
278+
The configuration did not pass validation.
281279
</Alert>
282280
<ScrollArea h={300} offsetScrollbars>
283281
<Stack gap="xs">

src/widgets/dashboard/utils/subscription-page-builder-header/subscription-page-builder-header.widget.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { IconCloudDownload, IconDownload, IconUpload } from '@tabler/icons-react'
2-
import { Accordion, Button, Group, Text } from '@mantine/core'
2+
import { Accordion, Button, FileInput, Group, Text } from '@mantine/core'
33
import { PiInfoDuotone } from 'react-icons/pi'
44

55
import { DataTableShared } from '@shared/ui/table'
66

77
export function SubscriptionPageBuilderHeaderWidget(props: {
88
exportConfig: () => void
9-
importConfig: (event: React.ChangeEvent<HTMLInputElement>) => void
9+
importConfig: (file: File | null) => void
1010
loadDefaultConfig: () => Promise<void>
1111
}) {
1212
const { exportConfig, importConfig, loadDefaultConfig } = props
@@ -28,15 +28,14 @@ export function SubscriptionPageBuilderHeaderWidget(props: {
2828
Export Config
2929
</Button>
3030

31-
<Button component="label" leftSection={<IconUpload size="1rem" />}>
32-
Import Config
33-
<input
34-
accept=".json"
35-
onChange={importConfig}
36-
style={{ display: 'none' }}
37-
type="file"
38-
/>
39-
</Button>
31+
<FileInput
32+
accept="application/json,.json"
33+
clearable
34+
leftSection={<IconUpload size="1rem" />}
35+
onChange={importConfig}
36+
placeholder="Upload Config"
37+
radius="lg"
38+
/>
4039
</Group>
4140
}
4241
title="Subscription Page Builder"

0 commit comments

Comments
 (0)