-
Notifications
You must be signed in to change notification settings - Fork 293
feat: job payment #5144
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
Merged
Merged
feat: job payment #5144
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
de7870e
feat: job payment
capJavert 681587c
fix: types
capJavert 8fb92ba
feat: adjust custom data
capJavert e81cb56
fix: types
capJavert 87f5cb8
Merge branch 'main' into job-payment
rebelchris d5fe265
refactor: paid to subscriptionStatus
capJavert 19716fa
Merge branch 'job-payment' of github.com:dailydotdev/apps into job-pa…
capJavert 61f296c
Merge branch 'main' into job-payment
capJavert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/shared/src/contexts/RecruiterPaymentContext/RecruiterPaymentContext.tsx
This file contains hidden or 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,15 @@ | ||
| import type { ReactElement } from 'react'; | ||
| import React from 'react'; | ||
| import type { RecruiterContextProviderProps } from './types'; | ||
| import { RecruiterPaymentPaddleContextProvider } from './RecruiterPaymentPaddleContext'; | ||
|
|
||
| export const RecruiterPaymentContext = ({ | ||
| children, | ||
| ...props | ||
| }: RecruiterContextProviderProps): ReactElement => { | ||
| return ( | ||
| <RecruiterPaymentPaddleContextProvider {...props}> | ||
| {children} | ||
| </RecruiterPaymentPaddleContextProvider> | ||
| ); | ||
| }; |
78 changes: 78 additions & 0 deletions
78
packages/shared/src/contexts/RecruiterPaymentContext/RecruiterPaymentPaddleContext.tsx
This file contains hidden or 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,78 @@ | ||
| import type { ReactElement } from 'react'; | ||
| import React, { useEffect, useMemo, useRef, useState } from 'react'; | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { useRouter } from 'next/router'; | ||
| import { PurchaseType } from '../../graphql/paddle'; | ||
| import { usePaddlePayment } from '../../hooks/usePaddlePayment'; | ||
| import { useLogContext } from '../LogContext'; | ||
| import { useAuthContext } from '../AuthContext'; | ||
| import type { | ||
| RecruiterPaymentContextData, | ||
| RecruiterContextProviderProps, | ||
| RecruiterProductOption, | ||
| } from './types'; | ||
| import { RecruiterPaymentContext } from './types'; | ||
| import { webappUrl } from '../../lib/constants'; | ||
| import { recruiterPricesQueryOptions } from '../../features/opportunity/graphql'; | ||
|
|
||
| export const RecruiterPaymentPaddleContextProvider = ({ | ||
| onCompletion, | ||
| origin, | ||
| children, | ||
| }: RecruiterContextProviderProps): ReactElement => { | ||
| const router = useRouter(); | ||
| const { user, isLoggedIn } = useAuthContext(); | ||
| const { logEvent } = useLogContext(); | ||
| const [selectedProduct, setSelectedProduct] = | ||
| useState<RecruiterProductOption>(); | ||
| const logRef = useRef<typeof logEvent>(); | ||
| logRef.current = logEvent; | ||
|
|
||
| const { data: prices } = useQuery( | ||
| recruiterPricesQueryOptions({ | ||
| user, | ||
| isLoggedIn, | ||
| }), | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (!prices?.length) { | ||
| return; | ||
| } | ||
|
|
||
| if (selectedProduct) { | ||
| return; | ||
| } | ||
|
|
||
| setSelectedProduct({ | ||
| id: prices[0].priceId, | ||
| }); | ||
| }, [prices, selectedProduct]); | ||
|
|
||
| const { paddle, openCheckout } = usePaddlePayment({ | ||
| successCallback: () => { | ||
| router.push( | ||
| `${webappUrl}recruiter/${router.query.opportunityId}/prepare`, | ||
| ); | ||
| }, | ||
| priceType: PurchaseType.Recruiter, | ||
| }); | ||
|
|
||
| const contextData = useMemo<RecruiterPaymentContextData>( | ||
| () => ({ | ||
| paddle, | ||
| onCompletion, | ||
| selectedProduct, | ||
| setSelectedProduct, | ||
| openCheckout, | ||
| origin, | ||
| }), | ||
| [onCompletion, openCheckout, origin, paddle, selectedProduct], | ||
| ); | ||
|
|
||
| return ( | ||
| <RecruiterPaymentContext.Provider value={contextData}> | ||
| {children} | ||
| </RecruiterPaymentContext.Provider> | ||
| ); | ||
| }; | ||
37 changes: 37 additions & 0 deletions
37
packages/shared/src/contexts/RecruiterPaymentContext/types.ts
This file contains hidden or 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,37 @@ | ||
| import type { Paddle } from '@paddle/paddle-js'; | ||
| import type { ReactNode } from 'react'; | ||
| import { createContext, useContext } from 'react'; | ||
| import type { OpenCheckoutFn } from '../payment/context'; | ||
| import type { Origin } from '../../lib/log'; | ||
|
|
||
| export const RecruiterPaymentContext = | ||
| createContext<RecruiterPaymentContextData>(undefined); | ||
|
|
||
| export const useRecruiterPaymentContext = (): RecruiterPaymentContextData => | ||
| useContext(RecruiterPaymentContext); | ||
|
|
||
| export type RecruiterProductOption = { | ||
| id: string; | ||
| }; | ||
|
|
||
| export type ProcessingError = { | ||
| title: string; | ||
| description?: string; | ||
| onRequestClose?: () => void; | ||
| }; | ||
|
|
||
| export type RecruiterPaymentContextData = { | ||
| paddle?: Paddle | undefined; | ||
| openCheckout?: OpenCheckoutFn<{ opportunity_id: string }>; | ||
| onCompletion?: () => void; | ||
| selectedProduct?: RecruiterProductOption; | ||
| setSelectedProduct: (product: RecruiterProductOption) => void; | ||
| error?: ProcessingError; | ||
| origin?: Origin; | ||
| }; | ||
|
|
||
| export type RecruiterContextProviderProps = { | ||
| children?: ReactNode; | ||
| origin?: Origin; | ||
| onCompletion?: () => void; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.