Skip to content

Commit

Permalink
feat: add setup for apis on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
vikrantgupta25 committed Nov 30, 2024
1 parent 6e1064c commit c082eba
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions frontend/src/AppRoutes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ROUTES from 'constants/routes';
import AppLayout from 'container/AppLayout';
import useAnalytics from 'hooks/analytics/useAnalytics';
import { KeyboardHotkeysProvider } from 'hooks/hotkeys/useKeyboardHotkeys';
import useActiveLicenseV3 from 'hooks/useActiveLicenseV3/useActiveLicenseV3';
import { useIsDarkMode, useThemeConfig } from 'hooks/useDarkMode';
import { THEME_MODE } from 'hooks/useDarkMode/constant';
import useFeatureFlags from 'hooks/useFeatureFlag';
Expand Down Expand Up @@ -57,6 +58,9 @@ function App(): JSX.Element {
AppReducer
>((state) => state.app);

const { data: activeLicenseV3 } = useActiveLicenseV3();
console.log(activeLicenseV3);

const dispatch = useDispatch<Dispatch<AppActions>>();

const { trackPageView } = useAnalytics();
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/api/licensesV3/getActive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ApiV3Instance as axios } from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import { ErrorResponse, SuccessResponse } from 'types/api';
import { LicenseV3EventQueueResModel } from 'types/api/licensesV3/getActive';

const getActive = async (): Promise<
SuccessResponse<LicenseV3EventQueueResModel> | ErrorResponse
> => {
try {
const response = await axios.get('/licenses/active');

return {
statusCode: 200,
error: null,
message: response.data.status,
payload: response.data.data,
};
} catch (error) {
return ErrorResponseHandler(error as AxiosError);
}
};

export default getActive;
1 change: 1 addition & 0 deletions frontend/src/constants/reactQueryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export const REACT_QUERY_KEY = {
DUPLICATE_ALERT_RULE: 'DUPLICATE_ALERT_RULE',
GET_HOST_LIST: 'GET_HOST_LIST',
UPDATE_ALERT_RULE: 'UPDATE_ALERT_RULE',
GET_ACTIVE_LICENSE_V3: 'GET_ACTIVE_LICENSE_V3',
};
25 changes: 25 additions & 0 deletions frontend/src/hooks/useActiveLicenseV3/useActiveLicenseV3.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import getActive from 'api/licensesV3/getActive';
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
import { useQuery, UseQueryResult } from 'react-query';
import { useSelector } from 'react-redux';
import { AppState } from 'store/reducers';
import { ErrorResponse, SuccessResponse } from 'types/api';
import { LicenseV3EventQueueResModel } from 'types/api/licensesV3/getActive';
import AppReducer from 'types/reducer/app';

const useActiveLicenseV3 = (): UseLicense => {
const { user } = useSelector<AppState, AppReducer>((state) => state.app);

return useQuery({
queryFn: getActive,
queryKey: [REACT_QUERY_KEY.GET_ACTIVE_LICENSE_V3, user?.email],
enabled: !!user?.email,
});
};

type UseLicense = UseQueryResult<
SuccessResponse<LicenseV3EventQueueResModel> | ErrorResponse,
unknown
>;

export default useActiveLicenseV3;
17 changes: 17 additions & 0 deletions frontend/src/types/api/licensesV3/getActive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export enum LicenseEvent {
FAILED_PAYMENT = 'FAILED_PAYMENT',
}

export type LicenseV3EventQueueResModel = {
event: keyof LicenseEvent;
status: string;
scheduled_at: string;
created_at: string;
updated_at: string;
};

export type LicenseV3ResModel = {
status: string;
state: string;
event_queue: LicenseV3EventQueueResModel;
};

0 comments on commit c082eba

Please sign in to comment.