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

fix(dashboard): Always trust the URL for the environment selection #7223

Merged
merged 5 commits into from
Dec 6, 2024

Conversation

SokratisVidros
Copy link
Contributor

@SokratisVidros SokratisVidros commented Dec 5, 2024

What changed? Why was the change needed?

  • Pick an environment based on the URL and avoid race conditions using the local storage as we did in the old web app
  • Allow multiple environments to open in separate browser tabs
  • Unify conventions around API-related hooks. That is:
  1. Name all of them similarly using the use-verb-resource pattern.
  2. Unify their return types and add stricter types to hook arguments
Screenshot 2024-12-05 at 23 50 31

What this PR doesn't contain?

-[] Unify the return types to always follow the { resourceName: data, ...restOfReactQuery } return type. This will be done separately in the future.

Copy link

netlify bot commented Dec 5, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit ac08790
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/675314cc4ab4f90008ef6ea5
😎 Deploy Preview https://deploy-preview-7223.dashboard.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 5, 2024

Deploy Preview for dashboard-v2-novu-staging ready!

Name Link
🔨 Latest commit ac08790
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/675314ccc6d1670008eed336
😎 Deploy Preview https://deploy-preview-7223.dashboard-v2.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Dec 5, 2024

Open in Stackblitz

@novu/client

npm i https://pkg.pr.new/novuhq/novu/@novu/client@7223

@novu/framework

npm i https://pkg.pr.new/novuhq/novu/@novu/framework@7223

@novu/node

npm i https://pkg.pr.new/novuhq/novu/@novu/node@7223

@novu/notification-center

npm i https://pkg.pr.new/novuhq/novu/@novu/notification-center@7223

@novu/headless

npm i https://pkg.pr.new/novuhq/novu/@novu/headless@7223

novu

npm i https://pkg.pr.new/novuhq/novu@7223

@novu/providers

npm i https://pkg.pr.new/novuhq/novu/@novu/providers@7223

@novu/shared

npm i https://pkg.pr.new/novuhq/novu/@novu/shared@7223

commit: ac08790

@@ -17,28 +17,28 @@ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
const request = async <T>(
endpoint: string,
options?: {
data?: unknown;
environment?: IEnvironment;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inject the environment to API calls

export async function getBillingSubscription() {
const { data } = await get<{ data: GetSubscriptionDto }>('/billing/subscription');

export async function getSubscription({ environment }: { environment: IEnvironment }) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplify naming

@@ -1,25 +1,26 @@
import { useEffect, useState } from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sort alphabetically to have it nice and tidy

@@ -9,7 +9,7 @@ import { useForm, Controller } from 'react-hook-form';
import { updateClerkOrgMetadata } from '../../api/organization';
import { hubspotCookie } from '../../utils/cookies';
import { identifyUser } from '../../api/telemetry';
import { useTelemetry } from '../../hooks';
import { useTelemetry } from '../../hooks/use-telemetry';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should avoid the index.ts barrel file. It destroys tree shaking, chunking and introduces an extra import and file resolution.

@@ -1,9 +0,0 @@
export * from './use-billing-subscription';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

const { mutateAsync, isPending } = useMutation({
mutationFn: async (data: CreateWorkflowDto) => createWorkflow(data),
mutationFn: async (workflow: CreateWorkflowDto) => createWorkflow({ environment: currentEnvironment!, workflow }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a follow-up PR, currentEnvironment will never be undefined or null to avoid the ! or ?._id discomfort.

placeholderData: keepPreviousData,
enabled: !!currentEnvironment?._id,
refetchOnWindowFocus: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This caters to the use case where customers will have their dev and prod environments side by side, and they will sync workflows between environments. They should be able to see the update without a full page reload.

- Pick an environment based on the URL and avoid race conditions using the local storage as we did in the old web app
- Allow multiple environments open in separate browser tabs
This caters to the use case where customers will have their dev and prod environments side by side, and they will sync workflows between environments. They should be able to see the update without a full page reload.
Copy link
Contributor

@LetItRock LetItRock left a comment

Choose a reason for hiding this comment

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

lgtm 🙌

@SokratisVidros SokratisVidros merged commit ba519c2 into next Dec 6, 2024
43 of 44 checks passed
@SokratisVidros SokratisVidros deleted the env_switching branch December 6, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants