feat: Initial Project Create Form ('/projects/create') by bryphe-coder · Pull Request #60 · coder/coder · GitHub
Skip to content

feat: Initial Project Create Form ('/projects/create') - #60

Merged
bryphe-coder merged 16 commits into
mainfrom
bryphe/feat/project-create-form
Jan 26, 2022
Merged

feat: Initial Project Create Form ('/projects/create')#60
bryphe-coder merged 16 commits into
mainfrom
bryphe/feat/project-create-form

Conversation

@bryphe-coder

@bryphe-coder bryphe-coder commented Jan 25, 2022

Copy link
Copy Markdown
Contributor

This is a super simple form for creating projects:

2022-01-25 12 58 21

TODO:

  • Wire up actual cancel behavior in project form
  • Wire up actual submit behavior in project form
    • POST to /projects/{organization} route
    • Handle invalidating /projects routes
  • Fix 'submit' button (use loading button)
  • Update gif with entire flow
  • Add smoke test for CreateProjectForm

@bryphe-coder bryphe-coder self-assigned this Jan 25, 2022
@codecov

codecov Bot commented Jan 25, 2022

Copy link
Copy Markdown

@bryphe-coder
bryphe-coder marked this pull request as ready for review January 25, 2022 21:01
Comment thread site/forms/CreateProjectForm.tsx Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do this factory pattern instead of using the component directly? I assume it's for the types?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, exactly - sets things up so the compiler knows the formFieldName can only be a few possibilities:

image

And if I introduce a typo - or the schema of the types changes - VSCode lets me know:
image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's also some more backstory here: https://github.com/coder/m/pull/7766 - it's a pattern @vapurrmaid introduced there that we've been leveraging for all our forms.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

formik out of the box is very loose with type safety - there's a lot of any's in their type definitions: https://github.com/jaredpalmer/formik/blob/e677bea8181f40e6762fc7e7fb009122384500c6/packages/formik/src/types.tsx#L6

@bryphe-coder bryphe-coder Jan 25, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I regressed some code early on (one of my first PRs): https://github.com/coder/m/pull/9609- if that component had used this, it would've been caught at compile time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, one thing on our mind is how to accomplish this type-safety w/o a higher-order component - there may be a way to simplify this, esp with newer typescript versions

@bryphe-coder bryphe-coder Jan 25, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually... sorry for this rambling thread... I experimented and it seems we may be able to move away from the higher-order component today w/ our current TS version: #70 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Merged #70 and refactored so that FormDropdownField doesn't need a HoC either in 458703e ... and still get type safety!

@bryphe-coder
bryphe-coder merged commit c7fb16e into main Jan 26, 2022
@bryphe-coder
bryphe-coder deleted the bryphe/feat/project-create-form branch January 26, 2022 00:36
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.

2 participants