Skip to content

Commit 44bf38e

Browse files
Api: fetch from GET /subscription_user endpoint (#1466)
* build(deps): bump the prod-deps group with 4 updates Bumps the prod-deps group with 4 updates: [@storyblok/react](https://github.com/storyblok/storyblok-react), [axios](https://github.com/axios/axios), [firebase](https://github.com/firebase/firebase-js-sdk) and [next-intl](https://github.com/amannn/next-intl). Updates `@storyblok/react` from 4.6.0 to 4.6.1 - [Release notes](https://github.com/storyblok/storyblok-react/releases) - [Commits](storyblok/storyblok-react@v4.6.0...v4.6.1) Updates `axios` from 1.8.4 to 1.9.0 - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](axios/axios@v1.8.4...v1.9.0) Updates `firebase` from 11.6.0 to 11.6.1 - [Release notes](https://github.com/firebase/firebase-js-sdk/releases) - [Changelog](https://github.com/firebase/firebase-js-sdk/blob/main/CHANGELOG.md) - [Commits](https://github.com/firebase/firebase-js-sdk/compare/firebase@11.6.0...firebase@11.6.1) Updates `next-intl` from 4.0.2 to 4.1.0 - [Release notes](https://github.com/amannn/next-intl/releases) - [Changelog](https://github.com/amannn/next-intl/blob/main/CHANGELOG.md) - [Commits](amannn/next-intl@v4.0.2...v4.1.0) --- updated-dependencies: - dependency-name: "@storyblok/react" dependency-version: 4.6.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: prod-deps - dependency-name: axios dependency-version: 1.9.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: prod-deps - dependency-name: firebase dependency-version: 11.6.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: prod-deps - dependency-name: next-intl dependency-version: 4.1.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: prod-deps ... Signed-off-by: dependabot[bot] <support@github.com> * Api: Fetch subscription user data from new endpoint * UI: Fixed Whatsapp signup banner flow * Fix: resolve build error in whatsapp forms * Final: Centralized data to Notes page * Final: Rename subscription user query * Fix: Remove comments * Fix: Remove activeSubscription from addUser --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent caa31fe commit 44bf38e

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

components/pages/NotesPage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import WhatsappSubscribeForm from '@/components/forms/WhatsappSubscribeForm';
77
import WhatsappUnsubscribeForm from '@/components/forms/WhatsappUnsubscribeForm';
88
import Header, { HeaderProps } from '@/components/layout/Header';
99
import StoryblokPageSection from '@/components/storyblok/StoryblokPageSection';
10+
import { useGetSubscriptionsUserQuery } from '@/lib/api';
1011
import { useTypedSelector } from '@/lib/hooks/store';
1112
import illustrationChange from '@/public/illustration_change.svg';
1213
import illustrationChooseTherapist from '@/public/illustration_choose_therapist.svg';
@@ -61,6 +62,10 @@ export default function NotesPage({ story }: Props) {
6162
const userActiveSubscriptions = useTypedSelector((state) => state.user.activeSubscriptions);
6263
const userId = useTypedSelector((state) => state.user.id);
6364

65+
const { data: subscriptions } = useGetSubscriptionsUserQuery(undefined, {
66+
skip: !userId,
67+
});
68+
6469
useEffect(() => {
6570
setHasActiveWhatsappSub(hasWhatsappSubscription(userActiveSubscriptions));
6671
}, [userActiveSubscriptions]);

lib/api.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ export const api = createApi({
275275
},
276276
providesTags: [{ type: 'UserCourses' }],
277277
}),
278+
getSubscriptionsUser: builder.query<Subscriptions, void>({
279+
query() {
280+
return {
281+
url: 'subscription-user',
282+
method: 'GET',
283+
};
284+
},
285+
}),
278286
}),
279287
});
280288

@@ -302,4 +310,5 @@ export const {
302310
useStartResourceMutation,
303311
useCompleteResourceMutation,
304312
useGetUserCoursesQuery,
313+
useGetSubscriptionsUserQuery,
305314
} = api;

lib/store/userSlice.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { api, GetUserResponse } from '@/lib/api';
1+
import { api } from '@/lib/api';
22
import { EMAIL_REMINDERS_FREQUENCY, LANGUAGES } from '@/lib/constants/enums';
33
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
44
import { PartnerAccesses } from './partnerAccessSlice';
@@ -135,23 +135,18 @@ const slice = createSlice({
135135

136136
extraReducers: (builder) => {
137137
builder.addMatcher(api.endpoints.addUser.matchFulfilled, (state, { payload }) => {
138-
const activeSubscriptions = getActiveSubscriptions(payload);
139-
140-
return Object.assign({}, state, payload.user, { activeSubscriptions });
138+
return Object.assign({}, state, payload.user);
141139
});
142140
builder.addMatcher(api.endpoints.updateUser.matchFulfilled, (state, { payload }) => {
143141
return Object.assign({}, state, payload);
144142
});
145143
builder.addMatcher(api.endpoints.getUser.matchFulfilled, (state, { payload }) => {
146-
const activeSubscriptions = getActiveSubscriptions(payload);
147-
148-
return Object.assign({}, state, payload.user, { activeSubscriptions });
144+
return Object.assign({}, state, payload.user);
149145
});
150146
builder.addMatcher(api.endpoints.subscribeToWhatsapp.matchFulfilled, (state, { payload }) => {
151147
if (isSubscriptionActive(payload)) {
152148
state.activeSubscriptions.push(payload);
153149
}
154-
155150
return state;
156151
});
157152
builder.addMatcher(
@@ -163,12 +158,16 @@ const slice = createSlice({
163158
return state;
164159
},
165160
);
161+
builder.addMatcher(api.endpoints.getSubscriptionsUser.matchFulfilled, (state, { payload }) => {
162+
state.activeSubscriptions = getActiveSubscriptions(payload);
163+
return state;
164+
});
166165
},
167166
});
168167

169-
const getActiveSubscriptions = (payload: GetUserResponse): ActiveSubscription[] => {
170-
if (payload.subscriptions && payload.subscriptions.length > 0) {
171-
return payload.subscriptions.filter(isSubscriptionActive);
168+
const getActiveSubscriptions = (subscriptions: Subscriptions): ActiveSubscription[] => {
169+
if (subscriptions && subscriptions.length > 0) {
170+
return subscriptions.filter(isSubscriptionActive);
172171
}
173172
return [];
174173
};

0 commit comments

Comments
 (0)