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

Add institution scenario #46

Closed
3 tasks done
skorphil opened this issue Feb 21, 2024 · 3 comments · Fixed by #52
Closed
3 tasks done

Add institution scenario #46

skorphil opened this issue Feb 21, 2024 · 3 comments · Fixed by #52
Assignees
Labels
enhancement New feature or request

Comments

@skorphil
Copy link
Owner

skorphil commented Feb 21, 2024

Implement scenario when user creates new institution.

  • tab must to display NEW label
  • user can create new institution
  • new institution opens fullscreen
@skorphil skorphil added the enhancement New feature or request label Feb 24, 2024
@skorphil skorphil self-assigned this Feb 24, 2024
@skorphil
Copy link
Owner Author

skorphil commented Feb 24, 2024

At first it is not working, when I tried to use different instances of useArrayForm() with same name in InstitutionsTabsList and institutionsList

const {
    fields: institutions,
    append: appendInstitution,
  } = useFieldArray({
    name: `institutions`,
  });

The problem was that InstitutionList not seeing freshly created institutions among fields: institutions. This problem described in docs https://react-hook-form.com/docs/usefieldarray#:~:text=should%20not%20have%20multiple%20useFieldArray%20with%20the%20same%20name

to fix this I passed append and fields from InstitutionsList to InstitutionsTabsList avoiding call extra useFieldArray() inside of InstitutionsTabsList

  • But, now i wonder if it is correct to call another useFieldArray() for asset list inside of InstitutionContainer
const arrayName = `${institutionName}.assets`;
  const {
    fields: assets,
    remove,
    append,
  } = useFieldArray({
    name: arrayName,
  });

Maybe I need to pass fields from InstitutionList and filter em like fields.institutions[id].assets
It might also affected #47 when isDirty state did not work as expected

@skorphil
Copy link
Owner Author

Since useFieldArray append is async, i wonder how is it possible to get updated field right after calling append

function handleInstitutionCreate({ append, setSelectedIndex, fields }) {
  append({
    name: "",
    country: "",
    assets: [
      {
        amount: "",
        currency: "",
        isEarning: false,
        description: "",
      },
    ],
  });
  // how to get updated fields list here?
  const selectedIndex = fields.length;
  setSelectedIndex(selectedIndex);
}

@skorphil
Copy link
Owner Author

Temporarily not updating StoryBook, because to implement components, which rely on context, need to write tons of decorator stuff. Do not know how to deal with it.

Demo of scenario:
https://github.com/skorphil/nextjs-form/assets/6762009/6c4b2108-ea64-4352-836a-2637ff0b4413

@skorphil skorphil added this to the Dynamic form milestone Mar 11, 2024
@skorphil skorphil linked a pull request Mar 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant