Skip to content

Commit 9bf3639

Browse files
Add Radiobox component and integrate it into UsersList for role selection
- Created Radiobox component with associated styles. - Updated UsersList to use Radiobox for user role selection, enhancing UI and functionality. - Improved styling for UsersList items and added hover effect.
1 parent 5e69fe1 commit 9bf3639

5 files changed

Lines changed: 67 additions & 14 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.component {
2+
display: flex;
3+
align-items: center;
4+
gap: 0.5rem;
5+
}
6+
7+
.label {
8+
margin: 0;
9+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import classes from './Radiobox.module.css'
2+
3+
export const Radiobox = ({
4+
name,
5+
value,
6+
checked,
7+
onChange,
8+
label,
9+
disabled,
10+
}: {
11+
name: string
12+
value: string
13+
checked: boolean
14+
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void
15+
label: string
16+
disabled?: boolean
17+
} & React.InputHTMLAttributes<HTMLInputElement>) => {
18+
return (
19+
<div className={classes.component}>
20+
<input
21+
type="radio"
22+
name={name}
23+
value={value}
24+
checked={checked}
25+
onChange={onChange}
26+
disabled={disabled}
27+
/>
28+
<label className={classes.label}>{label}</label>
29+
</div>
30+
)
31+
}

src/components/Radiobox/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Radiobox } from './Radiobox'

src/components/UsersList/UsersList.module.css

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,18 @@
1010

1111
.item {
1212
display: flex;
13-
padding: 0 0 1rem 0;
13+
padding: 1rem;
14+
}
15+
16+
.item:hover {
17+
background-color: #e9ecef;
18+
}
19+
20+
.email {
21+
margin: 0;
22+
min-width: 350px;
23+
}
24+
25+
.roles {
26+
margin: 0;
1427
}

src/components/UsersList/UsersList.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import React from 'react'
44
import { useQuery, useMutation } from '@apollo/client'
55
import { GET_USERS, GET_ROLES, UPDATE_USER_ROLE } from '@/db/queries-qraphql'
66
import classes from './UsersList.module.css'
7+
import { Radiobox } from '../Radiobox'
78

89
export const UsersList = () => {
9-
const [updateUserRole] = useMutation(UPDATE_USER_ROLE)
10+
const [updateUserRole, { loading }] = useMutation(UPDATE_USER_ROLE)
1011
const { data: usersData } = useQuery(GET_USERS)
1112
const { data: rolesData } = useQuery(GET_ROLES)
1213

@@ -24,20 +25,18 @@ export const UsersList = () => {
2425
<ul className={classes.list}>
2526
{usersData?.users?.map((user) => (
2627
<li key={user.id} className={classes.item}>
27-
{user.name} ({user.email})
28-
<ol>
28+
<p className={classes.email}>{user.email}</p>
29+
<ol className={classes.roles}>
2930
{rolesData?.roles?.map((role) => (
3031
<li key={role.id}>
31-
<label>
32-
<input
33-
type="radio"
34-
name={`user-${user.id}-role`}
35-
value={role.id}
36-
checked={user.role_id === role.id}
37-
onChange={() => handleUserRoleChange(user.id, role.id)}
38-
/>{' '}
39-
{role.name}
40-
</label>
32+
<Radiobox
33+
name={`user-${user.id}-role`}
34+
value={role.id}
35+
checked={user.role_id === role.id}
36+
onChange={() => handleUserRoleChange(user.id, role.id)}
37+
label={role.name}
38+
disabled={loading}
39+
/>
4140
</li>
4241
))}
4342
</ol>

0 commit comments

Comments
 (0)