Skip to content

Commit 8be0df7

Browse files
committed
Add schema
1 parent 8b75fc3 commit 8be0df7

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

packages/component/src/ActivityStatus/private/Originator.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
1+
import { validateProps } from '@msinternal/botframework-webchat-react-valibot';
12
import { type OrgSchemaProject } from 'botframework-webchat-core';
23
import React, { memo } from 'react';
4+
import { custom, object, optional, pipe, readonly, safeParse, string, type InferInput } from 'valibot';
35

46
import 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) => {
3154
Originator.displayName = 'Originator';
3255

3356
export default Originator;
57+
export { originatorPropsSchema, type OriginatorProps };

0 commit comments

Comments
 (0)