Skip to content

Commit

Permalink
feat: 🎸 Disable init message on bubble
Browse files Browse the repository at this point in the history
  • Loading branch information
OdapX committed Oct 4, 2023
1 parent 40125e1 commit 1decf8d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion components/AgentInputs/CommonInterfaceInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import { useFormContext } from 'react-hook-form';

import Input from '@app/components/Input';

import InitialBubbleMessageCheckbox from './InitialBubbleMessageCheckbox';
import InitMessageInput from './InitMessageInput';
import SuggestionsInput from './SuggestionsInput';

type Props = {};

export default function CommonInterfaceInput(props: Props) {
const { watch, control, register, setValue } = useFormContext();
const { watch, control, register } = useFormContext();

const config = watch('interfaceConfig');

return (
<>
<InitMessageInput />
<InitialBubbleMessageCheckbox />
<SuggestionsInput />
<Input
control={control}
Expand Down
28 changes: 28 additions & 0 deletions components/AgentInputs/InitialBubbleMessageCheckbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Checkbox, Stack, Typography } from "@mui/joy";
import { useFormContext } from "react-hook-form";

function InitialBubbleMessageCheckbox({ labelText = "Hide initial message on chat bubble" }) {
const { register, setValue, getValues } = useFormContext();
const { interfaceConfig } = getValues()
const handleCheckboxChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setValue('interfaceConfig.isInitMessagePopupDisabled', e.target.checked, {
shouldDirty: true,
shouldValidate: true,
});
};
return (
<Stack direction="row" spacing={1} alignItems="center">
<Checkbox
{...register('interfaceConfig.isInitMessagePopupDisabled')}
onChange={handleCheckboxChange}
checked={Boolean(interfaceConfig?.isInitMessagePopupDisabled)}
aria-label={labelText}
/>
<Typography>{labelText}</Typography>
</Stack>
);
}



export default InitialBubbleMessageCheckbox;
2 changes: 1 addition & 1 deletion components/ChatBubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function App(props: { agentId: string; initConfig?: AgentInterfaceConfig }) {
}, [props.agentId]);

useEffect(() => {
if (state.config?.initialMessage) {
if (state.config?.initialMessage && !state.config?.isInitMessagePopupDisabled) {
setTimeout(() => {
setState({
showInitialMessage: true,
Expand Down
1 change: 1 addition & 0 deletions types/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const AgentInterfaceConfig = z.object({
})
.optional(),
initialMessage: z.string().trim().optional(),
isInitMessagePopupDisabled: z.boolean().optional(),
messageTemplates: z.array(z.string()).optional(),
position: z.enum(['left', 'right']).optional(),
authorizedDomains: z.array(z.string()).optional(),
Expand Down

0 comments on commit 1decf8d

Please sign in to comment.