Skip to content

Commit 3331353

Browse files
committed
cleanup: middleware, custom branding, gql fragments, adjust migration date
1 parent 3264540 commit 3331353

File tree

9 files changed

+58
-74
lines changed

9 files changed

+58
-74
lines changed

components/nav/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ function LogoutObstacle ({ onClose }) {
352352

353353
await signOut({ callbackUrl: '/', redirect: !customDomain })
354354
if (customDomain) {
355-
onClose()
355+
router.push('/') // next auth redirect only supports the main domain
356356
}
357357
}}
358358
>

components/territory-branding-form.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ export default function BrandingForm ({ sub }) {
3535
}
3636
}
3737

38-
const subColors = sub?.customBranding?.colors || {}
38+
const customBranding = sub?.customBranding || {}
39+
const subColors = customBranding?.colors || {}
3940

4041
const initialValues = {
41-
title: sub?.customBranding?.title || sub?.subName,
42+
title: customBranding?.title || sub?.name,
4243
primary: subColors?.primary || '#FADA5E',
4344
secondary: subColors?.secondary || '#F6911D',
4445
info: subColors?.info || '#007cbe',
4546
success: subColors?.success || '#5c8001',
4647
danger: subColors?.danger || '#c03221',
47-
logoId: sub?.customBranding?.logoId || null,
48-
faviconId: sub?.customBranding?.faviconId || null
48+
logoId: customBranding?.logoId || null,
49+
faviconId: customBranding?.faviconId || null
4950
}
5051

51-
// TODO: cleanup
5252
return (
5353
<Form
5454
initial={initialValues}

components/territory-domains.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ export const DomainProvider = ({ customDomain: ssrCustomDomain, children }) => {
2626
const router = useRouter()
2727
const [customDomain, setCustomDomain] = useState(ssrCustomDomain || null)
2828

29+
// maintain the custom domain state across re-renders
2930
useEffect(() => {
3031
if (ssrCustomDomain && !customDomain) {
3132
setCustomDomain(ssrCustomDomain)
3233
}
3334
}, [ssrCustomDomain])
3435

35-
// TODO: alternative to this, for test only
36-
// auth sync
36+
// temporary auth sync
3737
useEffect(() => {
3838
if (router.query.type === 'sync') {
3939
console.log('signing in with sync')
4040
signIn('sync', { token: router.query.token, callbackUrl: router.query.callbackUrl, multiAuth: router.query.multiAuth, redirect: false })
41+
router.push(router.query.callbackUrl) // next auth redirect only supports the main domain
4142
}
4243
}, [router.query.type])
4344

@@ -143,7 +144,6 @@ export function DomainGuidelines ({ customDomain }) {
143144
)
144145
}
145146

146-
// TODO: clean this up, might not need all this refreshing, plus all this polling is not done correctly
147147
export default function CustomDomainForm ({ sub }) {
148148
const [setCustomDomain] = useMutation(SET_CUSTOM_DOMAIN)
149149

@@ -184,12 +184,11 @@ export default function CustomDomainForm ({ sub }) {
184184
return (
185185
<>
186186
<Form
187-
initial={{ domain: domain || sub.customDomain?.domain }}
187+
initial={{ domain }}
188188
schema={customDomainSchema}
189189
onSubmit={onSubmit}
190190
className='mb-2'
191191
>
192-
{/* TODO: too many flexes */}
193192
<div className='d-flex align-items-center gap-2'>
194193
<Input
195194
label={<DomainLabel customDomain={data?.customDomain} polling={polling} />}

components/territory-form.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export default function TerritoryForm ({ sub }) {
8888
}
8989
}, [sub, billing])
9090

91-
// TODO: Add a custom domain textbox and verification status; validation too
9291
return (
9392
<FeeButtonProvider baseLineItems={lineItems}>
9493
<Form

components/territory-header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function TerritoryInfo ({ sub, includeLink }) {
7070
<span className='fw-bold'>{numWithUnits(sub.replyCost)}</span>
7171
</div>
7272
</div>
73-
{sub.customDomain && (
73+
{sub.customDomain?.status === 'ACTIVE' && (
7474
<div className='text-muted'>
7575
<span>website </span>
7676
<Link className='fw-bold' href={`https://${sub.customDomain.domain}`}>{sub.customDomain.domain}</Link>

fragments/brandings.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
import { gql } from 'graphql-tag'
22

3-
export const GET_CUSTOM_BRANDING = gql`
4-
query CustomBranding($subName: String!) {
5-
customBranding(subName: $subName) {
6-
title
7-
colors
8-
logoId
9-
faviconId
10-
subName
11-
}
12-
}
13-
`
14-
15-
export const GET_CUSTOM_BRANDING_FIELDS = gql`
3+
export const CUSTOM_BRANDING_FIELDS = gql`
164
fragment CustomBrandingFields on CustomBranding {
175
title
186
colors
@@ -22,8 +10,17 @@ export const GET_CUSTOM_BRANDING_FIELDS = gql`
2210
}
2311
`
2412

13+
export const GET_CUSTOM_BRANDING = gql`
14+
${CUSTOM_BRANDING_FIELDS}
15+
query CustomBranding($subName: String!) {
16+
customBranding(subName: $subName) {
17+
...CustomBrandingFields
18+
}
19+
}
20+
`
21+
2522
export const SET_CUSTOM_BRANDING = gql`
26-
${GET_CUSTOM_BRANDING_FIELDS}
23+
${CUSTOM_BRANDING_FIELDS}
2724
mutation SetCustomBranding($subName: String!, $branding: CustomBrandingInput!) {
2825
setCustomBranding(subName: $subName, branding: $branding) {
2926
...CustomBrandingFields

fragments/domains.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
import { gql } from 'graphql-tag'
22

3+
export const CUSTOM_DOMAIN_FIELDS = gql`
4+
fragment CustomDomainFields on CustomDomain {
5+
domain
6+
status
7+
}
8+
`
9+
10+
export const CUSTOM_DOMAIN_FULL_FIELDS = gql`
11+
${CUSTOM_DOMAIN_FIELDS}
12+
fragment CustomDomainFullFields on CustomDomain {
13+
...CustomDomainFields
14+
lastVerifiedAt
15+
verification {
16+
dns {
17+
state
18+
cname
19+
txt
20+
}
21+
ssl {
22+
state
23+
arn
24+
cname
25+
value
26+
}
27+
}
28+
}
29+
`
30+
331
export const GET_CUSTOM_DOMAIN = gql`
32+
${CUSTOM_DOMAIN_FULL_FIELDS}
433
query CustomDomain($subName: String!) {
534
customDomain(subName: $subName) {
6-
domain
7-
status
8-
lastVerifiedAt
9-
verification {
10-
dns {
11-
state
12-
cname
13-
txt
14-
}
15-
ssl {
16-
state
17-
arn
18-
cname
19-
value
20-
}
21-
}
35+
...CustomDomainFullFields
2236
}
2337
}
2438
`
@@ -32,14 +46,6 @@ export const GET_DOMAIN_MAPPING = gql`
3246
}
3347
`
3448

35-
export const GET_CUSTOM_DOMAIN_FULL = gql`
36-
${GET_CUSTOM_DOMAIN}
37-
fragment CustomDomainFull on CustomDomain {
38-
...CustomDomainFields
39-
failedAttempts
40-
}
41-
`
42-
4349
export const SET_CUSTOM_DOMAIN = gql`
4450
mutation SetCustomDomain($subName: String!, $domain: String!) {
4551
setCustomDomain(subName: $subName, domain: $domain) {

fragments/subs.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { gql } from '@apollo/client'
22
import { ITEM_FIELDS, ITEM_FULL_FIELDS } from './items'
33
import { COMMENTS_ITEM_EXT_FIELDS } from './comments'
4+
import { CUSTOM_DOMAIN_FIELDS } from './domains'
5+
import { CUSTOM_BRANDING_FIELDS } from './brandings'
46

57
// we can't import from users because of circular dependency
68
const STREAK_FIELDS = gql`
@@ -15,6 +17,8 @@ const STREAK_FIELDS = gql`
1517

1618
// TODO: better place
1719
export const SUB_FIELDS = gql`
20+
${CUSTOM_DOMAIN_FIELDS}
21+
${CUSTOM_BRANDING_FIELDS}
1822
fragment SubFields on Sub {
1923
name
2024
createdAt
@@ -36,31 +40,10 @@ export const SUB_FIELDS = gql`
3640
meSubscription
3741
nsfw
3842
customDomain {
39-
createdAt
40-
updatedAt
41-
domain
42-
subName
43-
lastVerifiedAt
44-
status
45-
verification {
46-
dns {
47-
state
48-
cname
49-
txt
50-
}
51-
ssl {
52-
state
53-
arn
54-
cname
55-
value
56-
}
57-
}
43+
...CustomDomainFields
5844
}
5945
customBranding {
60-
title
61-
colors
62-
logoId
63-
faviconId
46+
...CustomBrandingFields
6447
}
6548
}`
6649

0 commit comments

Comments
 (0)