Skip to content

Commit 8fb92ba

Browse files
committed
feat: adjust custom data
1 parent 681587c commit 8fb92ba

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

packages/shared/src/contexts/RecruiterPaymentContext/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type ProcessingError = {
2222

2323
export type RecruiterPaymentContextData = {
2424
paddle?: Paddle | undefined;
25-
openCheckout?: OpenCheckoutFn;
25+
openCheckout?: OpenCheckoutFn<{ opportunity_id: string }>;
2626
onCompletion?: () => void;
2727
selectedProduct?: RecruiterProductOption;
2828
setSelectedProduct: (product: RecruiterProductOption) => void;

packages/shared/src/contexts/payment/context.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import type { Dispatch, ReactNode, SetStateAction } from 'react';
22
import { createContext, useContext } from 'react';
33
import type { ProductPricingPreview, PurchaseType } from '../../graphql/paddle';
44

5-
export interface OpenCheckoutProps {
5+
export interface OpenCheckoutProps<TCustomData = Record<string, unknown>> {
66
priceId: string;
77
giftToUserId?: string;
8-
customData?: Record<string, unknown>;
8+
customData?: TCustomData;
99
discountId?: string;
1010
quantity?: number;
1111
}
1212

13-
export type OpenCheckoutFn = (props: OpenCheckoutProps) => void;
13+
export type OpenCheckoutFn<TCustomData = Record<string, unknown>> = (
14+
props: OpenCheckoutProps<TCustomData>,
15+
) => void;
1416

1517
export interface PaymentContextData {
1618
openCheckout?: OpenCheckoutFn;

packages/shared/src/hooks/usePaddlePayment.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ export const usePaddlePayment = ({
201201
}, [router, disabledEvents, targetType, isOrganization, isPlusPlan]);
202202

203203
const openCheckout = useCallback(
204-
({
204+
<TCustomData>({
205205
priceId,
206206
giftToUserId,
207207
discountId,
208208
quantity = 1,
209-
}: OpenCheckoutProps) => {
209+
customData: customDataProp,
210+
}: OpenCheckoutProps<TCustomData>) => {
210211
const items: CheckoutLineItem[] = [{ priceId, quantity }];
211212
const customer: CheckoutCustomer = {
212213
...(user?.email
@@ -222,6 +223,7 @@ export const usePaddlePayment = ({
222223
};
223224

224225
const customData = {
226+
...customDataProp,
225227
user_id: giftToUserId ?? user?.id,
226228
tracking_id: trackingId,
227229
...(!!giftToUserId && { gifter_id: user?.id }),

packages/webapp/pages/recruiter/[opportunityId]/payment.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,31 @@ import {
1616
} from '@dailydotdev/shared/src/components/typography/Typography';
1717
import { FlexCol } from '@dailydotdev/shared/src/components/utilities';
1818
import { useRecruiterPaymentContext } from '@dailydotdev/shared/src/contexts/RecruiterPaymentContext/types';
19+
import {
20+
OpportunityPreviewProvider,
21+
useOpportunityPreviewContext,
22+
} from '@dailydotdev/shared/src/features/opportunity/context/OpportunityPreviewContext';
1923

2024
const RecruiterPaymentPage = (): ReactElement => {
2125
const router = useRouter();
2226
const checkoutRef = useRef<HTMLDivElement>(null);
2327
const { openCheckout, selectedProduct } = useRecruiterPaymentContext();
28+
const { opportunity } = useOpportunityPreviewContext();
2429

2530
useEffect(() => {
31+
if (!opportunity) {
32+
return;
33+
}
34+
2635
if (!selectedProduct) {
2736
return;
2837
}
2938

3039
openCheckout({
3140
priceId: selectedProduct.id,
41+
customData: { opportunity_id: opportunity.id },
3242
});
33-
}, [selectedProduct, openCheckout]);
43+
}, [selectedProduct, openCheckout, opportunity]);
3444

3545
const handleBack = () => {
3646
router.back();
@@ -156,7 +166,11 @@ const RecruiterPaymentPage = (): ReactElement => {
156166
RecruiterPaymentPage.getLayout = function getLayout(
157167
page: ReactNode,
158168
): ReactNode {
159-
return <RecruiterPaymentContext>{page}</RecruiterPaymentContext>;
169+
return (
170+
<OpportunityPreviewProvider>
171+
<RecruiterPaymentContext>{page}</RecruiterPaymentContext>
172+
</OpportunityPreviewProvider>
173+
);
160174
};
161175

162176
export default RecruiterPaymentPage;

0 commit comments

Comments
 (0)