mirror of
https://github.com/hexastack/hexabot
synced 2025-04-18 21:35:06 +00:00
fix: btn display
This commit is contained in:
parent
84f25ecfb1
commit
6e7200dfba
@ -41,7 +41,7 @@ export const ToggleableInput = forwardRef(
|
||||
}, [readOnlyValue, isDisabled, defaultValue]);
|
||||
|
||||
return (
|
||||
<Box display="flex">
|
||||
<Box display="flex" flex={1}>
|
||||
<Switch
|
||||
onChange={() => {
|
||||
const newIsDisabled = !isDisabled;
|
||||
|
@ -166,7 +166,7 @@ const ListMessageForm = () => {
|
||||
</ContentItem>
|
||||
</Grid>
|
||||
<Grid item xs={1}>
|
||||
<Divider orientation="vertical" sx={{ margin: "2rem" }} />
|
||||
<Divider orientation="vertical" sx={{ marginX: "2rem" }} />
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<FormLabel component="h4" sx={{ marginBottom: "1rem" }}>
|
||||
@ -278,7 +278,7 @@ const ListMessageForm = () => {
|
||||
/>
|
||||
</ContentItem>
|
||||
</Grid>
|
||||
<ContentItem>
|
||||
<ContentItem width="100%">
|
||||
<FormSectionTitle title={t("label.buttons")} Icon={ButtonsIcon} />
|
||||
<Controller
|
||||
name="options.content.buttons"
|
||||
|
@ -6,7 +6,7 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { Grid } from "@mui/material";
|
||||
import { Box } from "@mui/material";
|
||||
import { FC } from "react";
|
||||
import { FieldPath, useFormContext } from "react-hook-form";
|
||||
|
||||
@ -48,88 +48,86 @@ const ButtonInput: FC<ButtonInputProps> = ({
|
||||
} = useFormContext<IBlockAttributes>();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Grid item xs={5}>
|
||||
<Box display="flex" flex={1} flexGrow={1} gap={2}>
|
||||
<Input
|
||||
fullWidth={false}
|
||||
required
|
||||
label={t("label.title")}
|
||||
value={button.title}
|
||||
sx={{ flex: 1 }}
|
||||
inputProps={{
|
||||
maxLength: 20,
|
||||
}}
|
||||
{...register(buildFieldPath(fieldPath, idx, "title"), {
|
||||
required: t("message.title_is_required"),
|
||||
})}
|
||||
onChange={(e) => {
|
||||
onChange({ ...button, title: e.target.value });
|
||||
}}
|
||||
error={!!errors.message?.["buttons"]?.[idx]?.title}
|
||||
helperText={
|
||||
errors.message?.["buttons"]?.[idx]?.title?.message ||
|
||||
(button.title.length === 20
|
||||
? t("message.title_length_exceeded")
|
||||
: null)
|
||||
}
|
||||
/>
|
||||
{button.type === ButtonType.postback ? (
|
||||
<ToggleableInput
|
||||
defaultValue={button.payload}
|
||||
readOnlyValue={button.title}
|
||||
{...register(buildFieldPath(fieldPath, idx, "payload"), {
|
||||
validate: {
|
||||
required: (value) => {
|
||||
if (disablePayload || value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return t("message.payload_is_required");
|
||||
},
|
||||
},
|
||||
})}
|
||||
onChange={(payload) =>
|
||||
onChange({
|
||||
...button,
|
||||
payload,
|
||||
})
|
||||
}
|
||||
disabled={disablePayload}
|
||||
error={!!errors.message?.["buttons"]?.[idx]?.payload}
|
||||
helperText={errors.message?.["buttons"]?.[idx]?.payload?.message}
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
fullWidth
|
||||
required
|
||||
placeholder={t("label.title")}
|
||||
value={button.title}
|
||||
inputProps={{
|
||||
maxLength: 20,
|
||||
}}
|
||||
{...register(buildFieldPath(fieldPath, idx, "title"), {
|
||||
required: t("message.title_is_required"),
|
||||
type="url"
|
||||
label={t("label.url")}
|
||||
value={button.url}
|
||||
sx={{ flex: 1 }}
|
||||
{...register(buildFieldPath(fieldPath, idx, "url"), {
|
||||
validate: {
|
||||
required: (value) => {
|
||||
if (
|
||||
button.type === ButtonType.web_url &&
|
||||
(disablePayload || value)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return t("message.url_is_required");
|
||||
},
|
||||
},
|
||||
...rules.url,
|
||||
})}
|
||||
onChange={(e) => {
|
||||
onChange({ ...button, title: e.target.value });
|
||||
onChange({ ...button, url: e.target.value });
|
||||
}}
|
||||
error={!!errors.message?.["buttons"]?.[idx]?.title}
|
||||
helperText={
|
||||
errors.message?.["buttons"]?.[idx]?.title?.message ||
|
||||
(button.title.length === 20
|
||||
? t("message.title_length_exceeded")
|
||||
: null)
|
||||
}
|
||||
disabled={disablePayload}
|
||||
error={!!errors.message?.["buttons"]?.[idx]?.url}
|
||||
helperText={errors.message?.["buttons"]?.[idx]?.url?.message}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
{button.type === ButtonType.postback ? (
|
||||
<ToggleableInput
|
||||
defaultValue={button.payload}
|
||||
readOnlyValue={button.title}
|
||||
{...register(buildFieldPath(fieldPath, idx, "payload"), {
|
||||
validate: {
|
||||
required: (value) => {
|
||||
if (disablePayload || value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return t("message.payload_is_required");
|
||||
},
|
||||
},
|
||||
})}
|
||||
onChange={(payload) =>
|
||||
onChange({
|
||||
...button,
|
||||
payload,
|
||||
})
|
||||
}
|
||||
disabled={disablePayload}
|
||||
error={!!errors.message?.["buttons"]?.[idx]?.payload}
|
||||
helperText={errors.message?.["buttons"]?.[idx]?.payload?.message}
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
required
|
||||
type="ur"
|
||||
placeholder="URL"
|
||||
value={button.url}
|
||||
{...register(buildFieldPath(fieldPath, idx, "url"), {
|
||||
validate: {
|
||||
required: (value) => {
|
||||
if (
|
||||
button.type === ButtonType.web_url &&
|
||||
(disablePayload || value)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return t("message.url_is_required");
|
||||
},
|
||||
},
|
||||
...rules.url,
|
||||
})}
|
||||
onChange={(e) => {
|
||||
onChange({ ...button, url: e.target.value });
|
||||
}}
|
||||
disabled={disablePayload}
|
||||
error={!!errors.message?.["buttons"]?.[idx]?.url}
|
||||
helperText={errors.message?.["buttons"]?.[idx]?.url?.message}
|
||||
/>
|
||||
)}
|
||||
</Grid>
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
import { KeyboardReturn, Link, RemoveCircleOutline } from "@mui/icons-material";
|
||||
import AddIcon from "@mui/icons-material/Add";
|
||||
import { Box, Grid, IconButton } from "@mui/material";
|
||||
import { FC, Fragment, useEffect, useMemo, useState } from "react";
|
||||
import { Box, IconButton } from "@mui/material";
|
||||
import { FC, useEffect, useMemo, useState } from "react";
|
||||
import { FieldPath } from "react-hook-form";
|
||||
|
||||
import DropdownButton, {
|
||||
@ -96,19 +96,10 @@ const ButtonsInput: FC<ButtonsInput> = ({
|
||||
}, [buttons]);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs={5}>
|
||||
{t("label.title")}
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
{t("label.payload")} / {t("label.url")}
|
||||
</Grid>
|
||||
<Grid item xs={1}>
|
||||
|
||||
</Grid>
|
||||
<Box display="flex" flexDirection="column">
|
||||
<Box display="flex" flexDirection="column">
|
||||
{buttons.map(({ value, id }, idx) => (
|
||||
<Fragment key={id}>
|
||||
<Box display="flex" flex={1} mt={2} key={id}>
|
||||
<ButtonInput
|
||||
fieldPath={fieldPath}
|
||||
idx={idx}
|
||||
@ -116,20 +107,18 @@ const ButtonsInput: FC<ButtonsInput> = ({
|
||||
onChange={updateInput(idx)}
|
||||
disablePayload={disablePayload}
|
||||
/>
|
||||
<Grid item xs={1}>
|
||||
<IconButton
|
||||
color="error"
|
||||
onClick={() => removeInput(idx)}
|
||||
disabled={buttons.length <= minInput}
|
||||
>
|
||||
<RemoveCircleOutline />
|
||||
</IconButton>
|
||||
</Grid>
|
||||
</Fragment>
|
||||
<IconButton
|
||||
color="error"
|
||||
onClick={() => removeInput(idx)}
|
||||
disabled={buttons.length <= minInput}
|
||||
>
|
||||
<RemoveCircleOutline />
|
||||
</IconButton>
|
||||
</Box>
|
||||
))}
|
||||
</Grid>
|
||||
</Box>
|
||||
<DropdownButton
|
||||
sx={{ m: 1, float: "right", padding: "16px" }}
|
||||
sx={{ alignSelf: "end", marginTop: 2 }}
|
||||
label={t("button.add_button")}
|
||||
actions={actions}
|
||||
onClick={(action) => addInput(action.defaultValue)}
|
||||
|
Loading…
Reference in New Issue
Block a user