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

[feat] refactor add plant details #25

Merged
merged 14 commits into from
Nov 12, 2024
Merged

Conversation

SashankBalusu
Copy link
Contributor

@SashankBalusu SashankBalusu commented Oct 26, 2024

What's new in this PR 🧑‍🌾

Description

  • stopped input persistence so that each potential added plant only retains info of its own edits
  • thats weirdly worded but essentially, prior, if input was changed for one plant it would change for all plants--that doesnt happen anymore

Screenshots

How to review

  • Can look at add-details and the associated component PlantDetails

Next steps

Relevant links

Online sources

Related PRs

CC: @ccatherinetan

@SashankBalusu SashankBalusu linked an issue Oct 26, 2024 that may be closed by this pull request
@ccatherinetan ccatherinetan changed the title 22 refactor add plant details [feat] refactor add plant details Oct 28, 2024
app/add-details/page.tsx Outdated Show resolved Hide resolved
app/add-details/page.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@ccatherinetan ccatherinetan left a comment

Choose a reason for hiding this comment

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

looking good so far! please note that planting_type should be of the type PlantingTypeEnum; this may create some typing issues that we'll need to resolve

types/schema.d.ts Outdated Show resolved Hide resolved
app/add-details/page.tsx Outdated Show resolved Hide resolved
app/add-details/page.tsx Show resolved Hide resolved
app/add-details/page.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@ccatherinetan ccatherinetan left a comment

Choose a reason for hiding this comment

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

looking good! a couple more comments

  1. we should await updateUserPlants
  2. let's make details not a state


export default function Home() {
const [currentIndex, setCurrentIndex] = useState<number>(1);
const [details, setDetails] = useState<Partial<UserPlants>[]>([]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we make this a variable and not a state?

return;
}
if (
steps !== 0 &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there ever a case where steps===0? Would you be calling this function if they're not clicking Back/Next?

currentIndex + steps <= plants.length + 1
) {
if (steps > 0) {
setIsDisabled(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

just to confirm, this means if they're moving forward, the Next/Back buttons are disabled, but if they're moving backwards that means they've alr completed the previous page, so they should be able to move from the previous page

app/add-details/page.tsx Outdated Show resolved Hide resolved
Comment on lines 105 to 109
const updatedDetails = [...details];
updatedDetails[currentIndex - 1] = {
...updatedDetails[currentIndex - 1],
[field]: value,
plant_id: plants[currentIndex - 1].id,
};
setDetails(updatedDetails);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this will need to updated since details shouldn't be a state

}

function updateDB() {
updateUserPlants(user_id, details);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be async, so we should modify this to:

async function updateDB() {
    await updateUserPlants(user_id, details);
    router.push('/view-plants');
}

Awaiting ensures that updateUserPlants is completed before rerouting to /view-plants, so that the changes made in the Add Plant Details flow are reflected in /view-plants.

app/add-details/page.tsx Outdated Show resolved Hide resolved
@ccatherinetan ccatherinetan force-pushed the 22-refactor-add-plant-details branch from c85195a to d2900c2 Compare November 8, 2024 22:30
@ccatherinetan ccatherinetan merged commit 32b4023 into main Nov 12, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Add Plant Details
3 participants