Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
fix: fixing the docs app (COR-4237) (#460)
Browse files Browse the repository at this point in the history
<!-- You can erase any parts of this template not applicable to your Pull Request. -->

**Fixes or implements VF-XXX**

### Brief description. What is this change?

<!-- Build up some context for your teammates on the changes made here and potential tradeoffs made and/or highlight any topics for discussion -->

### Implementation details. How do you make this change?

<!-- Explain the way/approach you follow to make this change more deeply in order to help your teammates to understand much easier this change -->

### Setup information

<!-- Notes regarding local environment. These should note any new configurations, new environment variables, etc. -->

### Deployment Notes

<!-- Notes regarding deployment the contained body of work. These should note any db migrations, etc. -->

### Related PRs

<!-- List related PRs against other branches -->

- https://github.com/voiceflow/XXXXXXXXX/pull/123

### Checklist

- [ ] Breaking changes have been communicated, including:
    - New required environment variables
    - Renaming of interfaces (API routes, request/response interface, etc)
- [ ] New environment variables have [been deployed](https://www.notion.so/voiceflow/Add-Environment-Variables-be1b0136479f45f1adece7995a7adbfb)
- [ ] Appropriate tests have been written
    - Bug fixes are accompanied by an updated or new test
    - New features are accompanied by a new test
  • Loading branch information
gillyb committed Dec 13, 2024
1 parent 3f12d9b commit 378e328
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions apps/documentation/src/components/StoryEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@ import type { StoryObj } from '@storybook/react';
import type { DecoratorFunction } from '@storybook/types';
import { useEffect, useMemo, useState } from 'react';

const Stories = typeof window !== 'undefined' ? require('@voiceflow/react-chat/stories') : {};

const ComponentNotFound: React.FC = () => <h2>🚨 Component not found! 🚨</h2>;

export interface IStoryEmbed {
for: keyof typeof Stories;
for: string; // This should be `keyof type Stories` but we load this dynamically
name: string;
props?: Record<string, any>;
clientOnly?: boolean;
}

export const StoryEmbed: React.FC<IStoryEmbed> = ({ for: componentName, name, props, clientOnly = false }) => {
const module = Stories[componentName];
const target = (module as any)?.[name] as StoryObj<any>;
const [shouldRender, setShouldRender] = useState(!clientOnly);
const [stories, setStories] = useState<any>();

const decorators = useMemo(
() => (target?.decorators || module?.default.decorators || []) as DecoratorFunction<any>[],
[target?.decorators, module?.default.decorators]
);
useEffect(() => {
const initStories = async () => {
setStories(await import('@voiceflow/react-chat/stories'));
};
initStories();
}, []);

useEffect(() => setShouldRender(true), []);
if (!stories) return null;

const module = stories[componentName] as any;
const target = (module as any)?.[name] as StoryObj<any>;

const decorators = (target?.decorators || module?.default.decorators || []) as DecoratorFunction<any>[];

if (!shouldRender) return null;

Expand Down

0 comments on commit 378e328

Please sign in to comment.