fix #7830
This commit is contained in:
parent
60929c34f3
commit
72b8a70da2
@ -44,7 +44,7 @@ export function InputSelector<T>({
|
|||||||
fromStr = defaultFromString,
|
fromStr = defaultFromString,
|
||||||
toStr = defaultToString,
|
toStr = defaultToString,
|
||||||
}: Props<keyof T>): VNode {
|
}: Props<keyof T>): VNode {
|
||||||
const { error, value, onChange } = useField<T>(name);
|
const { error, value, onChange, required } = useField<T>(name);
|
||||||
return (
|
return (
|
||||||
<div class="field is-horizontal">
|
<div class="field is-horizontal">
|
||||||
<div class="field-label is-normal">
|
<div class="field-label is-normal">
|
||||||
@ -58,8 +58,8 @@ export function InputSelector<T>({
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="field-body is-flex-grow-3">
|
<div class="field-body is-flex-grow-3">
|
||||||
<div class="field">
|
<div class="field has-icons-right">
|
||||||
<p class={expand ? "control is-expanded select" : "control select"}>
|
<p class={expand ? "control is-expanded select" : "control select "}>
|
||||||
<select
|
<select
|
||||||
class={error ? "select is-danger" : "select"}
|
class={error ? "select is-danger" : "select"}
|
||||||
name={String(name)}
|
name={String(name)}
|
||||||
@ -78,8 +78,14 @@ export function InputSelector<T>({
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
{help}
|
{help}
|
||||||
</p>
|
</p>
|
||||||
|
{required && (
|
||||||
|
<span class="icon has-text-danger is-right" style={{height: "2.5em"}}>
|
||||||
|
<i class="mdi mdi-alert" />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
{error && <p class="help is-danger">{error}</p>}
|
{error && <p class="help is-danger">{error}</p>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1331,12 +1331,13 @@ export namespace MerchantBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace Webhooks {
|
namespace Webhooks {
|
||||||
|
type MerchantWebhookType = "pay" | "refund";
|
||||||
interface WebhookAddDetails {
|
interface WebhookAddDetails {
|
||||||
// Webhook ID to use.
|
// Webhook ID to use.
|
||||||
webhook_id: string;
|
webhook_id: string;
|
||||||
|
|
||||||
// The event of the webhook: why the webhook is used.
|
// The event of the webhook: why the webhook is used.
|
||||||
event_type: string;
|
event_type: MerchantWebhookType;
|
||||||
|
|
||||||
// URL of the webhook where the customer will be redirected.
|
// URL of the webhook where the customer will be redirected.
|
||||||
url: string;
|
url: string;
|
||||||
|
@ -33,6 +33,7 @@ import { InputDuration } from "../../../../components/form/InputDuration.js";
|
|||||||
import { InputNumber } from "../../../../components/form/InputNumber.js";
|
import { InputNumber } from "../../../../components/form/InputNumber.js";
|
||||||
import { useBackendContext } from "../../../../context/backend.js";
|
import { useBackendContext } from "../../../../context/backend.js";
|
||||||
import { MerchantBackend } from "../../../../declaration.js";
|
import { MerchantBackend } from "../../../../declaration.js";
|
||||||
|
import { InputSelector } from "../../../../components/form/InputSelector.js";
|
||||||
|
|
||||||
type Entity = MerchantBackend.Webhooks.WebhookAddDetails;
|
type Entity = MerchantBackend.Webhooks.WebhookAddDetails;
|
||||||
|
|
||||||
@ -50,7 +51,9 @@ export function CreatePage({ onCreate, onBack }: Props): VNode {
|
|||||||
|
|
||||||
const errors: FormErrors<Entity> = {
|
const errors: FormErrors<Entity> = {
|
||||||
webhook_id: !state.webhook_id ? i18n.str`required` : undefined,
|
webhook_id: !state.webhook_id ? i18n.str`required` : undefined,
|
||||||
event_type: !state.event_type ? i18n.str`required` : undefined,
|
event_type: !state.event_type ? i18n.str`required`
|
||||||
|
: state.event_type !== "pay" && state.event_type !== "refund" ? i18n.str`it should be "pay" or "refund"`
|
||||||
|
: undefined,
|
||||||
http_method: !state.http_method
|
http_method: !state.http_method
|
||||||
? i18n.str`required`
|
? i18n.str`required`
|
||||||
: !validMethod.includes(state.http_method)
|
: !validMethod.includes(state.http_method)
|
||||||
@ -84,16 +87,30 @@ export function CreatePage({ onCreate, onBack }: Props): VNode {
|
|||||||
label={i18n.str`ID`}
|
label={i18n.str`ID`}
|
||||||
tooltip={i18n.str`Webhook ID to use`}
|
tooltip={i18n.str`Webhook ID to use`}
|
||||||
/>
|
/>
|
||||||
<Input<Entity>
|
<InputSelector
|
||||||
name="event_type"
|
name="event_type"
|
||||||
label={i18n.str`Event`}
|
label={i18n.str`Event`}
|
||||||
|
values={[
|
||||||
|
i18n.str`Choose one...`,
|
||||||
|
i18n.str`pay`,
|
||||||
|
i18n.str`refund`,
|
||||||
|
]}
|
||||||
tooltip={i18n.str`The event of the webhook: why the webhook is used`}
|
tooltip={i18n.str`The event of the webhook: why the webhook is used`}
|
||||||
/>
|
/>
|
||||||
<Input<Entity>
|
<InputSelector
|
||||||
name="http_method"
|
name="http_method"
|
||||||
label={i18n.str`Method`}
|
label={i18n.str`Method`}
|
||||||
|
values={[
|
||||||
|
i18n.str`Choose one...`,
|
||||||
|
i18n.str`GET`,
|
||||||
|
i18n.str`POST`,
|
||||||
|
i18n.str`PUT`,
|
||||||
|
i18n.str`PATCH`,
|
||||||
|
i18n.str`HEAD`,
|
||||||
|
]}
|
||||||
tooltip={i18n.str`Method used by the webhook`}
|
tooltip={i18n.str`Method used by the webhook`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Input<Entity>
|
<Input<Entity>
|
||||||
name="url"
|
name="url"
|
||||||
label={i18n.str`URL`}
|
label={i18n.str`URL`}
|
||||||
|
Loading…
Reference in New Issue
Block a user