-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: URL prompt for starting recording from provided URL
- Loading branch information
1 parent
a622a55
commit 2a7bf4e
Showing
9 changed files
with
151 additions
and
69 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { useEffect, useRef } from 'react' | ||
import { css } from '@emotion/react' | ||
import { zodResolver } from '@hookform/resolvers/zod' | ||
import { DiscIcon } from '@radix-ui/react-icons' | ||
import { Button, Flex, Heading, Text, TextField } from '@radix-ui/themes' | ||
import { useForm } from 'react-hook-form' | ||
import { z } from 'zod' | ||
|
||
import { FieldGroup } from '@/components/Form' | ||
|
||
interface EmptyStateProps { | ||
isLoading: boolean | ||
onStart: (url?: string) => void | ||
} | ||
|
||
const RecorderEmptyStateSchema = z.object({ | ||
url: z.string(), | ||
}) | ||
|
||
type RecorderEmptyStateFields = z.infer<typeof RecorderEmptyStateSchema> | ||
|
||
export function EmptyState({ isLoading, onStart }: EmptyStateProps) { | ||
const inputRef = useRef<HTMLInputElement | null>(null) | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors }, | ||
} = useForm<RecorderEmptyStateFields>({ | ||
resolver: zodResolver(RecorderEmptyStateSchema), | ||
defaultValues: { | ||
url: '', | ||
}, | ||
shouldFocusError: false, | ||
}) | ||
|
||
const { ref, ...inputProps } = register('url') | ||
|
||
const onSubmit = ({ url }: RecorderEmptyStateFields) => { | ||
onStart(url) | ||
} | ||
|
||
useEffect(() => { | ||
window.requestAnimationFrame(() => { | ||
inputRef.current?.focus() | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<Flex direction="column" align="center" gap="2"> | ||
<Heading | ||
size="8" | ||
css={css` | ||
font-weight: 400; | ||
`} | ||
> | ||
Record your user flow | ||
</Heading> | ||
<Text color="gray" size="1"> | ||
Once you begin recording, requests will appear in this area | ||
</Text> | ||
<form | ||
onSubmit={handleSubmit(onSubmit)} | ||
css={css` | ||
margin-top: var(--space-6); | ||
`} | ||
> | ||
<FieldGroup | ||
name="url" | ||
label="Target URL" | ||
hint="Provide the URL of the service you want to test" | ||
hintType="text" | ||
errors={errors} | ||
width="460px" | ||
> | ||
<TextField.Root | ||
ref={(e) => { | ||
ref(e) | ||
inputRef.current = e | ||
}} | ||
{...inputProps} | ||
placeholder="e.g. test.k6.io" | ||
css={css` | ||
flex-grow: 1; | ||
border-bottom-right-radius: 0; | ||
border-top-right-radius: 0; | ||
`} | ||
/> | ||
</FieldGroup> | ||
<Button disabled={isLoading} type="submit"> | ||
<DiscIcon /> Start recording | ||
</Button> | ||
</form> | ||
</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
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