Skip to content

Commit

Permalink
feat: AddSolutionsModal (#1334)
Browse files Browse the repository at this point in the history
Co-authored-by: BrickheadJohnny <[email protected]>
Co-authored-by: valid <[email protected]>
  • Loading branch information
3 people authored Jul 8, 2024
1 parent bbadd4b commit 65884b4
Show file tree
Hide file tree
Showing 40 changed files with 937 additions and 181 deletions.
Binary file added public/platforms/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/platforms/nft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/platforms/points.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/platforms/text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/discord-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/form-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/gather-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/github-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/google-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/liquidity-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/liquidity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/nft-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/poap-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/points-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/polygon-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/telegram-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/solutions/text-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 2 additions & 24 deletions src/components/[guild]/AddRewardAndCampaign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
} from "@chakra-ui/react"
import { CaretDown, Plus } from "@phosphor-icons/react"
import CreateCampaignModal from "components/[guild]/CreateCampaignModal"
import LiquidityIncentiveSetupModal from "solutions/LiquidityIncentive/LiquidityIncentiveSetupModal"
import AddRewardButton from "./AddRewardButton"
import AddSolutionsButton from "solutions/components/AddSolutionsButton"
import { useIsTabsStuck } from "./Tabs"
import { useThemeContext } from "./ThemeContext"

Expand All @@ -24,16 +23,10 @@ const AddRewardAndCampaign = () => {
const { isStuck } = useIsTabsStuck()
const { textColor = null, buttonColorScheme = null } = useThemeContext() || {}

const {
isOpen: isSolutionOpen,
onClose: onSolutionClose,
onOpen: onSolutionOpen,
} = useDisclosure()

return (
<>
<ButtonGroup isAttached>
<AddRewardButton />
<AddSolutionsButton />
<Divider orientation="vertical" h="8" />
<Menu placement="bottom-end" autoSelect={false}>
<MenuButton
Expand All @@ -55,17 +48,6 @@ const AddRewardAndCampaign = () => {
zIndex="popover"
overflow="hidden"
>
<MenuItem
onClick={onSolutionOpen}
icon={<Icon as={Plus} mt="1" />}
alignItems="start"
py={4}
>
<Text as="span" fontWeight="semibold" fontSize="sm">
Add solution
</Text>
</MenuItem>
<Divider />
<MenuItem
onClick={onOpen}
icon={<Icon as={Plus} mt="1" />}
Expand All @@ -87,10 +69,6 @@ const AddRewardAndCampaign = () => {
</Menu>
</ButtonGroup>
<CreateCampaignModal isOpen={isOpen} onClose={onClose} />
<LiquidityIncentiveSetupModal
isOpen={isSolutionOpen}
onClose={onSolutionClose}
/>
</>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/[guild]/AddRewardButton/SelectRolePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const SelectRolePanel = ({

const goBack = () => {
if (!rewards[selection].autoRewardSetup) methods.reset(defaultValues)
setStep("REWARD_SETUP")
setStep(selection === "POLYGON_ID" ? "HOME" : "REWARD_SETUP")
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ const AddPointsPanel = ({ onAdd, onCancel }: AddRewardPanelProps) => {
selectedExistingId={selectedExistingId}
showCreateNew
mb="5"
onDone={(idToSet) => {
setValue("data.guildPlatformId", idToSet)
onDone={(selectionId) => {
setValue("data.guildPlatformId", selectionId)
}}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const ExistingPointsTypeSelect = ({
(option) => option.value === selectedExistingId
)?.img

const methods = useForm<{ selectedId?: number }>()
const methods = useForm<{ selectedId?: number | null }>({
defaultValues: {
selectedId: options?.[0]?.value || null,
},
})
const {
formState: { errors },
control,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const DynamicPointsAmountForm = ({ imageUrl, baseFieldPath }) => {
return () => {
setIsSubmitDisabled?.(false)
}
}, [requirementId])
}, [requirementId, setIsSubmitDisabled])

return (
<>
Expand Down
66 changes: 51 additions & 15 deletions src/components/common/SegmentedControl.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
import {
Box,
Flex,
HStack,
FlexProps,
RadioProps,
Text,
UseRadioGroupProps,
chakra,
useBreakpointValue,
useColorModeValue,
useRadio,
useRadioGroup,
} from "@chakra-ui/react"
import { motion } from "framer-motion"
import { useId } from "react"
import { useId, useMemo } from "react"

type SegmentedControlOption = {
label: string
value: unknown
isFullWidth?: boolean
}
type Props<TOption extends SegmentedControlOption> = {
options: TOption[]
size?: "md" | "sm"
isFullWidth?: boolean
styleProps?: FlexProps
onChange?: (nextValue: TOption["value"]) => void
value?: TOption["value"]
defaultValue?: TOption["value"]
} & Omit<UseRadioGroupProps, "onChange" | "value" | "defaultValue">

const SegmentedControl = <TOption extends SegmentedControlOption>({
options,
size = "md",
isFullWidth = true,
styleProps,
...useRadioGroupProps
}: Props<TOption>) => {
const bgColor = useColorModeValue("white", "blackAlpha.300")
const bgColor = useColorModeValue("gray.100", "blackAlpha.300")
const borderWidth = useColorModeValue(1, 0)

const { getRadioProps, getRootProps } = useRadioGroup({
Expand All @@ -39,15 +47,22 @@ const SegmentedControl = <TOption extends SegmentedControlOption>({

const uid = useId()

const height = useMemo(() => {
if (size === "md") return { base: "fit", md: 10 }
return { base: "fit", md: 9 }
}, [size])

return (
<HStack
<Flex
width="full"
borderWidth={borderWidth}
alignItems={"center"}
bgColor={bgColor}
borderRadius="lg"
height={10}
height={height}
padding={1}
spacing={1}
gap={1}
{...styleProps}
{...getRootProps()}
>
{options.map((option) => (
Expand All @@ -57,9 +72,11 @@ const SegmentedControl = <TOption extends SegmentedControlOption>({
{...getRadioProps({ value: option.value })}
label={option.label}
value={option.value as any}
size={size}
isFullWidth={isFullWidth}
/>
))}
</HStack>
</Flex>
)
}

Expand All @@ -68,36 +85,47 @@ const MotionBox = motion(Box)
const SegmentedControlButton = ({
uid,
label,
size = "md",
isFullWidth,
...useRadioProps
}: SegmentedControlOption & RadioProps & { uid: string }) => {
}: SegmentedControlOption & RadioProps & { uid: string; size?: "md" | "sm" }) => {
const { state, getInputProps, getRadioProps, htmlProps } = useRadio(useRadioProps)

const inputProps = getInputProps({})

const activeBgColor = useColorModeValue("blackAlpha.100", "whiteAlpha.200")
const activeBgColor = useColorModeValue("white", "whiteAlpha.200")

const isMobile = useBreakpointValue({ base: true, md: false })

return (
<chakra.label {...htmlProps} cursor="pointer" position="relative" h={8} w="full">
<chakra.label
{...htmlProps}
cursor="pointer"
position="relative"
h="full"
w={isFullWidth ? "full" : "auto"}
>
<input {...inputProps} hidden />

{state.isChecked && (
<MotionBox
position="absolute"
inset={0}
borderRadius="md"
borderRadius="lg"
backgroundColor={activeBgColor}
boxShadow={"0 0.5px 2px 0 rgba(0, 0, 0, 0.2)"}
layoutId={`${uid}-segmented-bg`}
transition={{
duration: 0.2,
}}
// Don't animate on the Y axis
style={{ originY: "0px" }}
style={isMobile ? {} : { originY: "0px" }}
/>
)}
<Flex
alignItems="center"
justifyContent="center"
h={8}
h="full"
borderRadius="md"
w="full"
fontWeight="medium"
Expand All @@ -119,9 +147,17 @@ const SegmentedControlButton = ({
}
}}
textAlign="center"
px={2}
px={3}
pos="relative"
zIndex="1"
>
<Text as="span" noOfLines={1}>
<Text
as="span"
noOfLines={1}
fontSize={size}
fontWeight={!isFullWidth ? "semibold" : undefined}
colorScheme={!state.isChecked ? "gray" : ""}
>
{label}
</Text>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ const PlatformSelectButton = ({
platformName === platform && !platformUserData?.readonly
)

const circleBgColor = useColorModeValue("gray.700", "gray.600")
const circleBgColor = useColorModeValue("gray.100", "gray.600")

const DynamicCtaIcon = useMemo(
() => dynamic(async () => (!isPlatformConnected ? ArrowSquareIn : CaretRight)),
[isPlatformConnected]
Expand Down Expand Up @@ -104,7 +105,12 @@ const PlatformSelectButton = ({
>
<HStack spacing={4}>
{imageUrl ? (
<Circle size="12" pos="relative" overflow="hidden">
<Circle
size="12"
pos="relative"
overflow="hidden"
bgColor={circleBgColor}
>
<Image src={imageUrl} alt="Guild logo" fill sizes="3rem" />
</Circle>
) : (
Expand All @@ -114,7 +120,7 @@ const PlatformSelectButton = ({
pos="relative"
overflow="hidden"
>
<Icon as={icon} boxSize={5} weight="regular" color="white" />
<Icon as={icon} boxSize={5} weight="regular" />
</Circle>
)}
<VStack
Expand All @@ -133,7 +139,7 @@ const PlatformSelectButton = ({
{title}
</Heading>
{description && (
<Text letterSpacing="wide" colorScheme="gray">
<Text colorScheme="gray" lineHeight={1.33}>
{(isLoading && `${loadingText}...`) || description}
</Text>
)}
Expand Down
10 changes: 5 additions & 5 deletions src/rewards/ContractCall/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PlatformAsRewardRestrictions, RewardData } from "rewards/types"
import useContractCallCardProps from "./useContractCallCardProps"
import ContractCallRewardCardButton from "./ContractCallRewardCardButton"
import ContractCallCardMenu from "./ContractCallCardMenu"
import Photo from "static/icons/photo.svg"
import dynamic from "next/dynamic"
import { AddRewardPanelLoadingSpinner } from "rewards/components/AddRewardPanelLoadingSpinner"
import LoadingRewardPreview from "rewards/components/LoadingRewardPreview"
import { PlatformAsRewardRestrictions, RewardData } from "rewards/types"
import Photo from "static/icons/photo.svg"
import ContractCallCardMenu from "./ContractCallCardMenu"
import ContractCallRewardCardButton from "./ContractCallRewardCardButton"
import useContractCallCardProps from "./useContractCallCardProps"

export default {
icon: Photo,
Expand Down
8 changes: 4 additions & 4 deletions src/rewards/SecretText/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import dynamic from "next/dynamic"
import { AddRewardPanelLoadingSpinner } from "rewards/components/AddRewardPanelLoadingSpinner"
import LoadingRewardPreview from "rewards/components/LoadingRewardPreview"
import { PlatformAsRewardRestrictions, RewardData } from "rewards/types"
import Box from "static/icons/box.svg"
import SecretTextCardMenu from "./SecretTextCardMenu"
import TextCardButton from "./TextCardButton"
import useSecretTextCardProps from "./useSecretTextCardProps"
import Box from "static/icons/box.svg"
import dynamic from "next/dynamic"
import { AddRewardPanelLoadingSpinner } from "rewards/components/AddRewardPanelLoadingSpinner"
import LoadingRewardPreview from "rewards/components/LoadingRewardPreview"

export default {
icon: Box,
Expand Down
2 changes: 1 addition & 1 deletion src/rewards/Token/DynamicRewardModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const DynamicRewardModal = ({
onClose: editOnClose,
onOpen: editOnOpen,
} = useDisclosure()
const footerBg = useColorModeValue("blackAlpha.100", "blackAlpha.600")
const footerBg = useColorModeValue("blackAlpha.100", "blackAlpha.300")

return (
<>
Expand Down
8 changes: 5 additions & 3 deletions src/rewards/components/PointsPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CREATE_NEW_OPTION } from "components/[guild]/RolePlatforms/components/AddRoleRewardModal/components/AddPointsPanel/components/ExistingPointsTypeSelect"
import useGuildPlatform from "components/[guild]/hooks/useGuildPlatform"
import { useWatch } from "react-hook-form"
import RewardPreview from "./RewardPreview"
Expand All @@ -14,9 +15,10 @@ const PointsPreview = (): JSX.Element => {
})

const { guildPlatform } = useGuildPlatform(guildPlatformId)
const { name, imageUrl } = guildPlatformId
? guildPlatform.platformGuildData ?? {}
: platformGuildData ?? {}
const { name, imageUrl } =
guildPlatformId && guildPlatformId !== CREATE_NEW_OPTION
? guildPlatform.platformGuildData ?? {}
: platformGuildData ?? {}

return (
<RewardPreview
Expand Down
Loading

0 comments on commit 65884b4

Please sign in to comment.