-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
177 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
20 changes: 20 additions & 0 deletions
20
src/client/store/ui/links/actions/getIsVerificationInProgress.ts
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,20 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit' | ||
import axios from 'axios' | ||
|
||
import { ApiEndPoint } from 'meta/api/endpoint' | ||
import { AssessmentName, CycleName } from 'meta/assessment' | ||
|
||
import { ThunkApiConfig } from 'client/store/types' | ||
|
||
type Props = { | ||
assessmentName: AssessmentName | ||
cycleName: CycleName | ||
} | ||
|
||
export const getIsVerificationInProgress = createAsyncThunk<boolean, Props, ThunkApiConfig>( | ||
'links/verification/status', | ||
async (props) => { | ||
const { data } = await axios.get(ApiEndPoint.CycleData.Links.verifyStatus(), { params: props }) | ||
return data | ||
} | ||
) |
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,12 @@ | ||
import { getIsVerificationInProgress } from 'client/store/ui/links/actions/getIsVerificationInProgress' | ||
import { LinksSlice } from 'client/store/ui/links/slice' | ||
|
||
import { updateLink } from './updateLink' | ||
import { verifyLinks } from './verifyLinks' | ||
|
||
export const LinksActions = { | ||
...LinksSlice.actions, | ||
getIsVerificationInProgress, | ||
updateLink, | ||
verifyLinks, | ||
} |
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,22 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit' | ||
import axios from 'axios' | ||
|
||
import { ApiEndPoint } from 'meta/api/endpoint' | ||
import { AssessmentName, CycleName } from 'meta/assessment' | ||
import { Link } from 'meta/cycleData' | ||
|
||
import { ThunkApiConfig } from 'client/store/types' | ||
|
||
type Props = { | ||
assessmentName: AssessmentName | ||
cycleName: CycleName | ||
link: Link | ||
} | ||
|
||
export const updateLink = createAsyncThunk<Link, Props, ThunkApiConfig>('links/update', async (props) => { | ||
const { assessmentName, cycleName, link } = props | ||
const params = { assessmentName, cycleName } | ||
|
||
const { data } = await axios.patch(ApiEndPoint.CycleData.Links.one(), { link }, { params }) | ||
return data | ||
}) |
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,16 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit' | ||
import axios from 'axios' | ||
|
||
import { ApiEndPoint } from 'meta/api/endpoint' | ||
import { AssessmentName, CycleName } from 'meta/assessment' | ||
|
||
import { ThunkApiConfig } from 'client/store/types' | ||
|
||
type Props = { | ||
assessmentName: AssessmentName | ||
cycleName: CycleName | ||
} | ||
|
||
export const verifyLinks = createAsyncThunk<void, Props, ThunkApiConfig>('links/verify', async (props) => { | ||
await axios.post(ApiEndPoint.CycleData.Links.verify(), {}, { params: props }) | ||
}) |
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,12 @@ | ||
import { AssessmentName, CycleName } from 'meta/assessment' | ||
|
||
import { useAppSelector } from 'client/store/store' | ||
import { LinksSelectors } from 'client/store/ui/links/selectors' | ||
|
||
export const useIsVerificationInProgress = ( | ||
assessmentName: AssessmentName, | ||
cycleName: CycleName | ||
): boolean | undefined => { | ||
const isVerificationInProgress = useAppSelector(LinksSelectors.isVerificationInProgress) | ||
return isVerificationInProgress?.[assessmentName]?.[cycleName] | ||
} |
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,30 @@ | ||
import { useEffect } from 'react' | ||
|
||
import { isAnyOf } from '@reduxjs/toolkit' | ||
|
||
import { ApiEndPoint } from 'meta/api/endpoint' | ||
|
||
import { addAppListener, useAppDispatch } from 'client/store' | ||
import { LinksActions } from 'client/store/ui/links' | ||
import { TablePaginatedActions, useTablePaginatedOrderBy, useTablePaginatedPage } from 'client/store/ui/tablePaginated' | ||
import { useCountryRouteParams } from 'client/hooks/useRouteParams' | ||
|
||
export const useLinksChangeListener = () => { | ||
const { assessmentName, countryIso, cycleName } = useCountryRouteParams() | ||
const dispatch = useAppDispatch() | ||
const path = ApiEndPoint.CycleData.Links.many() | ||
const page = useTablePaginatedPage(path) | ||
const orderBy = useTablePaginatedOrderBy(path) | ||
|
||
useEffect(() => { | ||
return dispatch( | ||
addAppListener({ | ||
matcher: isAnyOf(LinksActions.updateLink.fulfilled), | ||
effect: () => { | ||
const getDataProps = { assessmentName, cycleName, limit: 30, orderBy, page, path } | ||
dispatch(TablePaginatedActions.getData(getDataProps)) | ||
}, | ||
}) | ||
) | ||
}, [assessmentName, countryIso, cycleName, dispatch, orderBy, page, path]) | ||
} |
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,5 @@ | ||
export { LinksActions } from './actions' | ||
export { useIsVerificationInProgress } from './hooks' | ||
export { useLinksChangeListener } from './hooks/useLinksChangeListener' | ||
export { LinksSlice } from './slice' | ||
export type { LinksState } from './state' |
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,11 @@ | ||
import { createSelector } from '@reduxjs/toolkit' | ||
|
||
import { RootState } from 'client/store/RootState' | ||
import { LinksSlice } from 'client/store/ui/links/slice' | ||
|
||
const _getState = (state: RootState) => state.ui[LinksSlice.name] | ||
const isVerificationInProgress = createSelector(_getState, (links) => links.isVerificationInProgress) | ||
|
||
export const LinksSelectors = { | ||
isVerificationInProgress, | ||
} |
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,38 @@ | ||
import { createSlice, PayloadAction, Reducer } from '@reduxjs/toolkit' | ||
import { Objects } from 'utils/objects' | ||
|
||
import { AssessmentName, CycleName } from 'meta/assessment' | ||
|
||
import { getIsVerificationInProgress } from './actions/getIsVerificationInProgress' | ||
import { initialState, LinksState } from './state' | ||
|
||
export const LinksSlice = createSlice({ | ||
name: 'links', | ||
initialState, | ||
reducers: { | ||
reset: () => initialState, | ||
setIsVerificationInProgress: ( | ||
state: LinksState, | ||
action: PayloadAction<{ assessmentName: AssessmentName; cycleName: CycleName; isVerificationInProgress: boolean }> | ||
) => { | ||
const { assessmentName, cycleName, isVerificationInProgress } = action.payload | ||
Objects.setInPath({ | ||
obj: state, | ||
path: ['isVerificationInProgress', assessmentName, cycleName], | ||
value: isVerificationInProgress, | ||
}) | ||
}, | ||
}, | ||
extraReducers: (builder) => { | ||
builder.addCase(getIsVerificationInProgress.fulfilled, (state, { meta, payload }) => { | ||
const { assessmentName, cycleName } = meta.arg | ||
Objects.setInPath({ | ||
obj: state, | ||
path: ['isVerificationInProgress', assessmentName, cycleName], | ||
value: payload, | ||
}) | ||
}) | ||
}, | ||
}) | ||
|
||
export default LinksSlice.reducer as Reducer<LinksState> |
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,7 @@ | ||
import { AssessmentName, CycleName } from 'meta/assessment' | ||
|
||
export type LinksState = { | ||
isVerificationInProgress?: Record<AssessmentName, Record<CycleName, boolean>> | ||
} | ||
|
||
export const initialState: LinksState = {} |