-
Notifications
You must be signed in to change notification settings - Fork 168
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
Marchand-Nicolas
merged 4 commits into
lfglabs-dev:testnet
from
sandragcarrillo:fix-1008
Jan 27, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2bf5111
bannerStep component created
sandragcarrillo 0a0ffb8
Fix: Add Banner step before preview in admin form flow
sandragcarrillo 2121b86
Merge branch 'testnet' into fix-1008
sandragcarrillo 4368dab
adding banner to handleQuestInputChange
sandragcarrillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ import Typography from "@components/UI/typography/typography"; | |
import QuestDetailsForm from "@components/admin/formSteps/QuestDetailsForm"; | ||
import RewardDetailsForm from "@components/admin/formSteps/RewardDetailsForm"; | ||
import TaskDetailsForm from "@components/admin/formSteps/TaskDetailsForm"; | ||
import BannerDetailsForm from "@components/admin/formSteps/BannerDetailsForm"; | ||
import { TEXT_TYPE } from "@constants/typography"; | ||
import FormContainer from "@components/admin/FormContainer"; | ||
|
||
|
@@ -355,6 +356,7 @@ export default function Page({ params }: QuestIdProps) { | |
[] | ||
); | ||
|
||
|
||
const handleTasksInputChange = useCallback( | ||
(e: React.ChangeEvent<HTMLInputElement>, index: number) => { | ||
const { name, value } = e.target; | ||
|
@@ -369,6 +371,7 @@ export default function Page({ params }: QuestIdProps) { | |
[] | ||
); | ||
|
||
|
||
useEffect(() => { | ||
//check if start time is less than current time | ||
if (new Date(parseInt(startTime)).getTime() < new Date().getTime()) { | ||
|
@@ -701,19 +704,23 @@ export default function Page({ params }: QuestIdProps) { | |
!questInput.category; | ||
|
||
const questRewardValid = !questInput.rewards_title || !questInput.logo; | ||
|
||
const bannerValid = !questInput.banner?.tag || !questInput.banner?.title || !questInput.banner?.description || !questInput.banner?.cta || !questInput.banner?.href || !questInput.banner?.image; | ||
|
||
if (currentPage === 0) { | ||
return questInputValid; | ||
} else if (currentPage === 1) { | ||
return (showBoost && boostInputValid) || nftUriValid || questRewardValid; | ||
} | ||
if (currentPage === 2) { | ||
} else if (currentPage === 2) { | ||
return steps.some((step) => step.type === "None"); | ||
} else if (currentPage === 3) { | ||
return bannerValid; | ||
} | ||
return false; | ||
}, [ | ||
currentPage, | ||
questInput, | ||
questInput.banner, | ||
nfturi, | ||
steps, | ||
showBoost, | ||
|
@@ -807,7 +814,22 @@ export default function Page({ params }: QuestIdProps) { | |
}} | ||
/> | ||
); | ||
} else if (currentPage === 3) { | ||
} 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); | ||
}} | ||
/> | ||
); | ||
} | ||
Comment on lines
+875
to
+889
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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}
|
||
else if (currentPage === 4) { | ||
if (questData.id === 0) { | ||
return ( | ||
<div> | ||
|
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,73 @@ | ||
import React, { FunctionComponent } from "react"; | ||
import TextInput from "../textInput"; | ||
import { UpdateQuest } from "../../../types/backTypes"; | ||
import Button from "@components/UI/button"; | ||
|
||
type BannerDetailsFormProps = { | ||
questInput: UpdateQuest; | ||
setQuestInput: React.Dispatch<React.SetStateAction<UpdateQuest>>; | ||
handleQuestInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||
onSubmit: () => void; | ||
submitButtonDisabled: boolean; | ||
}; | ||
|
||
const BannerDetailsForm: FunctionComponent<BannerDetailsFormProps> = ({ | ||
questInput, | ||
handleQuestInputChange, | ||
onSubmit, | ||
submitButtonDisabled, | ||
}) => { | ||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<TextInput | ||
name="tag" | ||
value={questInput.banner?.tag || ""} | ||
onChange={handleQuestInputChange} | ||
label="Tag" | ||
placeholder="Enter banner tag" | ||
/> | ||
<TextInput | ||
name="title" | ||
value={questInput.banner?.title || ""} | ||
onChange={handleQuestInputChange} | ||
label="Title" | ||
placeholder="Enter banner title" | ||
/> | ||
<TextInput | ||
name="description" | ||
value={questInput.banner?.description || ""} | ||
onChange={handleQuestInputChange} | ||
label="Description" | ||
placeholder="Enter banner description" | ||
/> | ||
<TextInput | ||
name="cta" | ||
value={questInput.banner?.cta || ""} | ||
onChange={handleQuestInputChange} | ||
label="CTA" | ||
placeholder="Enter Call-to-Action" | ||
/> | ||
<TextInput | ||
name="href" | ||
value={questInput.banner?.href || ""} | ||
onChange={handleQuestInputChange} | ||
label="Link" | ||
placeholder="Enter Link" | ||
/> | ||
<TextInput | ||
name="image" | ||
value={questInput.banner?.image || ""} | ||
onChange={handleQuestInputChange} | ||
label="Image URL" | ||
placeholder="Enter Image URL" | ||
/> | ||
<div className="w-full sm:w-fit"> | ||
<Button onClick={onSubmit} disabled={submitButtonDisabled}> | ||
<p>Save Changes</p> | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BannerDetailsForm; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 theBannerDetailsForm
component and use it to disable the submit button during updates.