Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desktop/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default defineConfig({
"**/integration.spec.ts",
"**/profile.spec.ts",
"**/sidebar.spec.ts",
"**/sidebar-relay-card.spec.ts",
"**/tokens.spec.ts",
"**/persona-env-vars.spec.ts",
"**/mesh-compute.spec.ts",
Expand Down
21 changes: 21 additions & 0 deletions desktop/public/pow/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Emerge Tools, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added desktop/public/pow/plop.m4a
Binary file not shown.
Binary file added desktop/public/pow/poof1@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added desktop/public/pow/poof2@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added desktop/public/pow/poof3@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added desktop/public/pow/poof4@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added desktop/public/pow/poof5@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions desktop/src/app/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ import { chromeCssVarDefaults } from "@/shared/layout/chromeLayout";
import { cn } from "@/shared/lib/cn";
import { hasPrimaryShortcutModifier } from "@/shared/lib/platform";
import { useMessageDeepLinks } from "@/shared/useMessageDeepLinks";
import { ConnectionBanner } from "@/shared/ui/ConnectionBanner";
import { SidebarInset, SidebarProvider } from "@/shared/ui/sidebar";

const LazySettingsScreen = React.lazy(async () => {
Expand Down Expand Up @@ -879,7 +878,6 @@ export function AppShell() {
className="min-h-0 min-w-0 overflow-hidden"
style={chromeCssVarDefaults}
>
<ConnectionBanner />
<Outlet />
</SidebarInset>
</MainInsetProvider>
Expand Down
3 changes: 3 additions & 0 deletions desktop/src/features/onboarding/ui/OnboardingFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
profileQueryKey,
useUpdateProfileMutation,
} from "@/features/profile/hooks";
import { useWorkspaces } from "@/features/workspaces/useWorkspaces";
import { relayClient } from "@/shared/api/relayClient";
import { getMyRelayMembershipLookup } from "@/shared/api/relayMembers";
import { getIdentity, importIdentity } from "@/shared/api/tauri";
Expand Down Expand Up @@ -146,6 +147,7 @@ export function OnboardingFlow({
onBackToWorkspaceSetup,
}: OnboardingFlowProps) {
const { complete, skipForNow } = actions;
const { activeWorkspace } = useWorkspaces();
const queryClient = useQueryClient();
const savedProfile = resolveSavedProfile(initialProfile);
const profileUpdateMutation = useUpdateProfileMutation();
Expand Down Expand Up @@ -486,6 +488,7 @@ export function OnboardingFlow({
updateDisplayName: updateDisplayNameDraft,
}}
direction={transitionDirection}
relayUrl={activeWorkspace?.relayUrl}
state={profileStepState}
/>
) : currentPage === "key-import" ? (
Expand Down
209 changes: 207 additions & 2 deletions desktop/src/features/onboarding/ui/ProfileStep.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import * as React from "react";
import { toast } from "sonner";

import {
SidebarBlockAccessRefreshCompactCard,
SidebarBlockVpnOffCompactCard,
SidebarRelayConnectionCompactCard,
} from "@/features/sidebar/ui/SidebarRelayConnectionCard";
import { useReconnectRelay } from "@/shared/api/useReconnectRelay";
import { cn } from "@/shared/lib/cn";
import { resolveRelayConnectivityCardVariant } from "@/shared/lib/relayConnectivityCard";
import { isRelayUnreachableError } from "@/shared/lib/relayError";
import { Button } from "@/shared/ui/button";
import { Spinner } from "@/shared/ui/spinner";
import {
Expand All @@ -13,15 +22,206 @@ import type { ProfileStepActions, ProfileStepState } from "./types";
type ProfileStepProps = {
actions: ProfileStepActions;
direction: OnboardingTransitionDirection;
relayUrl?: string | null;
transitionEffect?: OnboardingTransitionEffect;
state: ProfileStepState;
};

function ErrorBanner({ message }: { message: string | null }) {
type OnboardingConnectivityAction =
| "connect-vpn"
| "reconnect-relay"
| "refresh-access";
type OnboardingRelayCardVariant =
| "connect-vpn"
| "reconnect-relay"
| "refresh-access";

const ONBOARDING_CONNECTIVITY_SUCCESS_AUTO_DISMISS_MS = 2_500;

function resolveOnboardingRelayCardVariant(
errorMessage: string,
relayUrl: string | null | undefined,
): OnboardingRelayCardVariant {
return resolveRelayConnectivityCardVariant(errorMessage, relayUrl);
}

function OnboardingRelayConnectionErrorCard({
isSaving,
message,
relayUrl,
}: {
isSaving: boolean;
message: string;
relayUrl?: string | null;
}) {
const { isPending: isReconnectPending, reconnect } = useReconnectRelay();
const [dismissedErrorMessage, setDismissedErrorMessage] = React.useState<
string | null
>(null);
const [connectivityAction, setConnectivityAction] =
React.useState<OnboardingConnectivityAction | null>(null);
const [successAction, setSuccessAction] =
React.useState<OnboardingConnectivityAction | null>(null);
const connectivityActionRef =
React.useRef<OnboardingConnectivityAction | null>(null);
const successTimeoutRef = React.useRef<number | null>(null);
const wasSavingRef = React.useRef(isSaving);
const cardVariant = resolveOnboardingRelayCardVariant(message, relayUrl);
const isActionPending = connectivityAction !== null || isReconnectPending;

React.useEffect(() => {
return () => {
if (successTimeoutRef.current !== null) {
window.clearTimeout(successTimeoutRef.current);
}
};
}, []);

React.useEffect(() => {
if (isSaving && !wasSavingRef.current) {
if (successTimeoutRef.current !== null) {
window.clearTimeout(successTimeoutRef.current);
successTimeoutRef.current = null;
}
setDismissedErrorMessage(null);
setSuccessAction(null);
}
wasSavingRef.current = isSaving;
}, [isSaving]);

const markSuccess = React.useCallback(
(action: OnboardingConnectivityAction) => {
setSuccessAction(action);
if (successTimeoutRef.current !== null) {
window.clearTimeout(successTimeoutRef.current);
}
successTimeoutRef.current = window.setTimeout(() => {
successTimeoutRef.current = null;
setDismissedErrorMessage(message);
}, ONBOARDING_CONNECTIVITY_SUCCESS_AUTO_DISMISS_MS);
},
[message],
);

const runConnectivityAction = React.useCallback(
(
action: OnboardingConnectivityAction,
runAction: () => Promise<boolean | undefined>,
) => {
if (connectivityActionRef.current !== null) {
return;
}

connectivityActionRef.current = action;
setConnectivityAction(action);
setSuccessAction(null);
void Promise.resolve()
.then(runAction)
.then((didReconnect) => {
if (didReconnect !== false) {
markSuccess(action);
}
})
.catch((error) => {
const detail = error instanceof Error ? error.message : String(error);
const label =
action === "refresh-access"
? "Could not refresh VPN access."
: action === "connect-vpn"
? "Could not turn on VPN."
: "Could not reconnect to the relay.";
toast.error(`${label} ${detail}`);
})
.finally(() => {
connectivityActionRef.current = null;
setConnectivityAction(null);
});
},
[markSuccess],
);

const handleConnectWarpVpn = React.useCallback(() => {
runConnectivityAction("connect-vpn", reconnect);
}, [reconnect, runConnectivityAction]);

const handleReconnectRelay = React.useCallback(() => {
runConnectivityAction("reconnect-relay", reconnect);
}, [reconnect, runConnectivityAction]);

const handleRefreshWarpAccess = React.useCallback(() => {
runConnectivityAction("refresh-access", reconnect);
}, [reconnect, runConnectivityAction]);

if (dismissedErrorMessage === message) {
return null;
Comment thread
klopez4212 marked this conversation as resolved.
}

return (
<div className="fixed bottom-4 left-4 z-50 w-[calc(100vw-2rem)] text-left sm:bottom-6 sm:left-6 sm:w-[22rem]">
{cardVariant === "refresh-access" ? (
<SidebarBlockAccessRefreshCompactCard
actionTestId="onboarding-refresh-vpn-access"
isActionDisabled={isActionPending}
isActionPending={connectivityAction === "refresh-access"}
isActionSuccess={successAction === "refresh-access"}
onAction={handleRefreshWarpAccess}
onDismiss={() => setDismissedErrorMessage(message)}
surface="secondary"
testId="onboarding-vpn-access-refresh-card"
/>
) : cardVariant === "connect-vpn" ? (
<SidebarBlockVpnOffCompactCard
actionTestId="onboarding-connect-vpn"
isActionDisabled={isActionPending}
isActionPending={connectivityAction === "connect-vpn"}
isActionSuccess={successAction === "connect-vpn"}
onAction={handleConnectWarpVpn}
Comment thread
klopez4212 marked this conversation as resolved.
onDismiss={() => setDismissedErrorMessage(message)}
surface="secondary"
testId="onboarding-vpn-off-card"
/>
) : (
<SidebarRelayConnectionCompactCard
actionTestId="onboarding-reconnect-relay"
isActionDisabled={isActionPending}
isConnected={successAction === "reconnect-relay"}
isReconnectPending={
connectivityAction === "reconnect-relay" || isReconnectPending
}
onDismiss={() => setDismissedErrorMessage(message)}
onReconnect={handleReconnectRelay}
surface="secondary"
testId="onboarding-relay-reconnect-card"
/>
)}
</div>
);
}

function ErrorBanner({
isSaving,
message,
relayUrl,
}: {
isSaving: boolean;
message: string | null;
relayUrl?: string | null;
}) {
if (!message) {
return null;
}

if (isRelayUnreachableError(message)) {
return (
<OnboardingRelayConnectionErrorCard
isSaving={isSaving}
key={message}
message={message}
relayUrl={relayUrl}
/>
);
}

return (
<p className="mt-4 rounded-md border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive">
{message}
Expand All @@ -32,6 +232,7 @@ function ErrorBanner({ message }: { message: string | null }) {
export function ProfileStep({
actions,
direction,
relayUrl,
transitionEffect = "line-slide",
state,
}: ProfileStepProps) {
Expand Down Expand Up @@ -117,7 +318,11 @@ export function ProfileStep({
</label>

{saveRecovery.errorMessage ? (
<ErrorBanner message={saveRecovery.errorMessage} />
<ErrorBanner
isSaving={isSaving}
message={saveRecovery.errorMessage}
relayUrl={relayUrl}
/>
) : null}

<div className="mt-12 flex w-full max-w-[500px] flex-col gap-3">
Expand Down
Loading