Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: New banner step when editing a quest #1060

Merged
merged 4 commits into from
Jan 27, 2025

Conversation

sandragcarrillo
Copy link
Contributor

@sandragcarrillo sandragcarrillo commented Jan 23, 2025

Resolves: #1008

Changes:

  • Add a new "Banner" step in the admin form flow, located before the preview step.
  • Create a new component for the banner step, allowing users to input the tag, title, description, cta, href, and image fields.
  • Integrate the banner data into the questInput state object.
  • Ensure the banner data is sent in the /admin/quest/update request under the banner field.
  • Validate user input for the banner fields to ensure proper data is submitted.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new "Banner" step in the quest creation/editing process.
    • Introduced the BannerDetailsForm for configuring banner details, including fields for tag, title, description, CTA, link, and image.
  • Improvements

    • Enhanced quest editing workflow with comprehensive quest configuration options.
    • Implemented form validation to ensure all banner details are completed before submission.

This update enhances quest management by enabling detailed banner customization during the quest creation and editing process.

Copy link

vercel bot commented Jan 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
starknet-quest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 27, 2025 10:40pm

Copy link

vercel bot commented Jan 23, 2025

@sandragcarrillo is attempting to deploy a commit to the LFG Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn config production Use --omit=dev instead.
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: @typescript-eslint/[email protected]
npm error Found: [email protected]
npm error node_modules/eslint
npm error dev eslint@"^9.11.1" from the root project
npm error peer eslint@"^6.0.0 || ^7.0.0 || >=8.0.0" from @eslint-community/[email protected]
npm error node_modules/@eslint-community/eslint-utils
npm error @eslint-community/eslint-utils@"^4.2.0" from @typescript-eslint/[email protected]
npm error node_modules/@typescript-eslint/utils
npm error @typescript-eslint/utils@"5.62.0" from @typescript-eslint/[email protected]
npm error node_modules/@typescript-eslint/eslint-plugin
npm error dev @typescript-eslint/eslint-plugin@"^5.47.0" from the root project
npm error 1 more (eslint-config-next)
npm error 1 more (@typescript-eslint/type-utils)
npm error @eslint-community/eslint-utils@"^4.2.0" from [email protected]
npm error 5 more (@typescript-eslint/type-utils, ...)
npm error
npm error Could not resolve dependency:
npm error peer eslint@"^6.0.0 || ^7.0.0 || ^8.0.0" from @typescript-eslint/[email protected]
npm error node_modules/@typescript-eslint/eslint-plugin
npm error dev @typescript-eslint/eslint-plugin@"^5.47.0" from the root project
npm error @typescript-eslint/eslint-plugin@"^5.4.2 || ^6.0.0 || ^7.0.0 || ^8.0.0" from [email protected]
npm error node_modules/eslint-config-next
npm error dev eslint-config-next@"^14.0.1" from the root project
npm error
npm error Conflicting peer dependency: [email protected]
npm error node_modules/eslint
npm error peer eslint@"^6.0.0 || ^7.0.0 || ^8.0.0" from @typescript-eslint/[email protected]
npm error node_modules/@typescript-eslint/eslint-plugin
npm error dev @typescript-eslint/eslint-plugin@"^5.47.0" from the root project
npm error @typescript-eslint/eslint-plugin@"^5.4.2 || ^6.0.0 || ^7.0.0 || ^8.0.0" from [email protected]
npm error node_modules/eslint-config-next
npm error dev eslint-config-next@"^14.0.1" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /.npm/_logs/2025-01-27T22_42_09_807Z-eresolve-report.txt
npm error A complete log of this run can be found in: /.npm/_logs/2025-01-27T22_42_09_807Z-debug-0.log

Walkthrough

The pull request introduces a new "Banner" step in the quest editing workflow for administrators. This addition allows users to define banner details such as tag, title, description, call-to-action, href, and image before the preview step. The changes include creating a new BannerDetailsForm component, updating the form steps constant, modifying the quest update type, and adjusting the page component to incorporate the new banner input functionality.

Changes

File Change Summary
app/admin/quests/dashboard/[questId]/page.tsx Added BannerDetailsForm component, updated form navigation logic, modified isButtonDisabled and renderFormStep functions to include banner step
components/admin/formSteps/BannerDetailsForm.tsx New component created for capturing banner details with input fields for tag, title, description, CTA, href, and image
constants/admin.ts Updated formSteps array to include "Banner" step in the form progression
types/backTypes.d.ts Added optional banner property to UpdateQuest type with required string fields

Assessment against linked issues

Objective Addressed Explanation
Add "Banner" step before preview (1008)
Create component for banner input (1008)
Integrate banner data into questInput (1008)
Validate user input for banner fields (1008)

Possibly related issues

Possibly related PRs

  • Fix: Persist current step in URL for Quest dashboard #1061: This PR modifies the currentPage state management in the Page component, which is directly related to the changes made in the main PR that also involves the Page component and the currentPage state for rendering the BannerDetailsForm.

Suggested reviewers

  • Marchand-Nicolas

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sandragcarrillo sandragcarrillo marked this pull request as draft January 23, 2025 23:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
components/admin/taskSteps/bannerStep.tsx (2)

19-63: Potentially add client-side validation or length constraints.

Since users can input text for multiple banner fields, you might want to include basic validation (character limits, required fields, URL validation for href and image, etc.) to ensure the banner data meets certain standards before being submitted.


67-67: Include unit test coverage for the new component.

Consider adding a suite of tests to verify the banner step’s functionality, ensuring that interactions (input changes, etc.) are properly handled and that default/fallback values are correctly displayed.

Would you like me to generate a sample unit testing file for this component?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf1a679 and 2bf5111.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • components/admin/taskSteps/bannerStep.tsx (1 hunks)

Comment on lines 13 to 17
const BannerStep: FunctionComponent<BannerStepProps> = ({
handleTasksInputChange,
step,
index,
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider defaulting to a fallback when banner is null or undefined.

If step.data.banner can be missing, this code will throw a runtime error when accessing its properties. Safeguard by providing a default object or verifying if the banner object is defined before rendering.

-const BannerStep: FunctionComponent<BannerStepProps> = ({
-  handleTasksInputChange,
-  step,
-  index,
-}) => {
+const BannerStep: FunctionComponent<BannerStepProps> = (props) => {
+  const { handleTasksInputChange, step, index } = props;
+  const banner = step?.data?.banner || {
+    tag: "",
+    title: "",
+    description: "",
+    cta: "",
+    href: "",
+    image: ""
+  };
   return (
     <div className="flex flex-col gap-4 pt-2">
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const BannerStep: FunctionComponent<BannerStepProps> = ({
handleTasksInputChange,
step,
index,
}) => {
const BannerStep: FunctionComponent<BannerStepProps> = (props) => {
const { handleTasksInputChange, step, index } = props;
const banner = step?.data?.banner || {
tag: "",
title: "",
description: "",
cta: "",
href: "",
image: ""
};

Comment on lines 4 to 11
type BannerStepProps = {
handleTasksInputChange: (
e: React.ChangeEvent<HTMLInputElement>,
index: number
) => void;
step: StepMap;
index: number;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Add explicit import for StepMap type and resolve ambiguous type definition

The StepMap type is not imported in bannerStep.tsx, and there are two different definitions in the codebase:

  • types/frontTypes.d.ts: Base type definition
  • app/admin/quests/dashboard/[questId]/page.tsx: Extended type with id field

Add an explicit import from types/frontTypes.d.ts to ensure type consistency and prevent potential type mismatches.

🔗 Analysis chain

Verify the StepMap type import.

It's unclear how StepMap is declared or imported; ensure that this type is properly defined or imported to avoid potential “cannot find name StepMap” errors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for StepMap type definition or import references.

# We'll look for StepMap definition or import statements across the codebase.
rg 'type StepMap\b|interface StepMap\b|import.*StepMap'

Length of output: 155


Script:

#!/bin/bash
# Get the type definitions and imports
echo "=== StepMap definition in types/frontTypes.d.ts ==="
rg -A 10 "type StepMap =" types/frontTypes.d.ts

echo -e "\n=== StepMap definition in app/admin/quests/dashboard/[questId]/page.tsx ==="
rg -A 10 "type StepMap =" "app/admin/quests/dashboard/[questId]/page.tsx"

echo -e "\n=== Imports in bannerStep.tsx ==="
rg "^import" "components/admin/taskSteps/bannerStep.tsx"

Length of output: 1859

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
components/admin/formSteps/BannerDetailsForm.tsx (1)

6-12: Prop Types are well-defined but consider adding validation.
The BannerDetailsFormProps covers most scenarios. However, if more robust runtime validation or stricter typing is required for each banner field, consider libraries such as yup or react-hook-form.

app/admin/quests/dashboard/[questId]/page.tsx (1)

817-830: Integrating BannerDetailsForm is consistent with the new flow.
This block properly saves the banner data and shows a success notification. However, note that additional server-side validation or error handling might be beneficial if requests fail or partial data is submitted.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bf5111 and 813b1fd.

📒 Files selected for processing (4)
  • app/admin/quests/dashboard/[questId]/page.tsx (5 hunks)
  • components/admin/formSteps/BannerDetailsForm.tsx (1 hunks)
  • constants/admin.ts (1 hunks)
  • types/backTypes.d.ts (1 hunks)
🔇 Additional comments (9)
components/admin/formSteps/BannerDetailsForm.tsx (3)

1-4: Imports look good.
All imported modules appear necessary and relevant to this new component.


14-71: No explicit input validation on user-entered data.
While the form is straightforward and uses placeholders, there is no sanitization or dynamic validation for the banner fields. This might lead to incomplete or invalid data if integrated into a production flow without additional checks.

Would you like to see an example snippet showcasing minimal data validation for these fields?


73-73: Exporting the component is properly handled.
No issues found with the default export.

constants/admin.ts (1)

12-12: Including "Banner" step in the form flow is consistent with the new design.
Ensure that any step-index-based logic is updated to reflect the insertion of the new step in the flow.

types/backTypes.d.ts (1)

309-316: Addition of the banner property supports the new form fields.
Defining this property as optional is helpful, but consider whether any fields (e.g., title, image) should be mandatory at the type level if they are strictly required for the banner.

app/admin/quests/dashboard/[questId]/page.tsx (4)

28-28: Importing the new BannerDetailsForm is aligned with the revised form flow.
Please confirm that all relevant components and type imports are consistently updated to handle the new step.


359-359: Ensure robust handling of index in handleTasksInputChange.
This function may fail if the index provided is out of range or invalid. Consider adding safeguards to avoid potential runtime errors.


374-374: Potential parse ambiguity with non-numeric startTime.
Using parseInt(startTime) may yield NaN if users input invalid data. Consider adding numeric validation or fallback logic to handle errors gracefully.


707-708: Correct approach to gating the banner step, but triple-check the step indices.
Lines 707–708 introduce bannerValid initialization. Lines 714 and 716 expand the if/else chain to accommodate the new step. Ensure no off-by-one errors in the step navigation logic across the codebase.

Also applies to: 714-714, 716-716

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
app/admin/quests/dashboard/[questId]/page.tsx (1)

707-708: Consider adding type validation for banner fields.

The banner validation checks for empty fields but doesn't validate the field types. Consider adding type validation to ensure the fields contain the correct data types.

-    const bannerValid = !questInput.banner?.tag || !questInput.banner?.title || !questInput.banner?.description || !questInput.banner?.cta || !questInput.banner?.href || !questInput.banner?.image;
+    const bannerValid = !questInput.banner?.tag?.trim() || 
+      !questInput.banner?.title?.trim() || 
+      !questInput.banner?.description?.trim() || 
+      !questInput.banner?.cta?.trim() || 
+      !questInput.banner?.href?.trim() || 
+      !questInput.banner?.image?.trim() ||
+      !(questInput.banner?.href?.startsWith('http://') || questInput.banner?.href?.startsWith('https://'));

Also applies to: 716-717

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 813b1fd and 0a0ffb8.

📒 Files selected for processing (4)
  • app/admin/quests/dashboard/[questId]/page.tsx (5 hunks)
  • components/admin/formSteps/BannerDetailsForm.tsx (1 hunks)
  • constants/admin.ts (1 hunks)
  • types/backTypes.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • constants/admin.ts
  • types/backTypes.d.ts
  • components/admin/formSteps/BannerDetailsForm.tsx
🔇 Additional comments (2)
app/admin/quests/dashboard/[questId]/page.tsx (2)

28-28: LGTM!

The import statement for the BannerDetailsForm component is correctly added.


723-723: LGTM!

The banner dependency is correctly added to the isButtonDisabled hook dependencies.

Comment on lines +825 to +827
await handleUpdateQuest();
showNotification("Banner updated successfully", "success");
setCurrentPage((prev) => prev + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add loading state to prevent multiple submissions.

The banner update submission handler doesn't prevent multiple submissions while the update is in progress. This could lead to race conditions or duplicate updates.

Add the buttonLoading prop to the BannerDetailsForm component and use it to disable the submit button during updates.

Comment on lines +817 to +831
} else if (currentPage === 3) {
return (
<BannerDetailsForm
setQuestInput={setQuestInput}
questInput={questInput}
handleQuestInputChange={handleQuestInputChange}
submitButtonDisabled={isButtonDisabled}
onSubmit={async () => {
await handleUpdateQuest();
showNotification("Banner updated successfully", "success");
setCurrentPage((prev) => prev + 1);
}}
/>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for banner update.

The banner update logic lacks error handling. If the update fails, the user won't receive proper feedback and the form will still proceed to the next step.

       onSubmit={async () => {
-          await handleUpdateQuest(); 
-          showNotification("Banner updated successfully", "success");
-          setCurrentPage((prev) => prev + 1); 
+          try {
+            setButtonLoading(true);
+            await handleUpdateQuest();
+            showNotification("Banner updated successfully", "success");
+            setCurrentPage((prev) => prev + 1);
+          } catch (error) {
+            showNotification("Failed to update banner. Please try again.", "error");
+            console.error("Error updating banner:", error);
+          } finally {
+            setButtonLoading(false);
+          }
         }}
+        buttonLoading={buttonLoading}

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I cannot write in the input fields (Even though I write on my keyboard, the fields remain empty. On the onChange={handleQuestInputChange}, you need to update the questInput.banner object.
image

@Marchand-Nicolas
Copy link
Collaborator

Also don't forget to resolve conflicts @sandragcarrillo

@Marchand-Nicolas Marchand-Nicolas added the ❌ Change request Change requested from reviewer label Jan 27, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
app/admin/quests/dashboard/[questId]/page.tsx (1)

860-874: ⚠️ Potential issue

Add loading state and error handling to banner update.

The banner update submission handler doesn't prevent multiple submissions while the update is in progress. This could lead to race conditions or duplicate updates.

Apply this diff to add proper loading state and error handling:

      return (
      <BannerDetailsForm
        setQuestInput={setQuestInput}
        questInput={questInput}
        handleQuestInputChange={handleQuestInputChange}
        submitButtonDisabled={isButtonDisabled}
        onSubmit={async () => {
-          await handleUpdateQuest(); 
-          showNotification("Banner updated successfully", "success");
-          setCurrentPage((prev) => prev + 1); 
+          try {
+            setButtonLoading(true);
+            await handleUpdateQuest();
+            showNotification("Banner updated successfully", "success");
+            handleTabChange(currentPage + 1);
+          } catch (error) {
+            showNotification("Failed to update banner. Please try again.", "error");
+            console.error("Error updating banner:", error);
+          } finally {
+            setButtonLoading(false);
+          }
        }}
+       buttonLoading={buttonLoading}
/>
      );
    }

Note: Also replaced setCurrentPage with handleTabChange to maintain consistency with the URL state management.

🧹 Nitpick comments (1)
app/admin/quests/dashboard/[questId]/page.tsx (1)

749-750: Consider using optional chaining for banner validation.

The current validation might throw if questInput.banner is undefined. Consider using optional chaining to handle this case gracefully.

-    const bannerValid = !questInput.banner?.tag || !questInput.banner?.title || !questInput.banner?.description || !questInput.banner?.cta || !questInput.banner?.href || !questInput.banner?.image;
+    const bannerValid = !questInput.banner?.tag || 
+                       !questInput.banner?.title || 
+                       !questInput.banner?.description || 
+                       !questInput.banner?.cta || 
+                       !questInput.banner?.href || 
+                       !questInput.banner?.image;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a0ffb8 and 2121b86.

📒 Files selected for processing (1)
  • app/admin/quests/dashboard/[questId]/page.tsx (5 hunks)
🔇 Additional comments (2)
app/admin/quests/dashboard/[questId]/page.tsx (2)

28-28: LGTM!

The import statement for the BannerDetailsForm component is correctly placed.


756-759: LGTM!

The form step conditions are correctly updated to include the new banner step.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
app/admin/quests/dashboard/[questId]/page.tsx (2)

883-885: ⚠️ Potential issue

Add loading state to prevent multiple submissions.

The banner update submission handler doesn't prevent multiple submissions while the update is in progress. This could lead to race conditions or duplicate updates.


875-889: ⚠️ Potential issue

Add error handling for banner update.

The banner update logic lacks error handling. If the update fails, the user won't receive proper feedback and the form will still proceed to the next step.

🧹 Nitpick comments (2)
app/admin/quests/dashboard/[questId]/page.tsx (2)

360-374: Consider initializing banner state with a dedicated constant.

The banner object initialization is embedded within the change handler. This could lead to inconsistency in the initial state across different parts of the component.

Extract the initial state to a constant:

+const INITIAL_BANNER_STATE = {
+  tag: "",
+  title: "",
+  description: "",
+  cta: "",
+  href: "",
+  image: "",
+};

const handleQuestInputChange = useCallback(
  (e: React.ChangeEvent<HTMLInputElement>) => {
    const { name, value } = e.target;
    setQuestInput((prev) => ({
      ...prev,
      banner: {
-        ...(prev.banner ?? {
-          tag: "",
-          title: "",
-          description: "",
-          cta: "",
-          href: "",
-          image: "",
-        }),
+        ...(prev.banner ?? INITIAL_BANNER_STATE),
        [name]: value,
      },
    }));
  },
  []
);

764-765: Improve banner validation readability.

The banner validation is a long boolean expression that could be hard to maintain.

Consider extracting it to a separate function:

+const isBannerValid = (banner?: UpdateQuest['banner']) => {
+  if (!banner) return false;
+  return !banner.tag || !banner.title || !banner.description || 
+         !banner.cta || !banner.href || !banner.image;
+};

const isButtonDisabled = useMemo(() => {
  // ... other validation logic ...
-  const bannerValid = !questInput.banner?.tag || !questInput.banner?.title || 
-    !questInput.banner?.description || !questInput.banner?.cta || 
-    !questInput.banner?.href || !questInput.banner?.image;
+  const bannerValid = isBannerValid(questInput.banner);
  // ... rest of the function
}, [/* dependencies */]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2121b86 and 4368dab.

📒 Files selected for processing (1)
  • app/admin/quests/dashboard/[questId]/page.tsx (6 hunks)
🔇 Additional comments (1)
app/admin/quests/dashboard/[questId]/page.tsx (1)

771-774: LGTM: Form step conditions are properly ordered.

The conditions for different form steps are logically ordered and include the new banner step.

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did a really good job!! Well done :)
Lgtm!

@Marchand-Nicolas Marchand-Nicolas merged commit bebf69b into lfglabs-dev:testnet Jan 27, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❌ Change request Change requested from reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New banner step when editing a quest
2 participants