-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add setup for apis on frontend
- Loading branch information
1 parent
6e1064c
commit c082eba
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
frontend/src/hooks/useActiveLicenseV3/useActiveLicenseV3.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |