Enforce required prop in default tags.

This commit is contained in:
muzam1l
2022-07-28 18:12:58 +05:30
parent df0f8abe62
commit ca52a5e064
2 changed files with 11 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useState } from "react"; import React, { useCallback, useEffect, useState } from "react";
import { Plus, Trash, X } from "phosphor-react"; import { Plus, Trash, X } from "phosphor-react";
import { Button, Box } from "."; import { Button, Box, Text } from ".";
import { Stack, Flex, Select } from "."; import { Stack, Flex, Select } from ".";
import { import {
Dialog, Dialog,
@@ -30,6 +30,7 @@ import {
transactionOptions, transactionOptions,
SetHookData, SetHookData,
} from "../utils/setHook"; } from "../utils/setHook";
import { capitalize } from "../utils/helpers";
export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo( export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
({ accountAddress }) => { ({ accountAddress }) => {
@@ -250,6 +251,7 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
<Input <Input
// important to include key with field's id // important to include key with field's id
placeholder="Parameter name" placeholder="Parameter name"
readOnly={field.$metaData?.required}
{...register( {...register(
`HookParameters.${index}.HookParameter.HookParameterName` `HookParameters.${index}.HookParameter.HookParameterName`
)} )}
@@ -258,7 +260,8 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
css={{ mx: "$2" }} css={{ mx: "$2" }}
placeholder="Value (hex-quoted)" placeholder="Value (hex-quoted)"
{...register( {...register(
`HookParameters.${index}.HookParameter.HookParameterValue` `HookParameters.${index}.HookParameter.HookParameterValue`,
{ required: field.$metaData?.required }
)} )}
/> />
<Button <Button
@@ -268,8 +271,12 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
<Trash weight="regular" size="16px" /> <Trash weight="regular" size="16px" />
</Button> </Button>
</Flex> </Flex>
{errors.HookParameters?.[index]?.HookParameter
?.HookParameterValue?.type === "required" && (
<Text error>This field is required</Text>
)}
<Label css={{ fontSize: "$sm", mt: "$1" }}> <Label css={{ fontSize: "$sm", mt: "$1" }}>
{field.$metaData?.description} {capitalize(field.$metaData?.description)}
</Label> </Label>
</Flex> </Flex>
</Stack> </Stack>

View File

@@ -42,6 +42,7 @@ export const getParameters = (content?: string) => {
}, },
$metaData: { $metaData: {
description: tag.description, description: tag.description,
required: !tag.optional
}, },
})); }));