-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into fix/cdn-snippet
- Loading branch information
Showing
21 changed files
with
1,518 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use client"; | ||
|
||
import { useFetch } from "hooks/use-fetch"; | ||
import { useRouter } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
import { routes } from "routes"; | ||
|
||
export const WelcomeRedirect = (): null => { | ||
const { data } = useFetch("/me"); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
if (!data) return; | ||
if (!data.finished_welcome) router.replace(routes.welcomeNewsletter); | ||
}, [data, router]); | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Flex } from "@flows/styled-system/jsx"; | ||
import { Text } from "ui"; | ||
|
||
import { SubscribeForm } from "./subscribe-form"; | ||
|
||
export default function WelcomeSubscribePage(): JSX.Element { | ||
return ( | ||
<Flex flexDirection="column" gap="space24" maxW="400px" width="100%"> | ||
<Flex alignItems="center" flexDirection="column" gap="space4"> | ||
<Text variant="titleL">Subscribe to updates</Text> | ||
<Text color="muted" align="center"> | ||
Flows are improving every month. These are the best ways to stay in the loop. | ||
</Text> | ||
</Flex> | ||
|
||
<SubscribeForm /> | ||
</Flex> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
"use client"; | ||
|
||
import { css } from "@flows/styled-system/css"; | ||
import { Box, Flex } from "@flows/styled-system/jsx"; | ||
import { mutate } from "hooks/use-fetch"; | ||
import { useSend } from "hooks/use-send"; | ||
import { api } from "lib/api"; | ||
import { useRouter } from "next/navigation"; | ||
import { Controller, type SubmitHandler, useForm } from "react-hook-form"; | ||
import { routes } from "routes"; | ||
import { links } from "shared"; | ||
import { Button, Switch, Text } from "ui"; | ||
|
||
type FormValues = { | ||
marketingConsent: boolean; | ||
}; | ||
|
||
export const SubscribeForm = (): JSX.Element => { | ||
const { handleSubmit, control } = useForm<FormValues>({ | ||
defaultValues: { marketingConsent: false }, | ||
}); | ||
const router = useRouter(); | ||
const { send, loading } = useSend(); | ||
const onSubmit: SubmitHandler<FormValues> = async (data) => { | ||
const requests: Promise<{ error?: Error }>[] = [ | ||
send(api["/me"]({ finished_welcome: true }), { errorMessage: null }), | ||
]; | ||
if (data.marketingConsent) | ||
requests.push(send(api["POST /newsletter"](), { errorMessage: "Failed to subscribe" })); | ||
|
||
const responses = await Promise.all(requests); | ||
if (responses.some((res) => !!res.error)) return; | ||
await mutate("/me"); | ||
router.replace(routes.home); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<Flex flexDirection="column" alignItems="center" width="100%"> | ||
<Box borderRadius="radius12" cardWrap="-" mb="space24"> | ||
<Flex flexDirection="column" gap="space16" padding="space24" borBottom="1px"> | ||
<Controller | ||
control={control} | ||
name="marketingConsent" | ||
render={({ field }) => ( | ||
<Switch | ||
checked={field.value} | ||
onChange={field.onChange} | ||
label={ | ||
<> | ||
<Text weight="600" display="block"> | ||
Subscribe to our newsletter | ||
</Text> | ||
<Text as="span" variant="bodyXs" display="block" color="muted"> | ||
Email once a month about new features and changes | ||
</Text> | ||
</> | ||
} | ||
/> | ||
)} | ||
/> | ||
</Flex> | ||
<Flex justifyContent="space-between" alignItems="center" padding="space24"> | ||
<Flex flexDirection="column"> | ||
<Text weight="600">Follow us on Twitter</Text> | ||
<Text variant="bodyXs" color="muted"> | ||
Tweets about features and tips | ||
</Text> | ||
</Flex> | ||
<Button variant="secondary" asChild> | ||
<a href={links.twitter} target="_blank" rel="noopener"> | ||
@flows_sh | ||
</a> | ||
</Button> | ||
</Flex> | ||
</Box> | ||
<Button | ||
className={css({ | ||
maxWidth: "200px", | ||
width: "100%", | ||
})} | ||
loading={loading} | ||
size="default" | ||
type="submit" | ||
> | ||
Continue | ||
</Button> | ||
</Flex> | ||
</form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.