Skip to content

Commit 49e94b2

Browse files
authored
get rid of baremetrics (#3957)
1 parent 3c901d3 commit 49e94b2

File tree

13 files changed

+27
-309
lines changed

13 files changed

+27
-309
lines changed

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
REACT_APP_SENTRY_DSN=$SENTRY_DSN
22
REACT_APP_STRIPE_KEY=$STRIPE_KEY
3-
REACT_APP_BAREMETRICS_TOKEN=$BAREMETRICS_TOKEN

.env.development

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ REACT_APP_BASE_URL=https://stage-web.codecov.dev
44
REACT_APP_MARKETING_BASE_URL=https://about.codecov.io
55
# REACT_APP_STRIPE_KEY=
66
# REACT_APP_LAUNCHDARKLY=
7-
# REACT_APP_BAREMETRICS_TOKEN=

src/pages/PlanPage/subRoutes/CancelPlanPage/subRoutes/DowngradePlan/CancelButton/CancelButton.jsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1+
import { format, fromUnixTime } from 'date-fns'
12
import PropType from 'prop-types'
23
import { useState } from 'react'
34

45
import Button from 'ui/Button'
56
import Modal from 'ui/Modal'
67

78
import { useCancel } from './hooks'
8-
import { cleanupBaremetrics, getEndPeriod } from './utils'
99

1010
const FALLBACK_PERIOD_TEXT = 'the end of the period'
1111

12-
function CancelButton({
13-
customerId,
14-
isFreePlan,
15-
upComingCancellation,
16-
currentPeriodEnd,
17-
}) {
12+
function getEndPeriod(unixPeriodEnd) {
13+
return (
14+
unixPeriodEnd &&
15+
format(fromUnixTime(unixPeriodEnd), 'MMMM do yyyy, h:m aaaa')
16+
)
17+
}
18+
19+
function CancelButton({ isFreePlan, upComingCancellation, currentPeriodEnd }) {
1820
const [isModalOpen, setIsModalOpen] = useState(false)
19-
const { cancelPlan, baremetricsBlocked, queryIsLoading } = useCancel({
20-
customerId,
21-
isModalOpen,
22-
})
21+
const { cancelPlan, queryIsLoading } = useCancel()
2322

2423
const isDisabled = [
2524
// disable button if
@@ -29,14 +28,7 @@ function CancelButton({
2928
].some(Boolean)
3029
const periodEnd = getEndPeriod(currentPeriodEnd)
3130

32-
function completeCancellation() {
33-
if (baremetricsBlocked) {
34-
cancelPlan()
35-
}
36-
}
37-
3831
function handleOnClose() {
39-
cleanupBaremetrics()
4032
setIsModalOpen(false)
4133
}
4234

@@ -84,12 +76,10 @@ function CancelButton({
8476
Cancel
8577
</Button>
8678
<Button
87-
// This ID is needed to render the baremetrics form. DO NOT CHANGE
88-
id="barecancel-trigger"
8979
variant="danger"
9080
hook="continue-cancellation-button"
9181
disabled={isDisabled}
92-
onClick={completeCancellation}
82+
onClick={cancelPlan}
9383
>
9484
Confirm Cancellation
9585
</Button>

src/pages/PlanPage/subRoutes/CancelPlanPage/subRoutes/DowngradePlan/CancelButton/CancelButton.test.jsx

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import CancelButton from './CancelButton'
77

88
const mocks = vi.hoisted(() => ({
99
useParams: vi.fn(),
10-
useBarecancel: vi.fn(),
1110
useCancelPlan: vi.fn(),
1211
useAddNotification: vi.fn(),
1312
}))
@@ -20,14 +19,6 @@ vi.mock('react-router-dom', async () => {
2019
}
2120
})
2221

23-
vi.mock('./useBarecancel', async () => {
24-
const actual = await vi.importActual('./useBarecancel')
25-
return {
26-
...actual,
27-
useBarecancel: mocks.useBarecancel,
28-
}
29-
})
30-
3122
vi.mock('services/account/useCancelPlan', async () => {
3223
const actual = await vi.importActual('services/account/useCancelPlan')
3324
return {
@@ -72,7 +63,7 @@ const wrapper = ({ children }) => (
7263
)
7364

7465
describe('CancelButton', () => {
75-
function setup(baremetricsBlocked = false) {
66+
function setup() {
7667
const user = userEvent.setup()
7768
const mutate = vi.fn()
7869
const addNotification = vi.fn()
@@ -84,7 +75,6 @@ describe('CancelButton', () => {
8475
mutate,
8576
onError: vi.fn(),
8677
})
87-
mocks.useBarecancel.mockReturnValue({ baremetricsBlocked })
8878

8979
return { mutate, addNotification, user }
9080
}
@@ -95,9 +85,9 @@ describe('CancelButton', () => {
9585
it('renders button text', () => {
9686
render(
9787
<CancelButton
98-
customerId="cus_1n4o328hn4"
88+
isFreePlan={false}
9989
planCost="users-pr-inappy"
100-
upComingCancelation={false}
90+
upComingCancellation={false}
10191
currentPeriodEnd={1675361466}
10292
/>,
10393
{ wrapper }
@@ -114,9 +104,9 @@ describe('CancelButton', () => {
114104
const { user } = setup()
115105
render(
116106
<CancelButton
117-
customerId="cus_1n4o328hn4"
107+
isFreePlan={false}
118108
planCost="users-pr-inappy"
119-
upComingCancelation={false}
109+
upComingCancellation={false}
120110
currentPeriodEnd={1675361466}
121111
/>,
122112
{ wrapper }
@@ -132,9 +122,9 @@ describe('CancelButton', () => {
132122
const { user } = setup()
133123
render(
134124
<CancelButton
135-
customerId="cus_1n4o328hn4"
125+
isFreePlan={false}
136126
planCost="users-pr-inappy"
137-
upComingCancelation={false}
127+
upComingCancellation={false}
138128
currentPeriodEnd={1675361466}
139129
/>,
140130
{ wrapper }
@@ -154,9 +144,9 @@ describe('CancelButton', () => {
154144
const { user } = setup()
155145
render(
156146
<CancelButton
157-
customerId="cus_1n4o328hn4"
147+
isFreePlan={false}
158148
planCost="users-pr-inappy"
159-
upComingCancelation={false}
149+
upComingCancellation={false}
160150
currentPeriodEnd={1675361466}
161151
/>,
162152
{ wrapper }
@@ -170,39 +160,16 @@ describe('CancelButton', () => {
170160
).not.toBeInTheDocument()
171161
})
172162
})
173-
174-
describe('when unmounted', () => {
175-
it('removes the baremetrics script', async () => {
176-
const { user } = setup()
177-
const { unmount } = render(
178-
<CancelButton
179-
customerId="cus_1n4o328hn4"
180-
planCost="users-pr-inappy"
181-
upComingCancelation={false}
182-
currentPeriodEnd={1675361466}
183-
/>,
184-
{ wrapper }
185-
)
186-
187-
await user.click(screen.getByTestId('downgrade-button'))
188-
189-
unmount()
190-
191-
expect(
192-
screen.queryByTestId('baremetrics-script')
193-
).not.toBeInTheDocument()
194-
})
195-
})
196163
})
197164

198165
describe('when clicking submit', () => {
199166
it('calls the cancelPlan/mutate function', async () => {
200167
const { mutate, user } = setup(true)
201168
render(
202169
<CancelButton
203-
customerId="cus_1n4o328hn4"
170+
isFreePlan={false}
204171
planCost="users-pr-inappy"
205-
upComingCancelation={false}
172+
upComingCancellation={false}
206173
currentPeriodEnd={1675361466}
207174
/>,
208175
{ wrapper }
@@ -219,9 +186,9 @@ describe('CancelButton', () => {
219186
const { mutate, addNotification, user } = setup(true)
220187
render(
221188
<CancelButton
222-
customerId="cus_1n4o328hn4"
189+
isFreePlan={false}
223190
planCost="users-pr-inappy"
224-
upComingCancelation={false}
191+
upComingCancellation={false}
225192
currentPeriodEnd={1675361466}
226193
/>,
227194
{ wrapper }
@@ -244,9 +211,9 @@ describe('CancelButton', () => {
244211
const { mutate, user } = setup(true)
245212
render(
246213
<CancelButton
247-
customerId="cus_1n4o328hn4"
214+
isFreePlan={false}
248215
planCost="users-pr-inappy"
249-
upComingCancelation={false}
216+
upComingCancellation={false}
250217
currentPeriodEnd={1675361466}
251218
/>,
252219
{ wrapper }

src/pages/PlanPage/subRoutes/CancelPlanPage/subRoutes/DowngradePlan/CancelButton/hooks.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@ import { useHistory, useParams } from 'react-router-dom'
33
import { useCancelPlan } from 'services/account/useCancelPlan'
44
import { useAddNotification } from 'services/toastNotification/context'
55

6-
import { useBarecancel } from './useBarecancel'
7-
8-
export function useCancel({ customerId, isModalOpen }, options = {}) {
6+
export function useCancel(options = {}) {
97
const addToast = useAddNotification()
108
const { provider, owner } = useParams()
119
const { push } = useHistory()
1210
const { mutate, isLoading } = useCancelPlan({ provider, owner })
13-
const { baremetricsBlocked } = useBarecancel({
14-
customerId,
15-
callbackSend: cancelPlan,
16-
isModalOpen,
17-
})
1811

1912
function sendUserToPlan() {
2013
push(`/plan/${provider}/${owner}`)
@@ -36,7 +29,6 @@ export function useCancel({ customerId, isModalOpen }, options = {}) {
3629

3730
return {
3831
cancelPlan,
39-
baremetricsBlocked,
4032
queryIsLoading: isLoading,
4133
}
4234
}

src/pages/PlanPage/subRoutes/CancelPlanPage/subRoutes/DowngradePlan/CancelButton/useBarecancel.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/pages/PlanPage/subRoutes/CancelPlanPage/subRoutes/DowngradePlan/CancelButton/useBarecancel.test.jsx

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)