-
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
Zabilsya
committed
Dec 9, 2024
1 parent
4cbe3c2
commit f6500f0
Showing
24 changed files
with
148 additions
and
21 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
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
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,33 @@ | ||
import React from 'react'; | ||
import { Typography } from 'antd'; | ||
import { PageContentWrapper } from '@shared/ui'; | ||
import { useParams } from 'react-router-dom'; | ||
import { PageDetailParams, UserRole } from '@shared/types'; | ||
import { useGetGroup } from '@entities/group'; | ||
import { hasAccessByUserRole } from '@shared/utils'; | ||
import { AccessError } from '@shared/config'; | ||
import { useGetTransfer } from '@entities/transfer'; | ||
import { UpdateTransfer } from '@widgets/transfer'; | ||
|
||
const { Title } = Typography; | ||
|
||
export const UpdateTransferPage = () => { | ||
const params = useParams<PageDetailParams>(); | ||
const { data: transfer } = useGetTransfer({ id: Number(params.id) }); | ||
const { data: group } = useGetGroup({ id: transfer.group_id }); | ||
|
||
if (!transfer || !group) { | ||
return null; | ||
} | ||
|
||
if (!hasAccessByUserRole(UserRole.Maintainer, group.role)) { | ||
throw new AccessError(); | ||
} | ||
|
||
return ( | ||
<PageContentWrapper width="small"> | ||
<Title>Update Transfer</Title> | ||
<UpdateTransfer transfer={transfer} group={group.data} /> | ||
</PageContentWrapper> | ||
); | ||
}; |
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,3 +1,4 @@ | ||
export * from './TransferListPage'; | ||
export * from './TransferDetailPage'; | ||
export * from './CreateTransferPage'; | ||
export * from './UpdateTransferPage'; |
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
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
13 changes: 13 additions & 0 deletions
13
src/widgets/transfer/TransferDetail/components/UpdateTransferButton/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { Button } from 'antd'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { UpdateTransferButtonProps } from './types'; | ||
|
||
export const UpdateTransferButton = ({ transferId }: UpdateTransferButtonProps) => { | ||
return ( | ||
<Button type="primary" size="large"> | ||
<Link to={`/transfers/${transferId}/update`}>Update Transfer</Link> | ||
</Button> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
src/widgets/transfer/TransferDetail/components/UpdateTransferButton/types.ts
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,3 @@ | ||
export interface UpdateTransferButtonProps { | ||
transferId: number; | ||
} |
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 +1,2 @@ | ||
export * from './DeleteTransferButton'; | ||
export * from './UpdateTransferButton'; |
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,43 @@ | ||
import React from 'react'; | ||
import { ManagedForm } from '@shared/ui'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { Transfer, TransferQueryKey, transferService } from '@entities/transfer'; | ||
import { MutateTransferForm } from '@features/transfer'; | ||
|
||
import { UpdateTransferForm, UpdateTransferProps } from './types'; | ||
|
||
export const UpdateTransfer = ({ transfer, group }: UpdateTransferProps) => { | ||
const { id: transferId, group_id, ...transferInitialValues } = transfer; | ||
const navigate = useNavigate(); | ||
|
||
const handleUpdateTransfer = (values: UpdateTransferForm) => { | ||
return transferService.updateTransfer({ id: transferId, ...values }); | ||
}; | ||
|
||
const onSuccess = (response: Transfer) => { | ||
navigate(`/transfers/${response.id}`); | ||
}; | ||
|
||
const onCancel = () => { | ||
navigate('/transfers'); | ||
}; | ||
|
||
return ( | ||
<ManagedForm<UpdateTransferForm, Transfer> | ||
initialValues={transferInitialValues} | ||
mutationFunction={handleUpdateTransfer} | ||
onSuccess={onSuccess} | ||
keysInvalidateQueries={[ | ||
[{ queryKey: [TransferQueryKey.GET_TRANSFERS, group.id] }], | ||
[{ queryKey: [TransferQueryKey.GET_TRANSFER, transfer.id] }], | ||
]} | ||
> | ||
<MutateTransferForm | ||
initialSourceConnectionType={transferInitialValues.source_params.type} | ||
initialTargetConnectionType={transferInitialValues.target_params.type} | ||
group={group} | ||
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,9 @@ | ||
import { GroupData } from '@entities/group'; | ||
import { Transfer, UpdateTransferRequest } from '@entities/transfer'; | ||
|
||
export interface UpdateTransferForm extends Omit<UpdateTransferRequest, 'id'> {} | ||
|
||
export interface UpdateTransferProps { | ||
transfer: Transfer; | ||
group: GroupData; | ||
} |
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,3 +1,4 @@ | ||
export * from './TransferListWrapper'; | ||
export * from './TransferDetail'; | ||
export * from './CreateTransfer'; | ||
export * from './UpdateTransfer'; |