-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add resume shop session form to debug dialog
- Loading branch information
1 parent
af5417c
commit e8ab425
Showing
2 changed files
with
73 additions
and
11 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
apps/store/src/components/DebugDialog/DebugResumeSessionSection.tsx
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,53 @@ | ||
import styled from '@emotion/styled' | ||
import { useRouter } from 'next/router' | ||
import { Button, theme } from 'ui' | ||
import { TextField } from '@/components/TextField/TextField' | ||
import { useShopSession } from '@/services/shopSession/ShopSessionContext' | ||
import { useCurrentLocale } from '@/utils/l10n/useCurrentLocale' | ||
import { PageLink } from '@/utils/PageLink' | ||
|
||
const INPUT_NAME = 'shopSessionId' | ||
|
||
export const DebugResumeSessionSection = () => { | ||
const { routingLocale } = useCurrentLocale() | ||
const { shopSession } = useShopSession() | ||
const router = useRouter() | ||
|
||
if (!shopSession) return null | ||
|
||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault() | ||
|
||
const formData = new FormData(event.currentTarget) | ||
const shopSessionId = formData.get(INPUT_NAME) | ||
|
||
if (typeof shopSessionId !== 'string') return | ||
|
||
router.push( | ||
PageLink.session({ | ||
shopSessionId, | ||
locale: routingLocale, | ||
next: `/${routingLocale}${router.pathname}`, | ||
}), | ||
) | ||
} | ||
|
||
return ( | ||
<Layout onSubmit={handleSubmit}> | ||
<div style={{ flex: 1 }}> | ||
<TextField name={INPUT_NAME} label="Resume shop session" variant="small" /> | ||
</div> | ||
|
||
<Button size="medium" type="submit"> | ||
Go | ||
</Button> | ||
</Layout> | ||
) | ||
} | ||
|
||
const Layout = styled.form({ | ||
display: 'grid', | ||
gridTemplateColumns: '4fr 1fr', | ||
alignItems: 'center', | ||
gap: theme.space.xs, | ||
}) |
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