Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reset sesion button to debug dialog #2798

Merged
merged 1 commit into from
Jul 18, 2023
Merged
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
10 changes: 5 additions & 5 deletions apps/store/src/components/ButtonNextLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Link, { LinkProps } from 'next/link'
import { ComponentProps } from 'react'
import Link, { type LinkProps } from 'next/link'
import { type ComponentProps } from 'react'
import { Button } from 'ui'

type ButtonProps = ComponentProps<typeof Button>
Expand All @@ -12,15 +12,15 @@ export const ButtonNextLink = (props: Props) => {
const { onClick, variant, size, loading, children, className, title, target, ...linkProps } =
props
return (
<Link {...linkProps} passHref legacyBehavior>
<Link {...linkProps} passHref={true} legacyBehavior={true}>
<Button
onClick={onClick}
variant={variant}
size={size}
loading={loading}
{...(target === '_blank' ? { target: '_blank', rel: 'noreferrer' } : {})}
{...(title ? { title: title } : {})}
title={title}
className={className}
{...(target === '_blank' ? { target: '_blank', rel: 'noreferrer' } : {})}
>
{children}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion apps/store/src/components/CartPage/PageDebugDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const PageDebugDialog = () => {
return (
<DebugDialog>
<Space y={1}>
<DebugShopSessionSection />
<LinkToCartSection />
<DebugShopSessionSection />
</Space>
</DebugDialog>
)
Expand Down
4 changes: 2 additions & 2 deletions apps/store/src/components/DebugDialog/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const CopyToClipboardWrapper = styled.div({
gap: theme.space.lg,

backgroundColor: theme.colors.gray100,
padding: theme.space.xs,
paddingInline: theme.space.xs,
borderRadius: theme.radius.xs,
border: `1px solid ${theme.colors.gray300}`,
height: '2.5rem',

'@media (hover: hover)': {
'&:hover': {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import { Space, Text } from 'ui'
import styled from '@emotion/styled'
import { useRouter } from 'next/router'
import { Button, Space, Text, theme } from 'ui'
import { useShopSession } from '@/services/shopSession/ShopSessionContext'
import { PageLink } from '@/utils/PageLink'
import { CopyToClipboard } from './CopyToClipboard'

export const DebugShopSessionSection = () => {
const { shopSession } = useShopSession()
const router = useRouter()

if (!shopSession) return null

const nextUrl = `/${router.locale}${router.pathname}`

return (
<Space y={0.25}>
<Text as="p" size="sm">
Shop Session
</Text>
<CopyToClipboard>{shopSession.id}</CopyToClipboard>
</Space>
<Layout>
<Space y={0.25} style={{ flex: 1 }}>
<Text as="p" size="sm">
Shop Session
</Text>
<CopyToClipboard>{shopSession.id}</CopyToClipboard>
</Space>

<Button variant="secondary" size="medium" href={PageLink.apiSessionReset({ next: nextUrl })}>
Reset
</Button>
</Layout>
)
}

const Layout = styled.div({
display: 'grid',
gridTemplateColumns: '4fr 1fr',
alignItems: 'flex-end',
gap: theme.space.xs,
})
2 changes: 1 addition & 1 deletion apps/store/src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const TextField = (props: Props) => {
)}

{inputValue &&
(inputProps.disabled ? (
(inputProps.disabled || inputProps.readOnly ? (
<LockIcon size="1rem" color={theme.colors.textSecondary} />
) : (
<DeleteButton
Expand Down
4 changes: 2 additions & 2 deletions apps/store/src/pages/api/session/reset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { type NextApiRequest, type NextApiResponse } from 'next'
import { ORIGIN_URL, PageLink } from '@/utils/PageLink'
import { resetSessionServerSide } from '@/utils/resetSessionServerSide'

Expand All @@ -18,7 +18,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {

const destination = nextURL.toString()
console.log(`Re-directing to destination: ${destination}`)
return res.redirect(destination)
res.redirect(destination)
}

export default handler
5 changes: 4 additions & 1 deletion apps/store/src/utils/PageLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export const PageLink = {
return url
},

apiSessionReset: () => '/api/session/reset',
apiSessionReset: ({ next }: { next?: string } = {}) => {
const nextQueryParam = next ? `?next=${next}` : ''
return `/api/session/reset${nextQueryParam}`
},
apiSessionCreate: (ssn: string) => `/api/session/create/?ssn=${ssn}`,
apiCampaign: ({ code, next }: CampaignAddRoute) => {
const nextQueryParam = next ? `?next=${next}` : ''
Expand Down