Skip to content

Commit

Permalink
Merge pull request #413 from ryanpwaldon/fix/hide-api-key-and-danger-…
Browse files Browse the repository at this point in the history
…zone-sections-for-non-admins

fix(dashboard): hide danger zone & api key sections for non-admins
  • Loading branch information
vplasencia committed Feb 29, 2024
2 parents 61b344a + 7641946 commit db76f5a
Showing 1 changed file with 85 additions and 79 deletions.
164 changes: 85 additions & 79 deletions apps/dashboard/src/pages/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export default function GroupPage(): JSX.Element {
const [_removeGroupName, setRemoveGroupName] = useState<string>("")
const [_selectedMembers, setSelectedMembers] = useState<string[]>([])
const { admin } = useContext(AuthContext)
const isGroupAdmin = !!(
admin &&
_group &&
(groupType === "off-chain"
? _group.admin === admin.id
: _group.admin === admin.address.toLowerCase())
)

useEffect(() => {
;(async () => {
Expand Down Expand Up @@ -349,82 +356,87 @@ ${memberIds.join("\n")}
</InputGroup>
</Box>
)
{groupType === "off-chain" && !_group.credentials && (
<Box
bgColor="balticSea.50"
p="25px 30px 25px 30px"
borderRadius="8px"
>
<HStack justify="space-between">
<Text fontSize="20px">Use API key</Text>

<Switch
id="enable-api"
isChecked={_group.apiEnabled}
onChange={(event) =>
onApiAccessToggle(event.target.checked)
}
/>
</HStack>

<Text mt="10px" color="balticSea.700">
Connect your app to your group using an API key.
</Text>
{groupType === "off-chain" &&
!_group.credentials &&
isGroupAdmin && (
<Box
bgColor="balticSea.50"
p="25px 30px 25px 30px"
borderRadius="8px"
>
<HStack justify="space-between">
<Text fontSize="20px">Use API key</Text>

<Switch
id="enable-api"
isChecked={_group.apiEnabled}
onChange={(event) =>
onApiAccessToggle(
event.target.checked
)
}
/>
</HStack>

{_group.apiEnabled && (
<>
<InputGroup size="lg" mt="10px">
<Input
pr="50px"
placeholder="API key"
value={_group?.apiKey}
isDisabled
/>
<Text mt="10px" color="balticSea.700">
Connect your app to your group using an API
key.
</Text>

{_group.apiEnabled && (
<>
<InputGroup size="lg" mt="10px">
<Input
pr="50px"
placeholder="API key"
value={_group?.apiKey}
isDisabled
/>

<InputRightElement mr="5px">
<Tooltip
label={
hasCopied
? "Copied!"
: "Copy"
}
closeOnClick={false}
hasArrow
>
<IconButton
variant="link"
aria-label="Copy API key"
onClick={onCopy}
onMouseDown={(e) =>
e.preventDefault()
}
icon={
<Icon
color="sunsetOrange.600"
boxSize="5"
as={FiCopy}
/>
<InputRightElement mr="5px">
<Tooltip
label={
hasCopied
? "Copied!"
: "Copy"
}
/>
</Tooltip>
</InputRightElement>
</InputGroup>

<Button
mt="10px"
variant="link"
color="balticSea.600"
textDecoration="underline"
onClick={generateApiKey}
>
Generate new key
</Button>
</>
)}
</Box>
)}
closeOnClick={false}
hasArrow
>
<IconButton
variant="link"
aria-label="Copy API key"
onClick={onCopy}
onMouseDown={(e) =>
e.preventDefault()
}
icon={
<Icon
color="sunsetOrange.600"
boxSize="5"
as={FiCopy}
/>
}
/>
</Tooltip>
</InputRightElement>
</InputGroup>

<Button
mt="10px"
variant="link"
color="balticSea.600"
textDecoration="underline"
onClick={generateApiKey}
>
Generate new key
</Button>
</>
)}
</Box>
)}
<Image src={image1} />
{_group.type === "off-chain" && (
{_group.type === "off-chain" && isGroupAdmin && (
<Box
bgColor="classicRose.50"
p="25px 30px 25px 30px"
Expand Down Expand Up @@ -482,13 +494,7 @@ ${memberIds.join("\n")}
variant="solid"
colorScheme="secondary"
onClick={addMembersModal.onOpen}
hidden={
!admin ||
(groupType === "off-chain"
? _group.admin !== admin.id
: _group.admin !==
admin.address.toLowerCase())
}
hidden={!isGroupAdmin}
>
Add member
</Button>
Expand Down

0 comments on commit db76f5a

Please sign in to comment.