Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into v2-header
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Jul 3, 2024
2 parents 29e2cc1 + 21aa403 commit e376372
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ const useCreateRequirements = () => {
roleIds: number[]
) => {
const requirementIdMap: RequirementIdMap = {}
const requirementsToCreate = requirements.filter((req) => req.type !== "FREE")

const promises = roleIds.flatMap((roleId) =>
requirements.map((req) =>
requirementsToCreate.map((req) =>
fetcherWithSign([
`/v2/guilds/${guildId}/roles/${roleId}/requirements`,
{
Expand Down
23 changes: 12 additions & 11 deletions src/rewards/components/SelectRoleOrSetRequirements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import RoleSelector from "components/[guild]/RoleSelector"
import useGuild from "components/[guild]/hooks/useGuild"
import useRoleGroup from "components/[guild]/hooks/useRoleGroup"
import SetRequirements from "components/create-guild/Requirements"
import rewards, { PlatformAsRewardRestrictions } from "rewards"
import { useEffect } from "react"
import { useFormContext, useWatch } from "react-hook-form"
import rewards, { PlatformAsRewardRestrictions } from "rewards"
import { PlatformName } from "types"
import getRandomInt from "utils/getRandomInt"

Expand Down Expand Up @@ -55,17 +56,17 @@ const SelectRoleOrSetRequirements = ({ isRoleSelectorDisabled }: Props) => {
const { unregister, setValue } = useFormContext()
const { selection, activeTab, setActiveTab } = useAddRewardContext()

const handleChange = (value: RoleTypeToAddTo) => {
if (value === RoleTypeToAddTo.NEW_ROLE) {
unregister("roleIds")
setValue("name", data?.roleName || `New ${rewards[selection].name} role`)
setValue("imageUrl", data?.imageUrl || `/guildLogos/${getRandomInt(286)}.svg`)
setValue("roleVisibility", "PUBLIC")
}

setActiveTab(value)
const initNewRole = () => {
unregister("roleIds")
setValue("name", data?.roleName || `New ${rewards[selection].name} role`)
setValue("imageUrl", data?.imageUrl || `/guildLogos/${getRandomInt(286)}.svg`)
setValue("roleVisibility", "PUBLIC")
}

useEffect(() => {
if (activeTab === RoleTypeToAddTo.NEW_ROLE) initNewRole()
}, [activeTab])

const { asRewardRestriction } = rewards[selection]

return (
Expand All @@ -76,7 +77,7 @@ const SelectRoleOrSetRequirements = ({ isRoleSelectorDisabled }: Props) => {
variant="solid"
colorScheme="indigo"
index={isRoleSelectorDisabled ? RoleTypeToAddTo.NEW_ROLE : activeTab}
onChange={handleChange}
onChange={setActiveTab}
>
<TabList mt="6" mb="7">
<Tab
Expand Down

0 comments on commit e376372

Please sign in to comment.