-
Notifications
You must be signed in to change notification settings - Fork 0
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
Zablisya
committed
Oct 14, 2024
1 parent
e9ed451
commit 7c1f9a6
Showing
57 changed files
with
508 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { AntdConfigProvider, AppRoutes } from '@app/config'; | ||
import { SelectedGroupProvider } from '@entities/group'; | ||
import { TanstackQueryProvider } from '@shared/config'; | ||
import React from 'react'; | ||
|
||
export const App = () => ( | ||
<TanstackQueryProvider> | ||
<AntdConfigProvider> | ||
<AppRoutes /> | ||
<SelectedGroupProvider> | ||
<AppRoutes /> | ||
</SelectedGroupProvider> | ||
</AntdConfigProvider> | ||
</TanstackQueryProvider> | ||
); |
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 |
---|---|---|
@@ -1,14 +1,29 @@ | ||
import { axiosInstance } from '@shared/config'; | ||
import { PaginationResponse } from '@shared/types'; | ||
|
||
import { GetGroupRequest, GetGroupsRequest, Group } from './types'; | ||
import { | ||
CreateGroupRequest, | ||
GetGroupRequest, | ||
GetGroupsRequest, | ||
Group, | ||
GroupFromList, | ||
UpdateGroupRequest, | ||
} from './types'; | ||
|
||
export const groupService = { | ||
getGroups: (params: GetGroupsRequest): Promise<PaginationResponse<Group>> => { | ||
getGroups: (params: GetGroupsRequest): Promise<PaginationResponse<GroupFromList>> => { | ||
return axiosInstance.get('groups', { params }); | ||
}, | ||
|
||
getGroup: ({ id }: GetGroupRequest): Promise<Group> => { | ||
return axiosInstance.get(`groups/${id}`); | ||
}, | ||
|
||
createGroup: (data: CreateGroupRequest): Promise<Group> => { | ||
return axiosInstance.post(`groups`, data); | ||
}, | ||
|
||
updateGroup: ({ id, ...data }: UpdateGroupRequest): Promise<Group> => { | ||
return axiosInstance.patch(`groups/${id}`, data); | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './api'; | ||
export * from './ui'; | ||
export * from './providers'; | ||
export * from './hooks'; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Group } from './api'; | ||
import { GroupFromList } from './api'; | ||
|
||
export interface SelectedGroupContextProps { | ||
group: Group | null; | ||
selectGroup: (group: Group) => void; | ||
group: GroupFromList | null; | ||
selectGroup: (group: GroupFromList) => void; | ||
} |
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
import { User } from '@entities/user'; | ||
|
||
export interface UserDetailInfoProps { | ||
user: User; | ||
} |
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,35 @@ | ||
import React, { memo } from 'react'; | ||
import { FormButtons, ManagedForm } from '@shared/ui'; | ||
import { Group, GroupQueryKey, groupService } from '@entities/group'; | ||
import { Form, Input } from 'antd'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export const CreateGroup = memo(() => { | ||
const navigate = useNavigate(); | ||
|
||
const onSuccess = (response: Group) => { | ||
navigate(`/groups/${response.id}`); | ||
}; | ||
|
||
const onCancel = () => { | ||
navigate('/groups'); | ||
}; | ||
|
||
return ( | ||
<ManagedForm | ||
mutationFunction={groupService.createGroup} | ||
onSuccess={onSuccess} | ||
keysInvalidateQueries={[[{ queryKey: [GroupQueryKey.GET_GROUPS] }]]} | ||
> | ||
<Form.Item label="Name" name="name" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
|
||
<Form.Item label="Description" name="description"> | ||
<Input size="large" /> | ||
</Form.Item> | ||
|
||
<FormButtons onCancel={onCancel} /> | ||
</ManagedForm> | ||
); | ||
}); |
11 changes: 3 additions & 8 deletions
11
...tities/group/ui/GroupDetailInfo/index.tsx → src/features/group/GroupDetailInfo/index.tsx
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,8 @@ | ||
import { Group } from '@entities/group'; | ||
import { User } from '@entities/user'; | ||
import { DescriptionsProps } from 'antd'; | ||
|
||
export interface GroupDetailInfoProps extends DescriptionsProps { | ||
group: Group; | ||
owner: User; | ||
} |
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 |
---|---|---|
@@ -1,16 +1,27 @@ | ||
import React, { memo } from 'react'; | ||
import { ManagedTable } from '@shared/ui'; | ||
import { GroupQueryKey, groupService } from '@entities/group'; | ||
import { GroupFromList, GroupQueryKey, groupService } from '@entities/group'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { hasAccessByUserRole } from '@shared/utils'; | ||
import { UserRole } from '@shared/types'; | ||
|
||
import { GROUP_LIST_COLUMNS } from './constants'; | ||
|
||
export const GroupList = memo(() => { | ||
const navigate = useNavigate(); | ||
|
||
const handleUpdateRowClick = (record: GroupFromList) => { | ||
navigate(`/groups/${record.data.id}/update`); | ||
}; | ||
|
||
return ( | ||
<ManagedTable | ||
queryKey={[GroupQueryKey.GET_GROUPS]} | ||
queryFunction={groupService.getGroups} | ||
columns={GROUP_LIST_COLUMNS} | ||
rowKey="id" | ||
isRenderUpdateRowAction={(record) => hasAccessByUserRole(UserRole.Owner, record.role)} | ||
onUpdateRowClick={handleUpdateRowClick} | ||
rowKey={(row) => row.data.id} | ||
/> | ||
); | ||
}); |
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,63 @@ | ||
import React, { memo, useMemo } from 'react'; | ||
import { FormButtons, ManagedForm, ManagedSelect } from '@shared/ui'; | ||
import { Group, GroupQueryKey, groupService } from '@entities/group'; | ||
import { Form, Input } from 'antd'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { UserQueryKey, userService } from '@entities/user'; | ||
|
||
import { UpdateGroupForm, UpdateGroupProps } from './types'; | ||
import { getUpdateGroupInitialValues } from './utils'; | ||
|
||
export const UpdateGroup = memo(({ group }: UpdateGroupProps) => { | ||
const navigate = useNavigate(); | ||
|
||
const initialValues = useMemo(() => { | ||
return getUpdateGroupInitialValues(group); | ||
}, [group]); | ||
|
||
const handleUpdateGroup = (values: UpdateGroupForm) => { | ||
return groupService.updateGroup({ ...values, id: group.id }); | ||
}; | ||
|
||
const onSuccess = (response: Group) => { | ||
navigate(`/groups/${response.id}`); | ||
}; | ||
|
||
const onCancel = () => { | ||
navigate('/groups'); | ||
}; | ||
|
||
return ( | ||
<ManagedForm<UpdateGroupForm, Group> | ||
mutationFunction={handleUpdateGroup} | ||
initialValues={initialValues} | ||
onSuccess={onSuccess} | ||
keysInvalidateQueries={[ | ||
[{ queryKey: [GroupQueryKey.GET_GROUPS] }], | ||
[{ queryKey: [GroupQueryKey.GET_GROUP, group.id] }], | ||
]} | ||
> | ||
<Form.Item label="Name" name="name" rules={[{ required: true }]}> | ||
<Input size="large" /> | ||
</Form.Item> | ||
|
||
<Form.Item label="Description" name="description"> | ||
<Input size="large" /> | ||
</Form.Item> | ||
|
||
<Form.Item label="Owner" name="owner_id" rules={[{ required: true }]}> | ||
<ManagedSelect | ||
size="large" | ||
queryKey={[UserQueryKey.GET_USERS]} | ||
queryFunction={userService.getUsers} | ||
renderOptionValue={(user) => user.id} | ||
renderOptionLabel={(user) => user.username} | ||
//TODO: [DOP-20026] Need to delete prop "disabled" when the backend leaves the user with access to the group, even after changing the owner | ||
disabled | ||
/> | ||
</Form.Item> | ||
|
||
<FormButtons onCancel={onCancel} /> | ||
</ManagedForm> | ||
); | ||
}); |
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 @@ | ||
import { Group, UpdateGroupRequest } from '@entities/group'; | ||
|
||
export interface UpdateGroupForm extends Omit<UpdateGroupRequest, 'id'> {} | ||
|
||
export interface UpdateGroupProps { | ||
group: Group; | ||
} |
Oops, something went wrong.