-
Notifications
You must be signed in to change notification settings - Fork 14
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
1 parent
bf2bd7e
commit 4deec30
Showing
6 changed files
with
142 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. | ||
* | ||
* This software is licensed under the Apache License, Version 2.0 (the | ||
* "License") as published by the Apache Software Foundation. | ||
* | ||
* You may not use this file except in compliance with the License. You may | ||
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { getApiUrl, useFetchData } from "../../utils"; | ||
|
||
type Roles = Array<{ role: string; permissions: string[] }>; | ||
type GetRolesResponse = | ||
| { | ||
status: "OK"; | ||
roles: Roles; | ||
} | ||
| { | ||
status: "FEATURE_NOT_ENABLED_ERROR"; | ||
}; | ||
|
||
export const useRolesService = () => { | ||
const fetchData = useFetchData(); | ||
|
||
const getRoles = async (): Promise<GetRolesResponse> => { | ||
const response = await fetchData({ | ||
url: getApiUrl("/api/userroles/roles"), | ||
method: "GET", | ||
}); | ||
|
||
if (response.ok) { | ||
const body = await response.json(); | ||
|
||
if (body.status === "FEATURE_NOT_ENABLED_ERROR") { | ||
return { | ||
status: "FEATURE_NOT_ENABLED_ERROR", | ||
}; | ||
} | ||
|
||
return body; | ||
} | ||
|
||
return { | ||
status: "OK", | ||
roles: [], | ||
}; | ||
}; | ||
|
||
const createRole = async (): Promise<{ | ||
status: "OK" | "ROLE_ALREADY_EXITS"; | ||
}> => { | ||
const response = await fetchData({ | ||
url: getApiUrl("/api/userroles/role"), | ||
method: "POST", | ||
}); | ||
|
||
if (response.ok) { | ||
const body = await response.json(); | ||
|
||
if (body.status === "ROLE_ALREADY_EXITS") { | ||
return { | ||
status: "ROLE_ALREADY_EXITS", | ||
}; | ||
} | ||
} | ||
|
||
return { | ||
status: "OK", | ||
}; | ||
}; | ||
|
||
const deleteRole = async (): Promise<void> => { | ||
await fetchData({ | ||
url: getApiUrl("/api/userroles/role"), | ||
method: "DELETE", | ||
}); | ||
}; | ||
|
||
return { | ||
getRoles, | ||
createRole, | ||
deleteRole, | ||
}; | ||
}; | ||
|
||
export default useRolesService; |
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 @@ | ||
.userroles-container { | ||
max-width: 830px; | ||
height: 100vh; | ||
padding: 72px 0px; | ||
margin: auto; | ||
width: 100vw; | ||
} |
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,28 @@ | ||
import { useEffect } from "react"; | ||
import useRolesService from "../../../api/userroles/roles"; | ||
import { Footer } from "../../components/footer/footer"; | ||
import { AppEnvContextProvider } from "../../contexts/AppEnvContext"; | ||
|
||
import "./index.scss"; | ||
|
||
export default function UserRolesList() { | ||
const { getRoles } = useRolesService(); | ||
|
||
useEffect(() => { | ||
void getRoles(); | ||
}, []); | ||
return ( | ||
<AppEnvContextProvider | ||
connectionURI={ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any).connectionURI | ||
}> | ||
<section className="userroles-container">Hello world!</section> | ||
<Footer | ||
colorMode="dark" | ||
horizontalAlignment="center" | ||
verticalAlignment="center" | ||
/> | ||
</AppEnvContextProvider> | ||
); | ||
} |
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