-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrating subscription modals into the app flow
- Created a PricingModals provider and context, with their usePricingModals hook - Integrated these into the invite team memberships, showing the upgrade tier modal there (which already links to the pricing one)
- Loading branch information
1 parent
1d79126
commit 00d43e8
Showing
14 changed files
with
537 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useDisclosure } from '@chakra-ui/hooks' | ||
import { createContext } from '@chakra-ui/react-utils' | ||
import React, { ReactNode, useState } from 'react' | ||
import { SubscriptionModal } from './Plans' | ||
import { PlanUpgradeData, PlanUpgradeModal, TierUpgradeModal } from './Upgrading' | ||
|
||
// Define types for the context | ||
type PricingModalType = 'tierUpgrade' | 'planUpgrade' | 'subscription' | null | ||
|
||
type PricingModalContextState = { | ||
openModal: (type: PricingModalType, modalData?: PlanUpgradeData | null) => void | ||
closeModal: () => void | ||
modalType: PricingModalType | ||
modalData: any | ||
} | ||
|
||
const [PricingModalProviderContext, usePricingModal] = createContext<PricingModalContextState>({ | ||
name: 'PricingModalProvider', | ||
errorMessage: 'usePricingModal must be used within a PricingModalProvider', | ||
strict: true, | ||
}) | ||
|
||
export const PricingModalProvider: React.FC<{ children?: ReactNode }> = ({ children }) => { | ||
const { isOpen, onOpen, onClose } = useDisclosure() | ||
const [modalType, setModalType] = useState<PricingModalType>(null) | ||
const [modalData, setModalData] = useState<PlanUpgradeData | null>(null) | ||
|
||
const openModal = (type: PricingModalType, data?: PlanUpgradeData | null) => { | ||
setModalType(type) | ||
setModalData(data || null) | ||
onOpen() | ||
} | ||
|
||
const closeModal = () => { | ||
setModalType(null) | ||
setModalData(null) | ||
onClose() | ||
} | ||
|
||
return ( | ||
<PricingModalProviderContext value={{ openModal, closeModal, modalType, modalData }}> | ||
{children} | ||
|
||
{/* Render modals dynamically based on the modalType */} | ||
{modalType === 'tierUpgrade' && isOpen && <TierUpgradeModal isOpen onClose={closeModal} {...modalData} />} | ||
{modalType === 'planUpgrade' && isOpen && <PlanUpgradeModal isOpen onClose={closeModal} {...modalData} />} | ||
{modalType === 'subscription' && isOpen && <SubscriptionModal isOpen onClose={closeModal} />} | ||
</PricingModalProviderContext> | ||
) | ||
} | ||
|
||
export { usePricingModal } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.