File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
packages/manager/apps/pci-project/src
pages/detail/activate/hooks Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -37,3 +37,12 @@ export const getStartupProgram = async (): Promise<TStartupProgram> => {
3737 const { data } = await v6 . get < TStartupProgram > ( '/me/credit/balance/STARTUP_PROGRAM' ) ;
3838 return data ;
3939} ;
40+
41+ export const isVoucherUsed = async ( projectId : string , voucher : string ) : Promise < boolean > => {
42+ const response = await getCreditDetails ( projectId ) ;
43+ return (
44+ ( response . data || [ ] ) . filter ( ( creditDetail : CreditDetailsResponse ) => {
45+ return creditDetail . voucher === voucher ;
46+ } ) . length === 0
47+ ) ;
48+ } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { NAMESPACES } from '@ovh-ux/manager-common-translations';
99import { useNotifications } from '@ovh-ux/manager-react-components' ;
1010
1111import { DISCOVERY_PROMOTION_VOUCHER } from '@/constants' ;
12+ import { isVoucherUsed } from '@/data/api/credit' ;
1213import { useClaimVoucher } from '@/data/hooks/useProjects' ;
1314import { useActivateProject , useSimulateProjectActivation } from '@/data/hooks/useServices' ;
1415import { TEligibilityVoucher } from '@/data/models/Eligibility.type' ;
@@ -68,10 +69,13 @@ export const useProjectActivation = ({
6869 try {
6970 // Step 1: Claim voucher if we have a promotion amount
7071 if ( promotionVoucher && claimVoucher ) {
71- await claimDiscoveryVoucher ( {
72- projectId,
73- voucherCode : DISCOVERY_PROMOTION_VOUCHER ,
74- } ) ;
72+ const isUsed = await isVoucherUsed ( projectId , DISCOVERY_PROMOTION_VOUCHER ) ;
73+ if ( ! isUsed ) {
74+ await claimDiscoveryVoucher ( {
75+ projectId,
76+ voucherCode : DISCOVERY_PROMOTION_VOUCHER ,
77+ } ) ;
78+ }
7579 }
7680
7781 // Step 2: Simulate activation to check if payment is required
You can’t perform that action at this time.
0 commit comments