mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-04 01:18:20 +02:00
* feat: add user groups table * add groups and group view * fix top level await on mock data * add UG flag * create group files, refactor group cards * add generic badge component * adapt hooks to use endpoints * implement basic create group * fix: update snap * fix: type id as string for now * implement create group, use api, refactoring * add stars to group owners * refactor GroupForm.tsx to use styled components * feat: remove group * add edit group * add group card actions * feat: edit and remove group users * add users to groups * Initial commit * refine project access table * add project access group view * Take users and groups from backend * Add onsubmit * new project access, assign and edit * fix EditGroup, Group * Finish assigning roles in project * List assigned projects in group card * Run prettier * Add added column to project access table Co-authored-by: Jaanus Sellin <jaanus@getunleash.ai> Co-authored-by: sighphyre <liquidwicked64@gmail.com>
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import useQueryParams from 'hooks/useQueryParams';
|
|
import { IGroupUser, Role } from 'interfaces/group';
|
|
|
|
export const useGroupForm = (
|
|
initialName = '',
|
|
initialDescription = '',
|
|
initialUsers: IGroupUser[] = []
|
|
) => {
|
|
const params = useQueryParams();
|
|
const groupQueryName = params.get('name');
|
|
const [name, setName] = useState(groupQueryName || initialName);
|
|
const [description, setDescription] = useState(initialDescription);
|
|
const [users, setUsers] = useState<IGroupUser[]>(initialUsers);
|
|
const [errors, setErrors] = useState({});
|
|
|
|
useEffect(() => {
|
|
if (!name) {
|
|
setName(groupQueryName || initialName);
|
|
}
|
|
}, [name, initialName, groupQueryName]);
|
|
|
|
useEffect(() => {
|
|
setDescription(initialDescription);
|
|
}, [initialDescription]);
|
|
|
|
const initialUsersStringified = JSON.stringify(initialUsers);
|
|
|
|
useEffect(() => {
|
|
setUsers(initialUsers);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [initialUsersStringified]);
|
|
|
|
const getGroupPayload = () => {
|
|
return {
|
|
name,
|
|
description,
|
|
users: users.map(({ id, role }) => ({
|
|
user: { id },
|
|
role: role || Role.Member,
|
|
})),
|
|
};
|
|
};
|
|
|
|
const clearErrors = () => {
|
|
setErrors({});
|
|
};
|
|
|
|
return {
|
|
name,
|
|
setName,
|
|
description,
|
|
setDescription,
|
|
users,
|
|
setUsers,
|
|
getGroupPayload,
|
|
clearErrors,
|
|
errors,
|
|
};
|
|
};
|