-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathRenameTeam.tsx
More file actions
126 lines (122 loc) · 3.21 KB
/
Copy pathRenameTeam.tsx
File metadata and controls
126 lines (122 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import {
Button,
Image,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalHeader,
ModalOverlay,
useDisclosure,
Text,
Spinner,
ButtonProps
} from '@chakra-ui/react';
import CustomInput from './Input';
import { useState, useEffect } from 'react';
import { useCustomToast } from '@/hooks/useCustomToast';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { renameRequest } from '@/api/namespace';
import { ApiResp } from '@/types';
import { useTranslation } from 'next-i18next';
import { EditIcon } from '@labring/sealos-ui';
export default function RenameTeam({
ns_uid,
defaultTeamName,
...props
}: {
ns_uid: string;
defaultTeamName: string;
} & ButtonProps) {
const { onOpen, isOpen, onClose } = useDisclosure();
const [teamName, setTeamName] = useState(defaultTeamName);
const { toast } = useCustomToast({ status: 'error' });
const queryClient = useQueryClient();
useEffect(() => {
setTeamName(defaultTeamName);
}, [defaultTeamName]);
const mutation = useMutation({
mutationFn: renameRequest,
onSuccess() {
setTeamName(defaultTeamName);
queryClient.invalidateQueries({
queryKey: ['teamList'],
exact: false
});
queryClient.invalidateQueries({
queryKey: ['ns-detail'],
exact: false
});
onClose();
},
onError(error) {
toast({ title: (error as ApiResp).message });
}
});
const { t } = useTranslation();
const submit = () => {
mutation.mutate({ ns_uid, teamName });
};
return (
<>
<Button
size={'sm'}
height={'32px'}
variant={'outline'}
{...props}
leftIcon={<EditIcon boxSize={'14px'} />}
onClick={onOpen}
>
{t('common:rename')}
</Button>
<Modal isOpen={isOpen} onClose={onClose} isCentered>
<ModalOverlay />
<ModalContent
borderRadius={'4px'}
maxW={'380px'}
bgColor={'#FFF'}
backdropFilter="blur(150px)"
p="24px"
>
<ModalCloseButton right={'24px'} top="16px" p="0" />
<ModalHeader bg={'white'} border={'none'} p="0">
{t('common:rename')}
</ModalHeader>
{mutation.isLoading ? (
<Spinner mx="auto" />
) : (
<ModalBody h="100%" w="100%" p="0" mt="22px">
<CustomInput
onChange={(e) => {
e.preventDefault();
setTeamName(e.target.value);
}}
placeholder={t('common:name_of_team') || ''}
value={teamName}
/>
<Button
w="100%"
variant={'unstyled'}
bg="#24282C"
borderRadius={'4px'}
color="#fff"
py="6px"
px="12px"
mt="24px"
_hover={{
opacity: '0.8'
}}
onClick={(e) => {
e.preventDefault();
submit();
}}
>
{t('common:confirm')}
</Button>
</ModalBody>
)}
</ModalContent>
</Modal>
</>
);
}