Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotificationBanner component - comp.setCollectionOptions is not a function #94

Closed
BhaskaranR opened this issue Jun 20, 2024 · 0 comments

Comments

@BhaskaranR
Copy link

I am using nextjs, dynamically loading the banner component with ssr set to false, not able to get the notification banner component to work

'use client'
import { env } from '@/env.mjs';
import { cn } from '@/lib/utils';
import { StripeConnectInstance, loadConnectAndInitialize } from "@stripe/connect-js/pure";

import {
  ConnectNotificationBanner,
  ConnectComponentsProvider,
} from '@stripe/react-connect-js';
import { useEffect, useState } from 'react';

export default function StripeNotificationBanner({ className }: { className?: string }) {
  const [isClient, setIsClient] = useState(false)
  const [stripeConnectInstance, setStripeConnectInstance] = useState<StripeConnectInstance | null>(null);

  useEffect(() => {
    setIsClient(true)
  }, [])


  useEffect(() => {
    if (isClient) {
      const loadStripeConnect = async () => {
        const fetchClientSecret = async () => {
          const response = await fetch('/api/v1/stripe/company_account_session', {
            method: 'POST',
          });
          if (!response.ok) {
            const { error } = await response.json();
            console.log('An error occurred: ', error);
            return undefined;
          } else {
            const { client_secret: clientSecret } = await response.json();
            return clientSecret;
          }
        };

        const instance = await loadConnectAndInitialize({
          publishableKey: env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY,
          fetchClientSecret,
        });

        setStripeConnectInstance(instance);
      };

      loadStripeConnect();
    }
  }, [isClient]);


  if (!isClient || !stripeConnectInstance) {
    return null;
  }

  return (
      <ConnectComponentsProvider connectInstance={stripeConnectInstance}>
        <ConnectNotificationBanner
          // Optional:
          // collectionOptions={{
          //   fields: 'eventually_due',
          //   futureRequirements: 'include',
          // }}
        />
      </ConnectComponentsProvider>)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant