-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
97 user role crud #100
Merged
Merged
97 user role crud #100
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b5bf006
role table api
indpurvesh 76e727c
fetch role info api
indpurvesh 7c4fd6e
input component changes
indpurvesh 851ffe8
role create and update
indpurvesh c561142
role table , create, edit
indpurvesh 27d8fd2
Update RoleCreate.jsx
indpurvesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import {useState} from "react"; | ||
import {Link, redirect, useNavigate} from "react-router-dom"; | ||
import axios from "axios"; | ||
|
||
function RoleCreate() { | ||
const [name, setName] = useState('Editor'); | ||
const [identifier, setIdentifier] = useState('editor'); | ||
const navigate = useNavigate() | ||
|
||
const handleSubmit = (async (e) => { | ||
e.preventDefault() | ||
|
||
const created_page_response = await axios({ | ||
url: 'http://localhost:8080/api/role', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + localStorage.getItem("AUTH_TOKEN"), | ||
}, | ||
data: JSON.stringify({name: name, identifier: identifier, permissions: []}) | ||
}) | ||
if (created_page_response.status) { | ||
return navigate("/admin/role"); | ||
} | ||
}) | ||
|
||
return ( | ||
<div className="flex-1 bg-white"> | ||
<div className="px-5 pl-64 "> | ||
<div className="w-full"> | ||
<div className="block rounded-lg p-6"> | ||
<h1 className="text-xl font-semibold mb-4 text-gray-900 dark:text-gray-100"> | ||
Role Information | ||
</h1> | ||
{/*<p className="text-gray-600 dark:text-gray-300 mb-6">Use a permanent address where you can*/} | ||
{/* receive mail.</p>*/} | ||
<form onSubmit={handleSubmit}> | ||
<div className="mb-4"> | ||
<input type="text" placeholder="Name" | ||
value={name} | ||
onChange={e => setName(e.target.value)} | ||
className="border p-2 rounded w-full"/> | ||
</div> | ||
<div className="mb-4"> | ||
<input type="text" | ||
placeholder="Identifier" | ||
value={identifier} | ||
onChange={e => setIdentifier(e.target.value)} | ||
className="border p-2 rounded w-full"/> | ||
</div> | ||
<div className="flex items-center"> | ||
<button type="submit" | ||
className="bg-primary-600 py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500" | ||
> | ||
Save | ||
</button> | ||
<Link to="/admin/page" | ||
className="ml-auto font-medium text-gray-600 hover:text-gray-500"> | ||
Cancel | ||
</Link> | ||
</div> | ||
|
||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default RoleCreate |
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,103 @@ | ||
import {useEffect, useState} from "react"; | ||
import {Link, redirect, useNavigate, useParams} from "react-router-dom"; | ||
import {isEmpty} from "lodash"; | ||
import axios from "axios"; | ||
|
||
function RoleEdit() { | ||
const [name, setName] = useState('Contact US update'); | ||
const [identifier, setIdentifier] = useState('contact-us-update'); | ||
const navigate = useNavigate() | ||
const params = useParams(); | ||
|
||
|
||
useEffect(() => { | ||
const mounted = (async () => { | ||
const response = await axios({ | ||
url: 'http://localhost:8080/api/role/' + params.role_id, | ||
method: 'get', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + localStorage.getItem("AUTH_TOKEN"), | ||
} | ||
}) | ||
|
||
if (!response.status) { | ||
return | ||
} | ||
|
||
return response.data | ||
}) | ||
|
||
mounted().then((res) => { | ||
if (isEmpty(res)) { | ||
localStorage. removeItem("AUTH_TOKEN") | ||
return navigate("/admin/login") | ||
} | ||
|
||
setName(res.role_model.name) | ||
setIdentifier(res.role_model.identifier) | ||
}) | ||
|
||
}, []) | ||
|
||
const handleSubmit = (async (e) => { | ||
e.preventDefault() | ||
const updated_role_response = await axios({ | ||
url: 'http://localhost:8080/api/role/' + params.role_id, | ||
method: 'put', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + localStorage.getItem("AUTH_TOKEN"), | ||
}, | ||
data: JSON.stringify({name: name, identifier: identifier, permissions: []}) | ||
}) | ||
if (updated_role_response.status) { | ||
return navigate("/admin/role"); | ||
} | ||
}) | ||
|
||
return ( | ||
<div className="flex-1 bg-white"> | ||
<div className="px-5 pl-64"> | ||
<div className="w-full"> | ||
<div className="block rounded-lg p-6"> | ||
<h1 className="text-xl font-semibold mb-4 text-gray-900 dark:text-gray-100"> | ||
Role Information | ||
</h1> | ||
{/*<p className="text-gray-600 dark:text-gray-300 mb-6">Use a permanent address where you can*/} | ||
{/* receive mail.</p>*/} | ||
<form onSubmit={handleSubmit}> | ||
<div className="mb-4"> | ||
<input type="text" placeholder="Name" | ||
value={name} | ||
onChange={e => setName(e.target.value)} | ||
className="border p-2 rounded w-full"/> | ||
</div> | ||
<div className="mb-4"> | ||
<input type="text" | ||
placeholder="Identifier" | ||
value={identifier} | ||
onChange={e => setIdentifier(e.target.value)} | ||
className="border p-2 rounded w-full"/> | ||
</div> | ||
<div className="flex items-center"> | ||
<button type="submit" | ||
className="bg-primary-600 py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500" | ||
> | ||
Save | ||
</button> | ||
<Link to="/admin/role" | ||
className="ml-auto font-medium text-gray-600 hover:text-gray-500"> | ||
Cancel | ||
</Link> | ||
</div> | ||
|
||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default RoleEdit |
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,102 @@ | ||
import {useEffect, useState} from "react"; | ||
import {Link, redirect, useNavigate} from "react-router-dom"; | ||
import {isEmpty} from "lodash"; | ||
import axios from "axios"; | ||
|
||
function RoleTable() { | ||
const [roles, setRoles] = useState([]); | ||
const navigate = useNavigate() | ||
|
||
const getFormattedDate = ((date) => { | ||
var date = new Date(date); | ||
|
||
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`; | ||
}) | ||
|
||
useEffect(() => { | ||
const mounted = (async () => { | ||
|
||
const response = await axios({ | ||
url: 'http://localhost:8080/api/role', | ||
method: 'get', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + localStorage.getItem("AUTH_TOKEN"), | ||
} | ||
}) | ||
return response | ||
}) | ||
|
||
mounted().then(({data}) => { | ||
console.log(data) | ||
if (isEmpty(data)) { | ||
localStorage.removeItem("AUTH_TOKEN") | ||
return navigate("/admin/login") | ||
} | ||
setRoles(data.data) | ||
}) | ||
|
||
}, []) | ||
|
||
return ( | ||
<div className="flex-1 bg-white"> | ||
<div className="px-5 ml-64"> | ||
<div className="flex items-center"> | ||
<div className="p-5 text-2xl font-semibold text-primary-500"> | ||
Roles | ||
</div> | ||
<Link className="ml-auto bg-primary-600 py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500" | ||
to="/admin/role-create"> | ||
Create | ||
</Link> | ||
</div> | ||
|
||
|
||
<div className="overflow-x-hidden"> | ||
<table className="min-w-full bg-white shadow-md rounded"> | ||
<thead> | ||
<tr className="bg-gray-700 text-white"> | ||
<th className="py-3 px-4 rounded-l font-semibold text-left">ID</th> | ||
<th className="py-3 px-4 font-semibol text-left">Name</th> | ||
<th className="py-3 px-4 font-semibol text-left">Identifier</th> | ||
<th className="py-3 px-4 font-semibol text-left">Created at</th> | ||
<th className="py-3 px-4 font-semibol text-left">Updated at</th> | ||
<th className="py-3 px-4 font-semibol text-left">Created by</th> | ||
<th className="py-3 px-4 font-semibol text-left">Updated by</th> | ||
<th className="py-3 px-4 rounded-r font-semibol text-left">Action</th> | ||
</tr> | ||
</thead> | ||
<tbody className=""> | ||
{roles.map((role) => { | ||
return ( | ||
<tr key={role.id} className="border-b"> | ||
<td className="py-3 px-4">{role.id}</td> | ||
<td className="py-3 px-4">{role.name}</td> | ||
<td className="py-3 px-4">{role.identifier}</td> | ||
<td className="py-3 px-4"> | ||
{getFormattedDate(role.created_at)} | ||
</td> | ||
<td className="py-3 px-4"> | ||
{getFormattedDate(role.updated_at)} | ||
</td> | ||
<td className="py-3 px-4">{role.created_by}</td> | ||
<td className="py-3 px-4">{role.updated_by}</td> | ||
<td className="py-3 px-4"> | ||
<Link className="font-medium text-primary-600 hover:text-primary-800" | ||
to={`/admin/role-edit/${role.id}`}> | ||
Edit | ||
</Link> | ||
|
||
</td> | ||
</tr> | ||
) | ||
})} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default RoleTable |
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,34 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::models::role_model::RoleModel; | ||
use crate::{ | ||
avored_state::AvoRedState, error::Result | ||
}; | ||
|
||
use axum::{extract::{Path as AxumPath, State}, Json, response::IntoResponse}; | ||
use serde::Serialize; | ||
|
||
pub async fn fetch_role_api_handler( | ||
AxumPath(role_id): AxumPath<String>, | ||
state: State<Arc<AvoRedState>> | ||
) -> Result<impl IntoResponse> { | ||
println!("->> {:<12} - fetch_role_api_handler", "HANDLER"); | ||
|
||
let role_model = state | ||
.role_service | ||
.find_by_id(&state.db, role_id) | ||
.await?; | ||
let response = FetchPageResponse { | ||
status: true, | ||
role_model: role_model | ||
}; | ||
|
||
Ok(Json(response)) | ||
} | ||
|
||
|
||
#[derive(Serialize, Debug)] | ||
pub struct FetchPageResponse { | ||
pub status: bool, | ||
pub role_model: RoleModel | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / clippy
redundant field names in struct initialization Warning