-
-
Notifications
You must be signed in to change notification settings - Fork 88
Block scene/performer submits with pending URLs #1123
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,6 +183,7 @@ const PerformerForm: FC<PerformerProps> = ({ | |
| piercings: initial?.piercings ?? performer?.piercings ?? [], | ||
| images: initial?.images ?? performer?.images ?? [], | ||
| urls: initial?.urls ?? performer?.urls ?? [], | ||
| pendingUrl: "", | ||
| }, | ||
| }); | ||
|
|
||
|
|
@@ -300,6 +301,7 @@ const PerformerForm: FC<PerformerProps> = ({ | |
| error: errors.urls?.find?.((u) => u?.url?.message)?.url?.message, | ||
| tab: "links", | ||
| }, | ||
| { error: errors.pendingUrl?.message, tab: "links" }, | ||
| ].filter((e) => e.error) as { error: string; tab: string }[]; | ||
|
|
||
| return ( | ||
|
|
@@ -668,6 +670,12 @@ const PerformerForm: FC<PerformerProps> = ({ | |
| lens={lens.focus("urls").defined()} | ||
| type={ValidSiteTypeEnum.PERFORMER} | ||
| errors={errors.urls} | ||
| pendingURLError={errors.pendingUrl?.message} | ||
| onPendingURLChange={(hasPendingURL) => | ||
| setValue("pendingUrl", hasPendingURL ? "pending" : "", { | ||
|
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. Soring pending vs "" to drive a boolean check seems weird to me and potentially a smell down the line. I would make pendingURL a yup.boolean() or store the pending url. 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. Seems like this is also the same on SceneForm.tsx and schema.ts
Contributor
Author
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. Made it store the pending URL. |
||
| shouldValidate: true, | ||
| }) | ||
| } | ||
| /> | ||
|
|
||
| <NavButtons onNext={() => setActiveTab("images")} /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,7 @@ const SceneForm: FC<SceneProps> = ({ | |
| control, | ||
| handleSubmit, | ||
| watch, | ||
| setValue, | ||
| formState: { errors }, | ||
| } = useForm({ | ||
| resolver: yupResolver(SceneSchema), | ||
|
|
@@ -83,6 +84,7 @@ const SceneForm: FC<SceneProps> = ({ | |
| images: initial?.images ?? scene?.images ?? [], | ||
| studio: initial?.studio ?? scene?.studio ?? undefined, | ||
| tags: initial?.tags ?? scene?.tags ?? [], | ||
| pendingUrl: "", | ||
| performers: (initial?.performers ?? scene?.performers ?? []).map((p) => ({ | ||
| performerId: p.performer.id, | ||
| name: p.performer.name, | ||
|
|
@@ -318,6 +320,7 @@ const SceneForm: FC<SceneProps> = ({ | |
| error: errors.urls?.find?.((u) => u?.url?.message)?.url?.message, | ||
| tab: "links", | ||
| }, | ||
| { error: errors.pendingUrl?.message, tab: "links" }, | ||
| ].filter((e) => e.error) as { error: string; tab: string }[]; | ||
|
|
||
| return ( | ||
|
|
@@ -500,6 +503,12 @@ const SceneForm: FC<SceneProps> = ({ | |
| lens={lens.focus("urls").defined()} | ||
| type={ValidSiteTypeEnum.SCENE} | ||
| errors={errors.urls} | ||
| pendingURLError={errors.pendingUrl?.message} | ||
| onPendingURLChange={(hasPendingURL) => | ||
| setValue("pendingUrl", hasPendingURL ? "pending" : "", { | ||
| shouldValidate: true, | ||
| }) | ||
| } | ||
|
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. Seems like this is duplicated. My genera rule of thumb is 2+ times to break it out into a hook or a shared component to reduce LOC
Contributor
Author
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. Done. |
||
| /> | ||
|
|
||
| <NavButtons onNext={() => setActiveTab("images")} /> | ||
|
|
||
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.
If im reading this correctly the onPendingURLChange notification is wired into onChange. It looks like the existing onPaste handler also calls setNewURL directly if it matches a site. I think if a user pastes in a URL, doesnt add, then saves it will get missed.
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.
Refactored this, thanks for the suggestion, the new code is a lot cleaner I think.