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

Fix theming update issue #102

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions client/hooks/ConnectJsWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
} from '@stripe/connect-js';
import {ConnectComponentsProvider} from '@stripe/react-connect-js';
import {useSession} from './SessionProvider';
import {useColorMode} from './ColorModeProvider';
import {FullScreenLoading} from '../components/FullScreenLoading';
import {ErrorState} from '../components/ErrorState';
import useTheme from '@mui/system/useTheme';
import {Theme} from '@mui/system';

type AccountSession = {
clientSecret: string;
Expand Down Expand Up @@ -68,33 +68,35 @@ const useInitStripeConnect = (
export const ConnectJsWrapper = ({children}: {children: React.ReactNode}) => {
const {stripeAccount} = useSession();
const theme = useTheme();
const {mode} = useColorMode();
const appearance = {
// FurEver specifies a subset of the available options in ConnectJS
colorPrimary: theme.palette.primary.main,
colorText: theme.palette.text.primary,
colorBackground: theme.palette.background.default,
colorSecondaryText: theme.palette.text.secondary,
colorSecondaryLinkText: theme.palette.secondary.main,
colorBorder: theme.palette.border.main,
colorFormHighlightBorder: theme.palette.primary.main,
colorDanger: theme.palette.error.main,
colorSecondaryButtonBackground: theme.palette.neutral100.main,
colorSecondaryButtonBorder: theme.palette.border.main,
} as Record<string, string>; // TODO: Remove casting once we've shipped theming options to beta

const calculateCurrentAppearance = (currentTheme: Theme) => {
return {
// FurEver specifies a subset of the available options in ConnectJS
colorPrimary: currentTheme.palette.primary.main,
colorText: currentTheme.palette.text.primary,
colorBackground: currentTheme.palette.background.default,
colorSecondaryText: currentTheme.palette.text.secondary,
colorSecondaryLinkText: currentTheme.palette.secondary.main,
colorBorder: currentTheme.palette.border.main,
colorFormHighlightBorder: currentTheme.palette.primary.main,
colorDanger: currentTheme.palette.error.main,
colorSecondaryButtonBackground: currentTheme.palette.neutral100.main,
colorSecondaryButtonBorder: currentTheme.palette.border.main,
};
};

const {
data: connectInstance,
error,
isLoading,
refetch,
} = useInitStripeConnect(!!stripeAccount, appearance);
} = useInitStripeConnect(!!stripeAccount, calculateCurrentAppearance(theme));

React.useEffect(() => {
connectInstance?.update({
appearance,
appearance: {variables: calculateCurrentAppearance(theme)},
});
}, [mode]);
}, [theme]);

if (!stripeAccount) return <>{children}</>;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"source": "client/index.html",
"scripts": {
"build": "parcel build client/index.html && yarn typescript",
"clean": "rimraf dist",
"clean": "rimraf dist .parcel-cache",
"dev": "yarn clean && yarn typescript && yarn watch",
"server": "node dist/server/server.js",
"start": "yarn clean && yarn build && yarn server",
Expand Down
Loading