-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YKI(Frontend): Show user's active registrations in header
- Loading branch information
Showing
12 changed files
with
172 additions
and
7 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
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
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
45 changes: 45 additions & 0 deletions
45
frontend/packages/yki/src/redux/reducers/userOpenRegistrations.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,45 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { APIResponseStatus } from 'shared/enums'; | ||
|
||
import { UserOpenRegistrationsResponse } from 'interfaces/publicRegistration'; | ||
|
||
interface UserOpenRegistrationsState { | ||
status: APIResponseStatus; | ||
openRegistrations?: UserOpenRegistrationsResponse; | ||
} | ||
|
||
const initialState: UserOpenRegistrationsState = { | ||
status: APIResponseStatus.NotStarted, | ||
}; | ||
|
||
const userOpenRegistrationsSlice = createSlice({ | ||
name: 'userOpenRegistrations', | ||
initialState, | ||
reducers: { | ||
acceptUserOpenRegistrations( | ||
state, | ||
action: PayloadAction<UserOpenRegistrationsResponse> | ||
) { | ||
state.status = APIResponseStatus.Success; | ||
state.openRegistrations = action.payload; | ||
}, | ||
loadUserOpenRegistrations(state) { | ||
state.status = APIResponseStatus.InProgress; | ||
}, | ||
rejectUserOpenRegistrations(state) { | ||
state.status = APIResponseStatus.Error; | ||
}, | ||
resetUserOpenRegistrations(state) { | ||
state.status = APIResponseStatus.NotStarted; | ||
state.openRegistrations = undefined; | ||
}, | ||
}, | ||
}); | ||
|
||
export const userOpenRegistrationsReducer = userOpenRegistrationsSlice.reducer; | ||
export const { | ||
acceptUserOpenRegistrations, | ||
loadUserOpenRegistrations, | ||
rejectUserOpenRegistrations, | ||
resetUserOpenRegistrations, | ||
} = userOpenRegistrationsSlice.actions; |
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
30 changes: 30 additions & 0 deletions
30
frontend/packages/yki/src/redux/sagas/userOpenRegistrations.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,30 @@ | ||
import { call, put, takeLatest } from '@redux-saga/core/effects'; | ||
import { AxiosResponse } from 'axios'; | ||
|
||
import axiosInstance from 'configs/axios'; | ||
import { APIEndpoints } from 'enums/api'; | ||
import { UserOpenRegistrationsResponse } from 'interfaces/publicRegistration'; | ||
import { | ||
acceptUserOpenRegistrations, | ||
loadUserOpenRegistrations, | ||
rejectUserOpenRegistrations, | ||
} from 'redux/reducers/userOpenRegistrations'; | ||
|
||
function* loadUserOpenRegistrationsSaga() { | ||
try { | ||
const response: AxiosResponse<UserOpenRegistrationsResponse> = yield call( | ||
axiosInstance.get, | ||
APIEndpoints.OpenRegistrations | ||
); | ||
yield put(acceptUserOpenRegistrations(response.data)); | ||
} catch (error) { | ||
yield put(rejectUserOpenRegistrations()); | ||
} | ||
} | ||
|
||
export function* watchUserOpenRegistrations() { | ||
yield takeLatest( | ||
loadUserOpenRegistrations.type, | ||
loadUserOpenRegistrationsSaga | ||
); | ||
} |
4 changes: 4 additions & 0 deletions
4
frontend/packages/yki/src/redux/selectors/userOpenRegistrations.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,4 @@ | ||
import { RootState } from 'configs/redux'; | ||
|
||
export const userOpenRegistrationsSelector = (state: RootState) => | ||
state.userOpenRegistrations; |
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