1+ import { validateProps } from '@msinternal/botframework-webchat-react-valibot' ;
12import { type OrgSchemaProject } from 'botframework-webchat-core' ;
23import React , { memo } from 'react' ;
4+ import { custom , object , optional , pipe , readonly , safeParse , string , type InferInput } from 'valibot' ;
35
46import useSanitizeHrefCallback from '../../hooks/internal/useSanitizeHrefCallback' ;
57
6- type Props = Readonly < { project : OrgSchemaProject } > ;
8+ const originatorPropsSchema = pipe (
9+ object ( {
10+ // TODO: [P1] We should build this schema into `OrgSchemaProject` instead, or build a Schema.org query library.
11+ project : custom < OrgSchemaProject > (
12+ value =>
13+ safeParse (
14+ object ( {
15+ name : optional ( string ( ) ) ,
16+ slogan : optional ( string ( ) ) ,
17+ url : optional ( string ( ) )
18+ } ) ,
19+ value
20+ ) . success
21+ )
22+ } ) ,
23+ readonly ( )
24+ ) ;
725
8- const Originator = memo ( ( { project } : Props ) => {
9- const { name, slogan, url } = project ;
10- const sanitizeLink = useSanitizeHrefCallback ( ) ;
26+ type OriginatorProps = InferInput < typeof originatorPropsSchema > ;
1127
12- const { sanitizedHref } = sanitizeLink ( url ) ;
28+ const Originator = memo ( ( props : OriginatorProps ) => {
29+ const {
30+ project : { name, slogan, url }
31+ } = validateProps ( originatorPropsSchema , props ) ;
32+
33+ const sanitizeHref = useSanitizeHrefCallback ( ) ;
34+
35+ const { sanitizedHref } = sanitizeHref ( url ) ;
1336 const text = slogan || name ;
1437
1538 return sanitizedHref ? (
@@ -31,3 +54,4 @@ const Originator = memo(({ project }: Props) => {
3154Originator . displayName = 'Originator' ;
3255
3356export default Originator ;
57+ export { originatorPropsSchema , type OriginatorProps } ;
0 commit comments