Skip to content

Commit

Permalink
fix: refactor config contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Dec 17, 2023
1 parent 40ae671 commit 57b52da
Show file tree
Hide file tree
Showing 29 changed files with 1,035 additions and 694 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-moose-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/design-system': minor
---

Refactor hooks used in server synced configuration features.
21 changes: 21 additions & 0 deletions apps/hostd/components/Config/StateConnError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Button, Text } from '@siafoundation/design-system'
import { Warning32 } from '@siafoundation/react-icons'
import { useConfig } from '../../contexts/config'

export function StateConnError() {
const { revalidateAndResetForm } = useConfig()
return (
<div className="flex flex-col gap-10 justify-center items-center h-[400px] cursor-pointer">
<Text>
<Warning32 className="scale-[200%]" />
</Text>
<div className="flex flex-col gap-3 items-center">
<Text color="subtle" className="text-center max-w-[500px]">
Error retrieving settings from daemon. Please check your connection
and try again.
</Text>
<Button onClick={() => revalidateAndResetForm()}>Reload</Button>
</div>
</div>
)
}
86 changes: 46 additions & 40 deletions apps/hostd/components/Config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { HostdAuthedLayout } from '../../components/HostdAuthedLayout'
import { AnnounceButton } from './AnnounceButton'
import { useConfig } from '../../contexts/config'
import { ConfigNav } from './ConfigNav'
import { StateConnError } from './StateConnError'

export function Config() {
const { openDialog } = useDialog()
Expand All @@ -20,9 +21,10 @@ export function Config() {
settings,
dynDNSCheck,
changeCount,
revalidateAndResetFormData,
revalidateAndResetForm,
form,
onSubmit,
remoteError,
} = useConfig()
return (
<HostdAuthedLayout
Expand Down Expand Up @@ -63,7 +65,7 @@ export function Config() {
tip="Reset all changes"
icon="contrast"
disabled={!changeCount}
onClick={revalidateAndResetFormData}
onClick={revalidateAndResetForm}
>
<Reset16 />
</Button>
Expand All @@ -81,44 +83,48 @@ export function Config() {
}
openSettings={() => openDialog('settings')}
>
<div className="p-6 flex flex-col gap-16 max-w-screen-xl">
<ConfigurationPanel
title="Host"
category="host"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="Pricing"
category="pricing"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="DNS"
category="DNS"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="Bandwidth"
category="bandwidth"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="Registry"
category="registry"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="Accounts"
category="RHP3"
fields={fields}
form={form}
/>
</div>
{remoteError ? (
<StateConnError />
) : (
<div className="p-6 flex flex-col gap-16 max-w-screen-xl">
<ConfigurationPanel
title="Host"
category="host"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="Pricing"
category="pricing"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="DNS"
category="DNS"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="Bandwidth"
category="bandwidth"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="Registry"
category="registry"
fields={fields}
form={form}
/>
<ConfigurationPanel
title="Accounts"
category="RHP3"
fields={fields}
form={form}
/>
</div>
)}
</HostdAuthedLayout>
)
}
Loading

0 comments on commit 57b52da

Please sign in to comment.