admin widget , register user
This commit is contained in:
@@ -291,7 +291,29 @@ export function HotelProvider({ accessToken, children, resClientId}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- WS USE EFFECT ----
|
// --- ADMIN PORTAL ----
|
||||||
|
|
||||||
|
function registerUser(username,password,hotel_ids, displayname) {
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
hotel_ids,
|
||||||
|
displayname
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Reg")
|
||||||
|
|
||||||
|
const res = fetch(`${API_BASE}/auth/register`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {"Content-Type": "application/json"},
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -372,16 +394,14 @@ export function HotelProvider({ accessToken, children, resClientId}) {
|
|||||||
users,
|
users,
|
||||||
usersById,
|
usersById,
|
||||||
clientId,
|
clientId,
|
||||||
updateRoomStatus,
|
|
||||||
fetchMessages,
|
|
||||||
fetchConvUsers,
|
|
||||||
sendMessage,
|
|
||||||
fetchHotelUsers,
|
fetchHotelUsers,
|
||||||
addUserToConv,
|
updateRoomStatus,
|
||||||
createConversation,
|
fetchMessages, fetchConvUsers, sendMessage,
|
||||||
fetchHotelInventory,
|
addUserToConv, createConversation,
|
||||||
updateItemAmount,
|
fetchHotelInventory, updateItemAmount, createItem,
|
||||||
createItem
|
|
||||||
|
registerUser
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import ChatWidget from "./widget/chatWidget"
|
|||||||
import InventoryWidget from "./widget/inventoryWidget";
|
import InventoryWidget from "./widget/inventoryWidget";
|
||||||
|
|
||||||
import "./MainApp.css"
|
import "./MainApp.css"
|
||||||
|
import AdminWidget from "./widget/adminWidget";
|
||||||
|
|
||||||
export default function MainAppWrapper({resClientId}) {
|
export default function MainAppWrapper({resClientId}) {
|
||||||
const accessToken = localStorage.getItem("access_tokens");
|
const accessToken = localStorage.getItem("access_tokens");
|
||||||
@@ -31,10 +32,11 @@ function MainApp() {
|
|||||||
<h2>Dashboard</h2>
|
<h2>Dashboard</h2>
|
||||||
<section className="main">
|
<section className="main">
|
||||||
|
|
||||||
|
<AdminWidget/>
|
||||||
<RoomWidget roomlist={rooms}/>
|
<RoomWidget roomlist={rooms}/>
|
||||||
<ChatWidget convlist={conversations}/>
|
<ChatWidget convlist={conversations}/>
|
||||||
<InventoryWidget/>
|
<InventoryWidget/>
|
||||||
|
<AdminWidget/>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
64
src/components/widget/adminWidget.jsx
Normal file
64
src/components/widget/adminWidget.jsx
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
import { useHotel } from "../HotelContext";
|
||||||
|
|
||||||
|
|
||||||
|
export default function AdminWidget() {
|
||||||
|
|
||||||
|
const [username, setUserName] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [hotel_ids, setHotelIds] = useState([]);
|
||||||
|
const [display_name, setDisplayName] = useState("");
|
||||||
|
|
||||||
|
const {
|
||||||
|
registerUser
|
||||||
|
} = useHotel()
|
||||||
|
|
||||||
|
|
||||||
|
const createUser = (username, password, hotel_ids, display_name) => {
|
||||||
|
|
||||||
|
registerUser(username, password, hotel_ids, display_name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return(
|
||||||
|
|
||||||
|
<div className="adminWidget">
|
||||||
|
<input
|
||||||
|
value={username}
|
||||||
|
onChange={e => setUserName(e.target.value)}
|
||||||
|
placeholder="NomDeCompte"
|
||||||
|
type="text" />
|
||||||
|
|
||||||
|
<input
|
||||||
|
value={password}
|
||||||
|
onChange={e => setPassword(e.target.value)}
|
||||||
|
placeholder="Mot de Passe"
|
||||||
|
type="text" />
|
||||||
|
|
||||||
|
<input
|
||||||
|
value={display_name}
|
||||||
|
onChange={e => setDisplayName(e.target.value)}
|
||||||
|
placeholder="Nome afficher"
|
||||||
|
type="text" />
|
||||||
|
|
||||||
|
<input
|
||||||
|
value={hotel_ids}
|
||||||
|
onChange={e => setHotelIds(e.target.value.split(",").map(Number))}
|
||||||
|
placeholder="hotels"
|
||||||
|
type="text" />
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() =>
|
||||||
|
registerUser(username, password, hotel_ids, display_name)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Créer l'utilisateur
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user