|
1 | | -import { getOrgSchemaMessage, type WebChatActivity } from 'botframework-webchat-core'; |
| 1 | +import { reactNode, validateProps } from '@msinternal/botframework-webchat-react-valibot'; |
2 | 2 | import { PartGrouping } from 'botframework-webchat-component/internal'; |
| 3 | +import { getOrgSchemaMessage, type WebChatActivity } from 'botframework-webchat-core'; |
3 | 4 | import cx from 'classnames'; |
4 | | -import React, { memo, useMemo } from 'react'; |
| 5 | +import React, { memo, useMemo, type ReactNode } from 'react'; |
| 6 | +import { array, custom, object, optional, pipe, readonly, safeParse } from 'valibot'; |
5 | 7 |
|
6 | | -import CopilotMessageHeader from './CopilotMessageHeader'; |
7 | 8 | import useVariants from '../../private/useVariants'; |
8 | 9 | import { useStyles, useVariantClassName } from '../../styles'; |
| 10 | +import CopilotMessageHeader from './CopilotMessageHeader'; |
9 | 11 |
|
10 | 12 | import styles from './PartGroupingDecorator.module.css'; |
11 | 13 |
|
12 | | -type PartGroupingDecoratorProps = Readonly<{ |
13 | | - activities: readonly WebChatActivity[]; |
14 | | - children?: React.ReactNode; |
15 | | -}>; |
| 14 | +const partGroupingDecoratorPropsSchema = pipe( |
| 15 | + object({ |
| 16 | + activities: pipe(array(custom<WebChatActivity>(value => safeParse(object({}), value).success)), readonly()), |
| 17 | + children: optional(reactNode()) |
| 18 | + }), |
| 19 | + readonly() |
| 20 | +); |
| 21 | + |
| 22 | +// TODO: [P2] InferInput does not add the required readonly, need to have a better way to define props. |
| 23 | +type PartGroupingDecoratorProps = { |
| 24 | + readonly activities: readonly WebChatActivity[]; |
| 25 | + readonly children?: ReactNode | undefined; |
| 26 | +}; |
16 | 27 |
|
17 | 28 | function PartGroupingDecorator(props: PartGroupingDecoratorProps) { |
18 | 29 | const { |
19 | 30 | activities: [activity, ...restActivities] |
20 | | - } = props; |
| 31 | + } = validateProps(partGroupingDecoratorPropsSchema, props); |
| 32 | + |
21 | 33 | const variants = useVariants(); |
22 | 34 | const classNames = useStyles(styles); |
23 | 35 | const variantClassName = useVariantClassName(styles); |
|
0 commit comments