-
Notifications
You must be signed in to change notification settings - Fork 61
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
25 changed files
with
159 additions
and
31 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,8 @@ | ||
import {createAsyncThunk} from "@reduxjs/toolkit" | ||
|
||
import type {RootState, AppDispatch} from "./types" | ||
|
||
export const createAppAsyncThunk = createAsyncThunk.withTypes<{ | ||
state: RootState | ||
dispatch: AppDispatch | ||
}>() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {createApi, fetchBaseQuery} from "@reduxjs/toolkit/query/react" | ||
import {getBaseURL} from "@/utils" | ||
|
||
import type {Group} from "@/types" | ||
import type {RootState} from "@/app/types" | ||
|
||
const baseQuery = fetchBaseQuery({ | ||
baseUrl: `${getBaseURL()}api`, | ||
prepareHeaders: (headers, {getState}) => { | ||
const state = getState() as RootState | ||
const token = state.auth.token | ||
const remote_user = state.auth.remote_user | ||
const remote_groups = state.auth.remote_groups | ||
const remote_name = state.auth.remote_name | ||
const remote_email = state.auth.remote_email | ||
|
||
if (token) { | ||
headers.set("authorization", `Bearer ${token}`) | ||
} | ||
|
||
if (remote_user) { | ||
headers.set("Remote-User", remote_user) | ||
} | ||
if (remote_groups) { | ||
headers.set("Remote-Groups", remote_groups) | ||
} | ||
if (remote_name) { | ||
headers.set("Remote-Name", remote_name) | ||
} | ||
if (remote_email) { | ||
headers.set("Remote-Email", remote_email) | ||
} | ||
|
||
headers.set("Content-Type", "application/json") | ||
|
||
return headers | ||
} | ||
}) | ||
|
||
// Define our single API slice object | ||
export const apiSlice = createApi({ | ||
reducerPath: "api", | ||
baseQuery: baseQuery, | ||
endpoints: builder => ({ | ||
getGroups: builder.query<Group[], void>({ | ||
query: () => "/groups/" | ||
}) | ||
}) | ||
}) | ||
|
||
// Export the auto-generated hook for the `getPosts` query endpoint | ||
export const {useGetGroupsQuery} = apiSlice |
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,58 @@ | ||
import Cookies from "js-cookie" | ||
import {createSlice} from "@reduxjs/toolkit" | ||
import type {RootState} from "@/app/types" | ||
import {createAppAsyncThunk} from "@/app/withTypes" | ||
import {getDefaultHeaders} from "@/utils" | ||
|
||
const COOKIE_NAME = "access_token" | ||
|
||
interface AuthState { | ||
token: string | null | ||
remote_user: string | null | ||
remote_groups: string | null | ||
remote_email: string | null | ||
remote_name: string | null | ||
} | ||
|
||
const initialState: AuthState = { | ||
token: null, | ||
remote_user: null, | ||
remote_groups: null, | ||
remote_email: null, | ||
remote_name: null | ||
} | ||
|
||
const authSlice = createSlice({ | ||
name: "auth", | ||
initialState, | ||
// Remove the reducer definitions | ||
reducers: { | ||
cookieLoaded: state => { | ||
const headers = getDefaultHeaders() | ||
const token = Cookies.get(COOKIE_NAME) | ||
|
||
if (headers["Remote-User"]) { | ||
state.remote_user = headers["Remote-User"] | ||
} | ||
|
||
if (headers["Remote-Groups"]) { | ||
state.remote_groups = headers["Remote-Groups"] | ||
} | ||
|
||
if (headers["Remote-Email"]) { | ||
state.remote_email = headers["Remote-Email"] | ||
} | ||
|
||
if (headers["Remote-Name"]) { | ||
state.remote_name = headers["Remote-Name"] | ||
} | ||
|
||
if (token) { | ||
state.token = token | ||
} | ||
} | ||
} | ||
}) | ||
|
||
export const {cookieLoaded} = authSlice.actions | ||
export default authSlice.reducer |
2 changes: 1 addition & 1 deletion
2
ui2/src/components/groups/ActionButtons.tsx → ...tures/groups/components/ActionButtons.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
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
2 changes: 1 addition & 1 deletion
2
ui2/src/components/groups/DeleteModal.tsx → ...eatures/groups/components/DeleteModal.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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion
6
ui2/src/components/groups/GroupRow.tsx → ...c/features/groups/components/GroupRow.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
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,5 @@ | ||
import GroupsList from "@/components/groups/List" | ||
import {fetchGroups} from "@/slices/groups" | ||
import {store} from "@/app/store" | ||
import {GroupsList} from "@/features/groups/components" | ||
|
||
export default function GroupsPage() { | ||
return <GroupsList /> | ||
} | ||
|
||
export async function loader() { | ||
const state = store.getState() | ||
await store.dispatch( | ||
fetchGroups({pageNumber: 1, pageSize: state.groups.lastPageSize}) | ||
) | ||
|
||
return null | ||
} |
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