Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(onboarding): mobile web welcome flow with email signup (#2624)

Evan Hutnik48cfc816d1a6
diff --git a/js/app/packages/app/component/interactive-onboarding/InteractiveOnboarding.tsx b/js/app/packages/app/component/interactive-onboarding/InteractiveOnboarding.tsx
index f96f1337ca..89d4e0ad0b 100644
--- a/js/app/packages/app/component/interactive-onboarding/InteractiveOnboarding.tsx
+++ b/js/app/packages/app/component/interactive-onboarding/InteractiveOnboarding.tsx
@@ -29,8 +29,68 @@ import { useIsAuthenticated } from '@core/auth';
import { fetchToken } from '@core/util/fetchWithToken';
import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
+import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
+import MobileWebWelcome from './MobileWebWelcome';
+import MobileWebSignupSent from './MobileWebSignupSent';
+import { useSendMobileWelcomeEmail } from '@queries/auth';
+import { isOk } from '@core/util/maybeResult';
+import { toast } from '@core/component/Toast/Toast';
export default function InteractiveOnboarding() {
+ const isAuthenticated = useIsAuthenticated();
+ const [mobileWebStep, setMobileWebStep] = createSignal<
+ 'welcome' | 'signup-sent'
+ >('welcome');
+ const sendMobileWelcomeEmail = useSendMobileWelcomeEmail();
+
+ // Mobile web users who aren't authenticated get a dedicated welcome screen
+ // with email signup instead of the full lesson flow.
+ const isMobileWeb = isTouchDevice() && !isNativeMobilePlatform();
+
+ const handleMobileSignUp = async (email: string) => {
+ if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
+ toast.failure('Invalid email address.');
+ return;
+ }
+
+ const result = await sendMobileWelcomeEmail.mutateAsync(email);
+
+ if (isOk(result)) {
+ if (result[1].sent) {
+ setMobileWebStep('signup-sent');
+ } else {
+ toast.alert('Email already sent.');
+ }
+ } else {
+ const code = result[0]?.[0]?.code;
+ if (code === 'RATE_LIMITED') {
+ toast.failure('Rate limit exceeded.');
+ } else if (code === 'INVALID_EMAIL') {
+ toast.failure('Invalid email address.');
+ } else {
+ toast.failure('Internal error. Please try again.');
+ }
+ }
+ };
+
+ return (
+ <Show
+ when={!isMobileWeb || isAuthenticated() === true}
+ fallback={
+ <Show
+ when={mobileWebStep() === 'welcome'}
+ fallback={<MobileWebSignupSent />}
+ >
+ <MobileWebWelcome onSignUp={handleMobileSignUp} />
+ </Show>
+ }
+ >
+ <InteractiveOnboardingInner />
+ </Show>
+ );
+}
+
+function InteractiveOnboardingInner() {
const analytics = useAnalytics();
const splitPanel = useSplitPanel();
@@ -337,7 +397,12 @@ export default function InteractiveOnboarding() {
onMount(() => {
if (state.currentIndex() > 0) return;
- analytics.track('onboarding_start');
+ analytics.track('onboarding_start', {
+ source:
+ params.get('mobile_welcome_email') === 'true'
+ ? 'mobile_welcome_email'
+ : undefined,
+ });
});
createEffect(
diff --git a/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx b/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx
new file mode 100644
index 0000000000..6912e754cb
--- /dev/null
+++ b/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx
@@ -0,0 +1,52 @@
+import { onMount } from 'solid-js';
+import LogoIcon from '@macro-icons/macro-logo.svg';
+import { PcNoiseGrid } from '@core/component/PcNoiseGrid';
+import { useAnalytics } from '@app/component/analytics-context';
+import { getWebOrigin } from '@core/util/webOrigin';
+
+export default function MobileWebSignupSent() {
+ const analytics = useAnalytics();
+
+ onMount(() => {
+ analytics.track('mobile_web_signup_sent_viewed');
+ });
+
+ return (
+ <div class="flex flex-col h-full w-full p-6 overflow-hidden relative">
+ <div class="inset-0 absolute text-edge bg-panel opacity-10 -z-1">
+ <PcNoiseGrid
+ cellSize={30}
+ warp={0}
+ crunch={0.2}
+ freq={0.001}
+ size={[0, 0.3]}
+ rounding={0}
+ fill={0}
+ stroke={1}
+ speed={[0.017, 0.209]}
+ />
+ </div>
+
+ <div class="flex flex-col items-start gap-4 w-full max-w-md mx-auto mt-6">
+ <LogoIcon class="size-16 text-accent self-center" />
+ <h2 class="text-3xl font-semibold text-ink mt-3">
+ Macro is better on desktop.
+ </h2>
+ <p class="text-base text-ink/60 mt-4">
+ We sent a link to your inbox - open it on your computer for the full
+ Macro experience.
+ </p>
+
+ <button
+ type="button"
+ onClick={() => {
+ window.location.href = getWebOrigin();
+ }}
+ class="w-full px-3 py-2.5 text-lg font-bold rounded-xs bg-accent text-panel border-none mt-16"
+ >
+ Back to Home
+ </button>
+ </div>
+ </div>
+ );
+}
diff --git a/js/app/packages/app/component/interactive-onboarding/MobileWebWelcome.tsx b/js/app/packages/app/component/interactive-onboarding/MobileWebWelcome.tsx
new file mode 100644
index 0000000000..460beee214
--- /dev/null
+++ b/js/app/packages/app/component/interactive-onboarding/MobileWebWelcome.tsx
@@ -0,0 +1,86 @@
+import { createSignal, onMount } from 'solid-js';
+import { A } from '@solidjs/router';
+import LogoIcon from '@macro-icons/macro-logo.svg';
+import { PcNoiseGrid } from '@core/component/PcNoiseGrid';
+import { useAnalytics } from '@app/component/analytics-context';
+
+interface MobileWebWelcomeProps {
+ onSignUp: (email: string) => void;
+}
+
+export default function MobileWebWelcome(props: MobileWebWelcomeProps) {
+ const analytics = useAnalytics();
+ const [email, setEmail] = createSignal('');
+
+ onMount(() => {
+ analytics.track('mobile_web_welcome_viewed');
+ analytics.track('onboarding_step_welcome', {
+ id: 'welcome',
+ index: 0,
+ state: 'viewed',
+ });
+ });
+
+ const handleSignUp = () => {
+ props.onSignUp(email());
+ };
+
+ return (
+ <div class="flex flex-col h-full w-full p-6 overflow-hidden relative">
+ <div class="inset-0 absolute text-edge bg-panel opacity-10 -z-1">
+ <PcNoiseGrid
+ cellSize={30}
+ warp={0}
+ crunch={0.2}
+ freq={0.001}
+ size={[0, 0.3]}
+ rounding={0}
+ fill={0}
+ stroke={1}
+ speed={[0.017, 0.209]}
+ />
+ </div>
+
+ <div class="flex flex-col items-start gap-4 w-full max-w-md mx-auto mt-6">
+ <LogoIcon class="size-16 text-accent self-center" />
+ <h2 class="text-3xl font-semibold text-ink mt-3">Welcome to Macro.</h2>
+ <p class="text-base text-ink/60 mt-4">
+ Macro is a unified system for work – built for <strong>speed</strong>{' '}
+ and <strong>focus</strong>.
+ </p>
+
+ <form
+ class="w-full flex flex-col gap-5 mt-10"
+ onSubmit={(e) => {
+ e.preventDefault();
+ handleSignUp();
+ }}
+ >
+ <input
+ type="email"
+ aria-label="Email address"
+ placeholder="[email protected]"
+ value={email()}
+ onInput={(e) => setEmail(e.currentTarget.value)}
+ class="w-full px-3 py-2.5 text-base border border-edge-muted rounded-xs bg-panel text-ink placeholder:text-ink/30 outline-none focus:border-accent/50"
+ />
+ <button
+ type="submit"
+ class="w-full px-3 py-2.5 text-lg font-bold rounded-xs bg-accent text-panel border-none"
+ >
+ Sign Up
+ </button>
+ </form>
+
+ <p class="text-sm text-ink/50 mt-20">Already have an account?</p>
+ <A
+ href="/login"
+ onClick={() => analytics.track('login_from_onboarding')}
+ class="w-full px-3 py-2.5 text-lg rounded-xs flex items-center justify-between gap-2 border-none bg-transparent text-ink/50 hover:bg-hover/60 ring-1 ring-edge-muted/50"
+ >
+ Login
+ </A>
+ </div>
+ </div>
+ );
+}
diff --git a/js/app/packages/app/lib/analytics/app-events.ts b/js/app/packages/app/lib/analytics/app-events.ts
index 6631fedd8e..6f970ef821 100644
--- a/js/app/packages/app/lib/analytics/app-events.ts
+++ b/js/app/packages/app/lib/analytics/app-events.ts
@@ -6,6 +6,8 @@ export type AppEvents = {
onboarding_step: Record<string, unknown>; // payload -
onboarding_completed: Record<string, unknown>;
login_from_onboarding: Record<string, unknown>;
+ mobile_web_welcome_viewed: Record<string, unknown>;
+ mobile_web_signup_sent_viewed: Record<string, unknown>;
subscription_start: Record<string, unknown>;
subscription_cancel: Record<string, unknown>;
diff --git a/js/app/packages/queries/auth/index.ts b/js/app/packages/queries/auth/index.ts
index 4717791000..4638be33dc 100644
--- a/js/app/packages/queries/auth/index.ts
+++ b/js/app/packages/queries/auth/index.ts
@@ -24,6 +24,7 @@ export {
useCompleteOnboardingMutation,
useSetGroupMutation,
} from './mutations';
+export { useSendMobileWelcomeEmail } from './mobile-welcome-email';
export {
useUserQuotaQuery,
invalidateUserQuota,
diff --git a/js/app/packages/queries/auth/mobile-welcome-email.ts b/js/app/packages/queries/auth/mobile-welcome-email.ts
new file mode 100644
index 0000000000..05122e2585
--- /dev/null
+++ b/js/app/packages/queries/auth/mobile-welcome-email.ts
@@ -0,0 +1,15 @@
+import { authServiceClient } from '@service-auth/client';
+import { useMutation } from '@tanstack/solid-query';
+
+/**
+ * Mutation for sending a mobile welcome email.
+ * Returns the raw `MaybeResult` from the client so callers can distinguish
+ * between "sent" / "already sent" / rate-limited / invalid-email cases.
+ */
+export function useSendMobileWelcomeEmail() {
+ return useMutation(() => ({
+ mutationFn: async (email: string) => {
+ return authServiceClient.sendMobileWelcomeEmail(email);
+ },
+ }));
+}
diff --git a/js/app/packages/service-clients/service-auth/client.ts b/js/app/packages/service-clients/service-auth/client.ts
index af53ff70e4..d98cc68212 100644
--- a/js/app/packages/service-clients/service-auth/client.ts
+++ b/js/app/packages/service-clients/service-auth/client.ts
@@ -17,6 +17,7 @@ import { fetchWithAuth as _fetchWithAuth } from './fetch';
import type {
InitGithubLinkResponse,
PatchUserTutorialRequest,
+ SendMobileWelcomeEmailResponse,
UserQuota,
} from './generated/schemas';
import type { AppleLoginRequest } from './generated/schemas/appleLoginRequest';
@@ -483,6 +484,32 @@ export const authServiceClient = {
(_result) => {}
);
},
+
+ async sendMobileWelcomeEmail(email: string) {
+ return safeFetch<
+ SendMobileWelcomeEmailResponse,
+ 'RATE_LIMITED' | 'INVALID_EMAIL'
+ >(
+ `${authHost}/mobile-welcome-email`,
+ {
+ method: 'POST',
+ body: JSON.stringify({ email }),
+ credentials: 'include',
+ },
+ async (response) => {
+ if (response.status === 429) {
+ return { code: 'RATE_LIMITED', message: 'Rate limit exceeded' };
+ }
+ if (response.status === 400) {
+ return { code: 'INVALID_EMAIL', message: 'Invalid email address' };
+ }
+ return {
+ code: 'HTTP_ERROR',
+ message: `HTTP error! status: ${response.status}`,
+ };
+ }
+ );
+ },
};
registerClient('auth', authServiceClient);
diff --git a/js/app/packages/service-clients/service-auth/generated/client.ts b/js/app/packages/service-clients/service-auth/generated/client.ts
index bcab681d97..5243d716ad 100644
--- a/js/app/packages/service-clients/service-auth/generated/client.ts
+++ b/js/app/packages/service-clients/service-auth/generated/client.ts
@@ -42,6 +42,7 @@ import type {
ResendFusionauthVerifyUserEmailRequest,
SendInviteBody,
SendMobileWelcomeEmailRequest,
+ SendMobileWelcomeEmailResponse,
SsoLoginParams,
SsoRequiredResponse,
StripeSessionResponse,
@@ -1068,15 +1069,10 @@ export const verifyMergeRequest = async (
and the email is not blocked.
*/
export type sendMobileWelcomeEmailResponse200 = {
- data: EmptyResponse;
+ data: SendMobileWelcomeEmailResponse;
status: 200;
};
-export type sendMobileWelcomeEmailResponse204 = {
- data: void;
- status: 204;
-};
-
export type sendMobileWelcomeEmailResponse400 = {
data: ErrorResponse;
status: 400;
@@ -1092,12 +1088,10 @@ export type sendMobileWelcomeEmailResponse500 = {
status: 500;
};
-export type sendMobileWelcomeEmailResponseSuccess = (
- | sendMobileWelcomeEmailResponse200
- | sendMobileWelcomeEmailResponse204
-) & {
- headers: Headers;
-};
+export type sendMobileWelcomeEmailResponseSuccess =
+ sendMobileWelcomeEmailResponse200 & {
+ headers: Headers;
+ };
export type sendMobileWelcomeEmailResponseError = (
| sendMobileWelcomeEmailResponse400
| sendMobileWelcomeEmailResponse429
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/index.ts b/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
index a1a97e49d9..6f5983f157 100644
--- a/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
@@ -57,6 +57,7 @@ export * from './putUserNameQueryParamsLastName';
export * from './resendFusionauthVerifyUserEmailRequest';
export * from './sendInviteBody';
export * from './sendMobileWelcomeEmailRequest';
+export * from './sendMobileWelcomeEmailResponse';
export * from './ssoLoginParams';
export * from './ssoRequiredResponse';
export * from './stripeProductTier';
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/sendMobileWelcomeEmailResponse.ts b/js/app/packages/service-clients/service-auth/generated/schemas/sendMobileWelcomeEmailResponse.ts
new file mode 100644
index 0000000000..7a6a123553
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/sendMobileWelcomeEmailResponse.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+export interface SendMobileWelcomeEmailResponse {
+ /** Whether the email was sent (false if it was already sent previously) */
+ sent: boolean;
+}
diff --git a/js/app/packages/service-clients/service-auth/openapi.json b/js/app/packages/service-clients/service-auth/openapi.json
index b7417ee6e6..05cc575dda 100644
--- a/js/app/packages/service-clients/service-auth/openapi.json
+++ b/js/app/packages/service-clients/service-auth/openapi.json
@@ -916,14 +916,11 @@
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/EmptyResponse"
+ "$ref": "#/components/schemas/SendMobileWelcomeEmailResponse"
}
}
}
},
- "204": {
- "description": ""
- },
"400": {
"description": "",
"content": {
@@ -3608,6 +3605,16 @@
}
}
},
+ "SendMobileWelcomeEmailResponse": {
+ "type": "object",
+ "required": ["sent"],
+ "properties": {
+ "sent": {
+ "type": "boolean",
+ "description": "Whether the email was sent (false if it was already sent previously)"
+ }
+ }
+ },
"SsoRequiredResponse": {
"type": "object",
"required": ["idp_id"],
diff --git a/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/_welcome_email_template.html b/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/_welcome_email_template.html
index 3998bd62b7..d207c23b44 100644
--- a/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/_welcome_email_template.html
+++ b/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/_welcome_email_template.html
@@ -69,7 +69,7 @@
</p>
<div style="text-align: center; margin: 56px 0">
<a
- href="https://macro.com/app/welcome"
+ href="https://macro.com/app/welcome?mobile_welcome_email=true"
style="
display: inline-block;
background-color: #ff8f00;
@@ -89,7 +89,7 @@
<table cellpadding="0" cellspacing="0" role="presentation" style="margin: 56px auto;">
<tr>
<td style="background-color: #ff8f00; border-radius: 3px;">
- <a href="https://macro.com/app/welcome" style="color: #090909; text-decoration: none; display: block; padding: 16px 32px; font-size: 16px; font-weight: 600; font-family: 'Rajdhani', Helvetica, Arial, sans-serif;">
+ <a href="https://macro.com/app/welcome?mobile_welcome_email=true" style="color: #090909; text-decoration: none; display: block; padding: 16px 32px; font-size: 16px; font-weight: 600; font-family: 'Rajdhani', Helvetica, Arial, sans-serif;">
Launch Macro
</a>
</td>
diff --git a/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/mod.rs b/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/mod.rs
index b594c4b11c..4ae1a960c6 100644
--- a/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/mod.rs
+++ b/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/mod.rs
@@ -5,7 +5,7 @@ use axum::{
response::{IntoResponse, Response},
routing::post,
};
-use model::response::{EmptyResponse, ErrorResponse};
+use model::response::ErrorResponse;
use thiserror::Error;
use tower::ServiceBuilder;
use utoipa::ToSchema;
@@ -50,6 +50,12 @@ pub struct SendMobileWelcomeEmailRequest {
pub email: String,
}
+#[derive(Debug, serde::Serialize, ToSchema)]
+pub struct SendMobileWelcomeEmailResponse {
+ /// Whether the email was sent (false if it was already sent previously)
+ pub sent: bool,
+}
+
pub fn router(state: ApiContext) -> Router<ApiContext> {
Router::new().route(
"/mobile-welcome-email",
@@ -69,8 +75,7 @@ pub fn router(state: ApiContext) -> Router<ApiContext> {
path = "/mobile-welcome-email",
operation_id = "send_mobile_welcome_email",
responses(
- (status = 200, body = EmptyResponse),
- (status = 204),
+ (status = 200, body = SendMobileWelcomeEmailResponse),
(status = 400, body = ErrorResponse),
(status = 429, body = ErrorResponse),
(status = 500, body = ErrorResponse),
@@ -80,7 +85,7 @@ pub fn router(state: ApiContext) -> Router<ApiContext> {
pub async fn handler(
State(ctx): State<ApiContext>,
extract::Json(req): extract::Json<SendMobileWelcomeEmailRequest>,
-) -> Result<Response, SendMobileWelcomeEmailError> {
+) -> Result<Json<SendMobileWelcomeEmailResponse>, SendMobileWelcomeEmailError> {
if !email_validator::is_valid_email(&req.email) {
return Err(SendMobileWelcomeEmailError::InvalidEmail);
}
@@ -110,7 +115,7 @@ pub async fn handler(
.await?;
if !inserted {
- return Ok(StatusCode::NO_CONTENT.into_response());
+ return Ok(Json(SendMobileWelcomeEmailResponse { sent: false }));
}
let welcome_email_content = WELCOME_EMAIL_TEMPLATE.to_string();
@@ -123,5 +128,5 @@ pub async fn handler(
)
.await?;
- Ok((StatusCode::OK, Json(EmptyResponse {})).into_response())
+ Ok(Json(SendMobileWelcomeEmailResponse { sent: true }))
}
diff --git a/rust/cloud-storage/authentication_service/src/api/swagger.rs b/rust/cloud-storage/authentication_service/src/api/swagger.rs
index 53a078748c..b53d1b7a8a 100644
--- a/rust/cloud-storage/authentication_service/src/api/swagger.rs
+++ b/rust/cloud-storage/authentication_service/src/api/swagger.rs
@@ -194,6 +194,7 @@ use model::user::{
// Mobile welcome email
mobile_welcome_email::SendMobileWelcomeEmailRequest,
+ mobile_welcome_email::SendMobileWelcomeEmailResponse,
// Merge
CreateAccountMergeRequest,