Skip to content

Commit

Permalink
misc: cleanup of form display structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sheensantoscapadngan committed Jul 2, 2024
1 parent ce5dbca commit 398a8f3
Showing 1 changed file with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,38 @@ export const AddWebhookForm = ({

const webhookType = watch("type");

const generalFormFields = (
<>
<FormControl
label="Secret Key"
isError={Boolean(errors?.webhookSecretKey)}
errorText={errors?.webhookSecretKey?.message}
helperText="To generate webhook signature for verification"
>
<Input placeholder="Provided during webhook setup" {...register("webhookSecretKey")} />
</FormControl>
<FormControl
label="Webhook URL"
isRequired
isError={Boolean(errors?.webhookUrl)}
errorText={errors?.webhookUrl?.message}
>
<Input {...register("webhookUrl")} />
</FormControl>
</>
);

const slackFormFields = (
<FormControl
label="Incoming Webhook URL"
isRequired
isError={Boolean(errors?.webhookUrl)}
errorText={errors?.webhookUrl?.message}
>
<Input placeholder="https://hooks.slack.com/services/..." {...register("webhookUrl")} />
</FormControl>
);

useEffect(() => {
if (!isOpen) {
reset();
Expand Down Expand Up @@ -146,32 +178,7 @@ export const AddWebhookForm = ({
{...register("secretPath")}
/>
</FormControl>
{webhookType === WebhookType.GENERAL && (
<FormControl
label="Secret Key"
isError={Boolean(errors?.webhookSecretKey)}
errorText={errors?.webhookSecretKey?.message}
helperText="To generate webhook signature for verification"
>
<Input
placeholder="Provided during webhook setup"
{...register("webhookSecretKey")}
/>
</FormControl>
)}
<FormControl
label={webhookType === WebhookType.SLACK ? "Incoming Webhook URL" : "Webhook URL"}
isRequired
isError={Boolean(errors?.webhookUrl)}
errorText={errors?.webhookUrl?.message}
>
<Input
placeholder={
webhookType === WebhookType.SLACK ? "https://hooks.slack.com/services/..." : ""
}
{...register("webhookUrl")}
/>
</FormControl>
{webhookType === WebhookType.SLACK ? slackFormFields : generalFormFields}
</div>
<div className="mt-8 flex items-center">
<Button
Expand Down

0 comments on commit 398a8f3

Please sign in to comment.