-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
112 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import NoisyContainer from '@/components/common/NoisyContainer/styles' | ||
import { AddFunctionCapabilitiesProps } from './types' | ||
import { useAddFunctionCapabilities } from '@/hooks/form/useAddFunctionCapabilities' | ||
import { Checkbox, CheckboxGroup } from '@aleph-front/aleph-core' | ||
|
||
const AddFunctionCapabilities = (props: AddFunctionCapabilitiesProps) => { | ||
const { internetAccessCtrl, blockchainRPCCtrl, enableAutoSnapshotsCtrl } = | ||
useAddFunctionCapabilities(props) | ||
|
||
return ( | ||
<NoisyContainer> | ||
<Checkbox | ||
label="Outgoing internet access" | ||
tw="my-3" | ||
{...internetAccessCtrl.field} | ||
{...internetAccessCtrl.fieldState} | ||
/> | ||
|
||
<Checkbox | ||
label="Accessing blockchain RPC nodes" | ||
tw="my-3" | ||
{...blockchainRPCCtrl.field} | ||
{...blockchainRPCCtrl.fieldState} | ||
/> | ||
|
||
<Checkbox | ||
label="Enable automatic snapshots (not available yet)" | ||
tw="my-3" | ||
{...enableAutoSnapshotsCtrl.field} | ||
{...enableAutoSnapshotsCtrl.fieldState} | ||
disabled | ||
/> | ||
</NoisyContainer> | ||
) | ||
} | ||
|
||
export default AddFunctionCapabilities |
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,2 @@ | ||
export { default } from './cmp' | ||
export type { AddFunctionCapabilitiesProps } from './types' |
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,6 @@ | ||
import { Control } from 'react-hook-form' | ||
|
||
export type AddFunctionCapabilitiesProps = { | ||
name?: string | ||
control: Control | ||
} |
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,49 @@ | ||
import { Control, UseControllerReturn, useController } from 'react-hook-form' | ||
|
||
export const defaultCapabilities = { | ||
internetAccess: true, | ||
blockchainRPC: true, | ||
enableAutoSnapshots: false, | ||
} | ||
|
||
export type UseAddFunctionCapabilitiesProps = { | ||
name?: string | ||
control: Control | ||
defaultValue?: typeof defaultCapabilities | ||
} | ||
|
||
export type UseAddFunctionCapabilitiesReturn = { | ||
internetAccessCtrl: UseControllerReturn<any, any> | ||
blockchainRPCCtrl: UseControllerReturn<any, any> | ||
enableAutoSnapshotsCtrl: UseControllerReturn<any, any> | ||
} | ||
|
||
export function useAddFunctionCapabilities({ | ||
name = 'capabilities', | ||
control, | ||
defaultValue = defaultCapabilities, | ||
}: UseAddFunctionCapabilitiesProps): UseAddFunctionCapabilitiesReturn { | ||
const internetAccessCtrl = useController({ | ||
control, | ||
name: `${name}.internetAccess`, | ||
defaultValue: defaultValue?.internetAccess, | ||
}) | ||
|
||
const blockchainRPCCtrl = useController({ | ||
control, | ||
name: `${name}.internetAccess`, | ||
defaultValue: defaultValue?.blockchainRPC, | ||
}) | ||
|
||
const enableAutoSnapshotsCtrl = useController({ | ||
control, | ||
name: `${name}.internetAccess`, | ||
defaultValue: defaultValue?.enableAutoSnapshots, | ||
}) | ||
|
||
return { | ||
internetAccessCtrl, | ||
blockchainRPCCtrl, | ||
enableAutoSnapshotsCtrl, | ||
} | ||
} |