Files
coder/site/util/swr.ts
T
Bryan 9f190418bb fix: Update routes for project page, workspace creation page, and workspace page (#415)
Some API routes were updated in https://github.com/coder/coder/pull/401, which impacted the UX - the flow is currently broken when trying to navigate to a project:

![2022-03-08 15 30 59](https://user-images.githubusercontent.com/88213859/157343533-3d08edf1-70d5-433b-b4a0-fe68875b1928.gif)

This fixes all the routes so that the complete project -> create workspace -> workspace page flow works:

![2022-03-08 16 18 57](https://user-images.githubusercontent.com/88213859/157348186-b9bde553-c602-484e-89bc-208a1d97f703.gif)

Because this had to touch a bunch of UI routes, I also opportunistically fixed #380 as part of this change.

Fixes #380
2022-03-09 13:22:43 -08:00

18 lines
614 B
TypeScript

/**
* unsafeSWRArgument
*
* Helper function for working with SWR / useSWR in the TypeScript world.
* TypeScript is helpful in enforcing type-safety, but SWR is designed to
* with the expectation that, if the argument is not available, an exception
* will be thrown.
*
* This just helps in abiding by those rules, explicitly, and lets us suppress
* the lint warning in a single place.
*/
export const unsafeSWRArgument = <T>(arg: T | null | undefined): T => {
if (typeof arg === "undefined" || arg === null) {
throw "SWR: Expected exception because the argument is not available"
}
return arg
}