export default function TalentMeetingProvider()

in src/providers/TalentMeetingProvider.tsx [153:200]


export default function TalentMeetingProvider(props: Props) {
  const { children, onLoad } = props;
  const verifiedParticipant = useVerifiedParticipantContext();
  const liveEvent = useLiveEventContext();
  const credentials = useContext(getCredentialsContext());
  const [talentMeetingService, setTalentMeetingService] = useState<
    TalentMeetingService
  >();

  useEffect(() => {
    if (!credentials.isAuthenticated || !credentials.authToken) {
      onLoad({
        error:
          'User must be authenticated to fetch the talent meeting details.',
      });
      return;
    }

    const service = new TalentMeetingService(
      liveEvent.liveEventId,
      credentials.authToken,
      verifiedParticipant.attendeeId
    );
    service
      ?.loadTalentMeeting()
      .then(() => {
        setTalentMeetingService(service);
        onLoad({});
      })
      .catch(e => {
        setTalentMeetingService(service);
        onLoad({
          error: `Error getting talent meeting details: ${e}`,
        });
      });
  }, [verifiedParticipant]);

  if (talentMeetingService) {
    return (
      <TalentMeetingContext.Provider value={talentMeetingService}>
        {children}
      </TalentMeetingContext.Provider>
    );
  }

  // Don't render until the talentMeetingService is instantiated and we've loaded the talentMeeting.
  return <CenteredLoadingSpinner />;
}