-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dynamic reward setup flow from role editor (#1222)
* feat(AddRequirement): support for displaying provided dynamic value during setup * feat(DynamicRewardModal): support value provider requirements * extract & dynamic import DataProviderRequirement from new component * feat: dynamic setup button & base value selector WIP * feat: BaseValueModal with Add requirement btn * refactor(AddRoleRewardModal): WIP * feat(DynamicRewardModal): reward amount calculation breakdown (#1213) * feat(DynamicRewardModal): reward amount calculation breakdown * feat(PointsReward): calculate dynamic reward amount * fix(PointsReward): add optional chaining * refactor(PointsReward): batch score calculation into memo fn with early return * fix(PointsReward): "some" fallback if the role is not held * cleanup: remove useMembership changes, use existing prop * abstract into useDynamicRewardUserAmount hook * DynamicRewardCalculationTable: add not connected fallback * UI: move DynamicTag to same row if there's enough space & modal info footer whitespace * fix(CalculationTable): handle fallback if connected but there's no provided value --------- Co-authored-by: valid <valid@zgen.hu> * feat: warning on linked requirement delete (#1214) * feat: warning on linked requirement delete * refactor: extract ExistingRequirementDeleteAlert & useHasLinkedReward --------- Co-authored-by: valid <valid@zgen.hu> * feat: submit dynamic point reward * fix: show images on conversion step & minor fixes * feat: EditDynamicRewardModal * fix: display conversion value flooring warning message only when necessary * fix: round down point amount * feat(InformationModal): info modal in dynamic reward setup * fix(InformationModal): light mode for illustration * fix: lint error * refactor: use AddRewardContext instead of jotai atom for target role * dynamic points setup into SetPointsAmount * UI: whitespace impros & shadow to border * cleanup(AddPointsPanel): variables order * UI(DynamicRewardModal): footerBg impros * fix(AddPointsPanel): disable continue btn if baseValue is not set * fix: minor copy change * fix(BaseValueModal): better copy about base values provided by reqs * pass targetRoleId to provider as prop, adjust disabled tooltip copy * feat(RolePlatforms): display dynamic tag on edit role panel --------- Co-authored-by: valid <valid@zgen.hu>
- Loading branch information
Showing
41 changed files
with
1,729 additions
and
301 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
63 changes: 63 additions & 0 deletions
63
src/components/[guild]/Requirements/components/DataProviderRequirement.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,63 @@ | ||
import { Box, Circle, Flex, HStack, Icon, SimpleGrid, Text } from "@chakra-ui/react" | ||
import { Lightning } from "phosphor-react" | ||
import { REQUIREMENT_PROVIDED_VALUES } from "requirements/requirements" | ||
import { RequirementProps } from "./Requirement" | ||
import { useRequirementContext } from "./RequirementContext" | ||
import { RequirementImage, RequirementImageCircle } from "./RequirementImage" | ||
|
||
const DataProviderRequirement = ({ | ||
image, | ||
isImageLoading, | ||
children, | ||
rightElement, | ||
}: RequirementProps): JSX.Element => { | ||
const requirement = useRequirementContext() | ||
|
||
const ProvidedValueDisplay = REQUIREMENT_PROVIDED_VALUES[requirement?.type] | ||
|
||
return ( | ||
<SimpleGrid | ||
spacing={4} | ||
w="full" | ||
py={2} | ||
templateColumns={`auto 1fr ${rightElement ? "auto" : ""}`} | ||
alignItems="center" | ||
> | ||
<Box mt="3px" alignSelf={"start"} position={"relative"}> | ||
<RequirementImageCircle isImageLoading={isImageLoading}> | ||
<RequirementImage image={requirement?.data?.customImage || image} /> | ||
</RequirementImageCircle> | ||
|
||
<Circle | ||
position="absolute" | ||
right={-1} | ||
bottom={0} | ||
bgColor={"white"} | ||
size={5} | ||
overflow="hidden" | ||
> | ||
<Icon boxSize={3} as={Lightning} weight="fill" color="green.500" /> | ||
</Circle> | ||
</Box> | ||
|
||
<Flex alignSelf={"center"} flexDir={"column"} justifyContent={"center"} ml={1}> | ||
{ProvidedValueDisplay && <ProvidedValueDisplay requirement={requirement} />} | ||
|
||
<HStack gap={1} alignItems={"center"}> | ||
<Text fontSize={"sm"} color={"GrayText"}> | ||
Via:{" "} | ||
</Text> | ||
<Text | ||
fontWeight={"medium"} | ||
sx={{ fontSize: "sm", "& *": { fontSize: "inherit" } }} | ||
> | ||
{requirement?.data?.customName || children} | ||
</Text> | ||
</HStack> | ||
</Flex> | ||
{rightElement} | ||
</SimpleGrid> | ||
) | ||
} | ||
|
||
export default DataProviderRequirement |
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
67 changes: 67 additions & 0 deletions
67
src/components/[guild]/RoleCard/components/DynamicReward/DynamicTag.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,67 @@ | ||
import { Icon, Tag, Tooltip, useDisclosure } from "@chakra-ui/react" | ||
import useGuildPermission from "components/[guild]/hooks/useGuildPermission" | ||
import useRequirements from "components/[guild]/hooks/useRequirements" | ||
import { Lightning, Warning } from "phosphor-react" | ||
import DynamicRewardModal from "platforms/Token/DynamicRewardModal" | ||
import { Rest, RolePlatform } from "types" | ||
|
||
const DynamicTag = ({ | ||
rolePlatform, | ||
...rest | ||
}: { rolePlatform: RolePlatform } & Rest) => { | ||
const { isAdmin } = useGuildPermission() | ||
|
||
const { onOpen, isOpen, onClose } = useDisclosure() | ||
|
||
const { data: requirements } = useRequirements(rolePlatform.roleId) | ||
|
||
const dynamicAmount: any = rolePlatform.dynamicAmount | ||
const requirementId = | ||
dynamicAmount?.operation?.input?.[0]?.requirementId || | ||
dynamicAmount?.operation?.input?.requirementId | ||
|
||
const linkedRequirement = requirements?.find((req) => req.id === requirementId) | ||
|
||
return ( | ||
<> | ||
<Tooltip label="Show details" hasArrow> | ||
<Tag | ||
fontWeight="semibold" | ||
_hover={{ cursor: "pointer" }} | ||
onClick={onOpen} | ||
w="fit-content" | ||
{...rest} | ||
> | ||
<Icon | ||
boxSize={"13px"} | ||
weight="fill" | ||
color="green.500" | ||
as={Lightning} | ||
mr={1} | ||
/> | ||
Dynamic | ||
</Tag> | ||
</Tooltip> | ||
|
||
{isAdmin && !linkedRequirement && ( | ||
<Tooltip | ||
hasArrow | ||
label="Dynamic rewards need a base value for reward amount calculation from a requirement. Edit the reward to set one!" | ||
> | ||
<Tag colorScheme={"orange"} w="fit-content"> | ||
<Icon as={Warning} mr={1} /> Missing linked requirement! | ||
</Tag> | ||
</Tooltip> | ||
)} | ||
|
||
<DynamicRewardModal | ||
onClose={onClose} | ||
isOpen={isOpen} | ||
rolePlatform={rolePlatform} | ||
linkedRequirement={linkedRequirement} | ||
></DynamicRewardModal> | ||
</> | ||
) | ||
} | ||
|
||
export default DynamicTag |
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
Oops, something went wrong.