-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathDisplaySecretModal.tsx
More file actions
112 lines (111 loc) · 3.48 KB
/
Copy pathDisplaySecretModal.tsx
File metadata and controls
112 lines (111 loc) · 3.48 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
import {
Button,
HStack,
IconButton,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Table,
TableContainer,
Tbody,
Td,
Text,
Tr,
} from '@chakra-ui/react';
import { DateWithTooltip } from 'dogma/common/components/DateWithTooltip';
import { newNotification } from 'dogma/features/notification/notificationSlice';
import { AppIdentityDto, isToken, isCertificate } from 'dogma/features/app-identity/AppIdentity';
import { MetadataPropertiesSchema } from 'dogma/features/metadata-properties/MetadataProperties';
import { useAppDispatch } from 'dogma/hooks';
import { MdContentCopy } from 'react-icons/md';
export const DisplaySecretModal = ({
isOpen,
onClose,
response,
schema,
}: {
isOpen: boolean;
onClose: () => void;
response: AppIdentityDto;
schema?: MetadataPropertiesSchema;
}) => {
const dispatch = useAppDispatch();
if (!response) return;
const { appId, systemAdmin, creation } = response;
return (
<Modal isOpen={isOpen} onClose={onClose} motionPreset="slideInBottom">
<ModalOverlay />
<ModalContent minWidth="max-content">
<ModalHeader>Application identity generated</ModalHeader>
<ModalCloseButton />
<ModalBody>
<TableContainer minWidth="max-content">
<Table whiteSpace="normal">
<Tbody>
<Tr>
<Td>Application ID</Td>
<Td>{appId}</Td>
</Tr>
{isToken(response) && response.secret && (
<Tr>
<Td>Secret</Td>
<Td>
<HStack>
<Text>{response.secret}</Text>
<IconButton
aria-label="Copy to clipboard"
icon={<MdContentCopy />}
variant="ghost"
onClick={async () => {
await navigator.clipboard.writeText(response.secret || '');
dispatch(newNotification('', 'copied to clipboard', 'success'));
}}
/>
</HStack>
</Td>
</Tr>
)}
{isCertificate(response) && (
<Tr>
<Td>Certificate ID</Td>
<Td>{response.certificateId}</Td>
</Tr>
)}
{response.properties &&
Object.entries(response.properties).map(([key, value]) => (
<Tr key={key}>
<Td>{schema?.properties?.[key]?.title || key}</Td>
<Td>{String(value)}</Td>
</Tr>
))}
<Tr>
<Td>Level</Td>
<Td>{systemAdmin ? 'System Admin' : 'User'}</Td>
</Tr>
<Tr>
<Td>Created by</Td>
<Td>{creation.user}</Td>
</Tr>
<Tr>
<Td>Created at </Td>
<Td>
<DateWithTooltip date={creation.timestamp} />
</Td>
</Tr>
</Tbody>
</Table>
</TableContainer>
</ModalBody>
<ModalFooter>
<Button colorScheme="teal" onClick={onClose}>
OK
</Button>
</ModalFooter>
</ModalContent>
</Modal>
);
};