-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
DiscordCardWarning
component (#1474)
* cleanup(Reward): remove `GoogleCardWarning` component * fix(GoogleCardWarning): remove unused logic/comments + refactor * feat(AccessedGuildPlatformCard): always display warning component * feat: `CardWarningComponentBase` component * cleanup: remove empty imports * feat: `DiscordCardWarning` component * copy(DiscordCardWarning): add "anymore" to the end * fix(AccessedGuildPlatformCard): destructure `useRolePlatform` return value --------- Co-authored-by: valid <[email protected]>
- Loading branch information
1 parent
9ecc70c
commit 14f0f25
Showing
11 changed files
with
127 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useRolePlatform } from "components/[guild]/RolePlatforms/components/RolePlatformProvider" | ||
import useGuildPermission from "components/[guild]/hooks/useGuildPermission" | ||
import useServerPermissions from "hooks/useServerPermissions" | ||
import { ReactNode } from "react" | ||
import { CardWarningComponentBase } from "rewards/components/CardWarningComponentBase" | ||
|
||
const DiscordCardWarning = (): ReactNode => { | ||
const { isAdmin } = useGuildPermission() | ||
if (!isAdmin) return null | ||
|
||
return <DiscordCardWarningWithLogic /> | ||
} | ||
|
||
const DiscordCardWarningWithLogic = (): ReactNode => { | ||
const rolePlatform = useRolePlatform() | ||
const { roleOrders } = useServerPermissions( | ||
// biome-ignore lint/style/noNonNullAssertion: we can be confident that platformGuildId exists at this point | ||
rolePlatform.guildPlatform?.platformGuildId!, | ||
{ | ||
revalidateOnMount: true, | ||
} | ||
) | ||
|
||
const existingDiscordRoles = roleOrders?.map((role) => role.discordRoleId) | ||
|
||
if ( | ||
!existingDiscordRoles || | ||
!rolePlatform.platformRoleId || | ||
existingDiscordRoles.includes(rolePlatform.platformRoleId) | ||
) | ||
return null | ||
|
||
return ( | ||
<CardWarningComponentBase> | ||
This reward won't be assigned to users, because the connected Discord role | ||
doesn't exist anymore | ||
</CardWarningComponentBase> | ||
) | ||
} | ||
|
||
export { DiscordCardWarning } |
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,35 @@ | ||
import { | ||
Icon, | ||
Popover, | ||
PopoverArrow, | ||
PopoverBody, | ||
PopoverContent, | ||
PopoverTrigger, | ||
Portal, | ||
} from "@chakra-ui/react" | ||
import { WarningCircle } from "@phosphor-icons/react" | ||
import { PropsWithChildren, ReactNode } from "react" | ||
|
||
const CardWarningComponentBase = ({ children }: PropsWithChildren): ReactNode => { | ||
return ( | ||
<Popover trigger="hover" openDelay={0}> | ||
<PopoverTrigger> | ||
<Icon | ||
as={WarningCircle} | ||
color="orange.300" | ||
weight="fill" | ||
boxSize={6} | ||
tabIndex={0} | ||
/> | ||
</PopoverTrigger> | ||
<Portal> | ||
<PopoverContent> | ||
<PopoverArrow /> | ||
<PopoverBody>{children}</PopoverBody> | ||
</PopoverContent> | ||
</Portal> | ||
</Popover> | ||
) | ||
} | ||
|
||
export { CardWarningComponentBase } |
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