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 url validation #2016

Merged
merged 5 commits into from
Oct 9, 2024
Merged

Add url validation #2016

merged 5 commits into from
Oct 9, 2024

Conversation

OKendigelyan
Copy link
Contributor

Proposed changes

Task link

Types of changes

  • Bugfix
  • New feature
  • Refactor
  • Breaking change
  • UI fix

Steps to reproduce

Screenshots

Add the screenshots of how the app used to look like and how it looks now

Web Desktop
https://github.com/user-attachments/assets/a7d6b692-a41f-479a-a60a-2c044b3dac28 https://github.com/user-attachments/assets/a6e469c9-fea9-4f62-b714-a3c3d45d63e6

Checklist

  • Tests that prove my fix is effective or that my feature works have been added
  • Documentation has been added (if appropriate)
  • Screenshots are added (if any UI changes have been made)
  • All TODOs have a corresponding task created (and the link is attached to it)

Copy link

vercel bot commented Oct 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
umami-v2-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 9, 2024 9:09am
umami-v2-web-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 9, 2024 9:09am

@@ -154,6 +154,7 @@
},
"packageManager": "[email protected]",
"dependencies": {
"electron-updater": "6.3.9"
"electron-updater": "6.3.9",
"@hookform/resolvers": "^3.9.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

this should go to the devDependencies

.string()
.min(1, "Tzkt Explorer URL is required")
.url("Enter a valid Tzkt Explorer URL"),
buyTezUrl: z.string().url("Enter a valid Buy Tez URL").or(z.literal("")),
Copy link
Contributor

Choose a reason for hiding this comment

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

also .optional()?

Copy link
Contributor Author

@OKendigelyan OKendigelyan Oct 7, 2024

Choose a reason for hiding this comment

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

it's not necessary since .or(z.literal("")) does the trick

rpcUrl: urlScheme("RPC"),
tzktApiUrl: urlScheme("Tzkt API"),
tzktExplorerUrl: urlScheme("Tzkt Explorer"),
buyTezUrl: urlScheme("Buy Tez").or(z.literal("")),
Copy link
Contributor

Choose a reason for hiding this comment

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

.or(z.literal("").optional())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.optional() isn't required in this case since form defaultValues are always equals empty string, so z.literal("") it's appropriate in this case

Comment on lines +22 to +29
name: network
? z.string().optional()
: z
.string()
.min(1, "Name is required")
.refine(name => !availableNetworks.find(n => n.name === name), {
message: "Network with this name already exists",
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

why not to just have network name in a hidden field? the code will become much simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a hidden field implies the creation of additional input and should also be described in the schema, so I don't see any advantage to it


const result = schema.safeParse(invalidInput);
expect(result.success).toBe(false);
if (!result.success) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious how result.success can be not false here? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

typescript doesn't know about it

@OKendigelyan OKendigelyan enabled auto-merge (squash) October 9, 2024 09:07
@OKendigelyan OKendigelyan merged commit 8a9deb1 into main Oct 9, 2024
7 of 8 checks passed
@OKendigelyan OKendigelyan deleted the add-url-validation branch October 9, 2024 09:19
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