Skip to content

Commit

Permalink
chore: extract CardSettingsComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Jul 29, 2024
1 parent a9c445d commit e5862a0
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import useGuild from "components/[guild]/hooks/useGuild"
import Button from "components/common/Button"
import { useFormContext, useWatch } from "react-hook-form"
import { CAPACITY_TIME_PLATFORMS } from "rewards"
import { cardSettings } from "rewards/CardSettings"
import NftAvailabilityTags from "rewards/ContractCall/components/NftAvailabilityTags"
import { cardPropsHooks } from "rewards/cardPropsHooks"
import rewardComponents from "rewards/components"
import {
GuildPlatformWithOptionalId,
PlatformName,
Expand Down Expand Up @@ -59,9 +59,8 @@ const NewRolePlatformCard = ({ rolePlatform, remove }: Props) => {
guildPlatform.platformGuildData.function ===
ContractCallFunction.DEPRECATED_SIMPLE_CLAIM

const { cardSettingsComponent } =
rewardComponents[type as keyof typeof rewardComponents]
const useCardProps = cardPropsHooks[type as keyof typeof cardPropsHooks]
const cardSettingsComponent = cardSettings[type]
const useCardProps = cardPropsHooks[type]

return (
<RolePlatformProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import useVisibilityModalProps from "components/[guild]/SetVisibility/hooks/useV
import useGuild from "components/[guild]/hooks/useGuild"
import Button from "components/common/Button"
import rewards, { CAPACITY_TIME_PLATFORMS } from "rewards"
import { cardSettings } from "rewards/CardSettings"
import NftAvailabilityTags from "rewards/ContractCall/components/NftAvailabilityTags"
import { cardPropsHooks } from "rewards/cardPropsHooks"
import rewardComponents from "rewards/components"
import {
GuildPlatformWithOptionalId,
PlatformName,
Expand Down Expand Up @@ -69,7 +69,7 @@ const ExistingRolePlatformCard = ({ rolePlatform }: Props) => {
guildPlatform.platformGuildData.function ===
ContractCallFunction.DEPRECATED_SIMPLE_CLAIM

const { cardSettingsComponent } = rewardComponents[type]
const cardSettingsComponent = cardSettings[type]
const useCardProps = cardPropsHooks[type]
const { isPlatform } = rewards[type]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { DISPLAY_CARD_INTERACTIVITY_STYLES } from "components/common/DisplayCard
import { useState } from "react"
import { useFormContext, useWatch } from "react-hook-form"
import rewards, { PlatformAsRewardRestrictions } from "rewards"
import { cardSettings } from "rewards/CardSettings"
import { cardPropsHooks } from "rewards/cardPropsHooks"
import rewardComponents from "rewards/components"
import { PlatformType, Requirement, RoleFormType, RolePlatform } from "types"
import EditRolePlatformModal from "../../EditRolePlatformModal"
import PlatformCard from "../../PlatformCard"
Expand Down Expand Up @@ -68,9 +68,7 @@ const SelectExistingPlatform = ({ onClose, onSelect }: Props) => {

const handleClick = (rolePlatformData?: Partial<RolePlatform>) => {
const platformId = rolePlatformData?.guildPlatform?.platformId
const { cardSettingsComponent = null } = platformId
? rewardComponents[PlatformType[platformId]]
: {}
const cardSettingsComponent = cardSettings[PlatformType[platformId]] ?? null

if (cardSettingsComponent) {
setSelectedRolePlatform(rolePlatformData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Modal } from "components/common/Modal"
import { createContext, useContext, useRef, useState } from "react"
import { FormProvider, useForm } from "react-hook-form"
import rewards from "rewards"
import rewardComponents from "rewards/components"
import { cardSettings } from "rewards/CardSettings"
import { PlatformType, RoleFormType, RolePlatform } from "types"
import { RolePlatformProvider } from "./RolePlatformProvider"

Expand Down Expand Up @@ -43,8 +43,8 @@ const EditRolePlatformModal = ({
rolePlatform.guildPlatform?.platformGuildName ??
rewards[PlatformType[rolePlatform.guildPlatform.platformId]].name

const { cardSettingsComponent: SettingsComponent } =
rewardComponents[PlatformType[rolePlatform?.guildPlatform?.platformId]]
const SettingsComponent =
cardSettings[PlatformType[rolePlatform?.guildPlatform?.platformId]]

return (
<Modal
Expand Down
1 change: 0 additions & 1 deletion src/rewards/CardSettings.ts

This file was deleted.

14 changes: 14 additions & 0 deletions src/rewards/CardSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import dynamic from "next/dynamic"
import DiscordCardSettings from "./Discord/DiscordCardSettings/DiscordCardSettings"
import GoogleCardSettings from "./Google/GoogleCardSettings"
import { AddRewardPanelLoadingSpinner } from "./components/AddRewardPanelLoadingSpinner"
import { CardSetting, RewardComponentMap } from "./types"

export const cardSettings = {
GOOGLE: GoogleCardSettings,
POINTS: dynamic(() => import("rewards/Points/PointsCardSettings"), {
ssr: false,
loading: () => <AddRewardPanelLoadingSpinner height={20} />,
}) as CardSetting,
DISCORD: DiscordCardSettings,
} as const satisfies RewardComponentMap<CardSetting>
3 changes: 0 additions & 3 deletions src/rewards/Discord/DiscordCardSettings/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/rewards/Discord/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import dynamic from "next/dynamic"
import { AddRewardPanelLoadingSpinner } from "rewards/components/AddRewardPanelLoadingSpinner"
import { RewardComponentsData } from "rewards/types"
import DiscordCardMenu from "./DiscordCardMenu"
import DiscordCardSettings from "./DiscordCardSettings"

export default {
cardSettingsComponent: DiscordCardSettings,
cardMenuComponent: DiscordCardMenu,
AddRewardPanel: dynamic(
() =>
Expand Down
2 changes: 0 additions & 2 deletions src/rewards/Google/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import dynamic from "next/dynamic"
import { AddRewardPanelLoadingSpinner } from "rewards/components/AddRewardPanelLoadingSpinner"
import { RewardComponentsData } from "rewards/types"
import GoogleCardMenu from "./GoogleCardMenu"
import GoogleCardSettings from "./GoogleCardSettings"
import GoogleCardWarning from "./GoogleCardWarning"

export default {
cardSettingsComponent: GoogleCardSettings,
cardMenuComponent: GoogleCardMenu,
cardWarningComponent: GoogleCardWarning,
AddRewardPanel: dynamic(
Expand Down
6 changes: 1 addition & 5 deletions src/rewards/Points/components.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import dynamic from "next/dynamic"
import { AddRewardPanelLoadingSpinner } from "rewards/components/AddRewardPanelLoadingSpinner"
import { CardSettings, RewardComponentsData } from "rewards/types"
import { RewardComponentsData } from "rewards/types"

export default {

Check notice on line 5 in src/rewards/Points/components.tsx

View workflow job for this annotation

GitHub Actions / quality-assurance

lint/style/noDefaultExport

Avoid default exports.
cardSettingsComponent: dynamic(() => import("rewards/Points/PointsCardSettings"), {
ssr: false,
loading: () => <AddRewardPanelLoadingSpinner height={20} />,
}) as CardSettings,
AddRewardPanel: dynamic(
() =>
import(
Expand Down
4 changes: 2 additions & 2 deletions src/rewards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type RewardData = {

export type RewardComponentsData = {
// cardPropsHook?: CardPropsHook
cardSettingsComponent?: CardSettings
// cardSettingsComponent?: CardSettings
cardMenuComponent?: (props: any) => JSX.Element
cardWarningComponent?: (props: any) => JSX.Element
cardButton?: (props: any) => JSX.Element
Expand All @@ -58,7 +58,7 @@ export type RewardComponentsData = {
RoleCardComponent?: ComponentType<RewardProps>
}

export type CardSettings = () => JSX.Element
export type CardSetting = () => JSX.Element
export type RewardPreview = ComponentType<PropsWithChildren>
export type AddRewardPanel = ComponentType<AddRewardPanelProps>
export type RoleCard = ComponentType<RewardProps>
Expand Down

0 comments on commit e5862a0

Please sign in to comment.