1
1
import { Badge } from 'react-bootstrap'
2
- import { Form , Input , SubmitButton } from './form'
2
+ import { Form , Input , SubmitButton , CopyButton } from './form'
3
3
import { useMutation , useQuery } from '@apollo/client'
4
4
import { customDomainSchema } from '@/lib/validate'
5
5
import ActionTooltip from './action-tooltip'
@@ -12,6 +12,9 @@ import { signIn } from 'next-auth/react'
12
12
import BrandingForm from '@/components/territory-branding-form'
13
13
import Head from 'next/head'
14
14
import Moon from '@/svgs/moon-fill.svg'
15
+ import ClipboardLine from '@/svgs/clipboard-line.svg'
16
+ import RefreshLine from '@/svgs/refresh-line.svg'
17
+ import styles from './item.module.css'
15
18
16
19
// Domain context for custom domains
17
20
const DomainContext = createContext ( {
@@ -91,19 +94,27 @@ const getSSLStatusBadge = (status) => {
91
94
}
92
95
}
93
96
94
- export function DomainLabel ( { customDomain, polling } ) {
97
+ const DomainLabel = ( { customDomain, polling } ) => {
95
98
const { domain, status, verification, lastVerifiedAt } = customDomain || { }
99
+
96
100
return (
97
101
< div className = 'd-flex align-items-center gap-2' >
98
102
< span > custom domain</ span >
99
103
{ domain && (
100
104
< ActionTooltip overlayText = { lastVerifiedAt ? new Date ( lastVerifiedAt ) . toLocaleString ( ) : '' } >
101
105
< div className = 'd-flex align-items-center gap-2' >
102
- { status !== 'HOLD' && (
103
- < >
104
- { getStatusBadge ( verification ?. dns ?. state ) }
105
- { getSSLStatusBadge ( verification ?. ssl ?. state ) }
106
- </ >
106
+ { status !== 'HOLD'
107
+ ? (
108
+ < >
109
+ { getStatusBadge ( verification ?. dns ?. state ) }
110
+ { getSSLStatusBadge ( verification ?. ssl ?. state ) }
111
+ </ >
112
+ )
113
+ : ( < Badge bg = 'secondary' > HOLD</ Badge > ) }
114
+ { status === 'HOLD' && (
115
+ < SubmitButton variant = 'link' className = 'p-0' >
116
+ < RefreshLine className = { styles . refresh } style = { { width : '1rem' , height : '1rem' } } />
117
+ </ SubmitButton >
107
118
) }
108
119
{ polling && < Moon className = 'spin fill-grey' style = { { width : '1rem' , height : '1rem' } } /> }
109
120
</ div >
@@ -113,38 +124,66 @@ export function DomainLabel ({ customDomain, polling }) {
113
124
)
114
125
}
115
126
116
- export function DomainGuidelines ( { customDomain } ) {
127
+ const DomainGuidelines = ( { customDomain } ) => {
117
128
const { domain, verification } = customDomain || { }
129
+
130
+ const dnsRecord = ( host , value ) => (
131
+ < div className = 'd-flex align-items-center gap-2' >
132
+ < span className = { `${ styles . record } ` } >
133
+ < small className = 'fw-bold text-muted d-flex align-items-center gap-1 position-relative' >
134
+ host
135
+ < CopyButton
136
+ value = { host }
137
+ append = {
138
+ < ClipboardLine
139
+ className = { `${ styles . clipboard } ` }
140
+ style = { { width : '1rem' , height : '1rem' } }
141
+ />
142
+ }
143
+ />
144
+ </ small >
145
+ < pre > { host } </ pre >
146
+ </ span >
147
+ < span className = { `${ styles . record } ` } >
148
+ < small className = 'fw-bold text-muted d-flex align-items-center gap-1 position-relative' >
149
+ value
150
+ < CopyButton
151
+ value = { value }
152
+ append = {
153
+ < ClipboardLine
154
+ className = { `${ styles . clipboard } ` }
155
+ style = { { width : '1rem' , height : '1rem' } }
156
+ />
157
+ }
158
+ />
159
+ </ small >
160
+ < pre > { value } </ pre >
161
+ </ span >
162
+ </ div >
163
+ )
164
+
118
165
return (
119
- < >
166
+ < div className = 'd-flex' >
120
167
{ ( verification ?. dns ?. state && verification ?. dns ?. state !== 'VERIFIED' ) && (
121
- < >
168
+ < div className = 'd-flex flex-column gap-2' >
122
169
< h5 > Step 1: Verify your domain</ h5 >
123
170
< p > Add the following DNS records to verify ownership of your domain:</ p >
124
171
< h6 > CNAME</ h6 >
125
- < p >
126
- Host: < pre > { domain || 'www' } </ pre >
127
- Value: < pre > stacker.news</ pre >
128
- </ p >
172
+ { dnsRecord ( domain || 'www' , verification ?. dns ?. cname ) }
173
+ < hr />
129
174
< h6 > TXT</ h6 >
130
- < p >
131
- Host: < pre > { domain || 'www' } </ pre >
132
- Value: < pre > { verification ?. dns ?. txt } </ pre >
133
- </ p >
134
- </ >
175
+ { dnsRecord ( domain || 'www' , verification ?. dns ?. txt ) }
176
+ </ div >
135
177
) }
136
178
{ verification ?. ssl ?. state === 'PENDING' && (
137
- < >
179
+ < div className = '' >
138
180
< h5 > Step 2: Prepare your domain for SSL</ h5 >
139
181
< p > We issued an SSL certificate for your domain. To validate it, add the following CNAME record:</ p >
140
182
< h6 > CNAME</ h6 >
141
- < p >
142
- Host: < pre > { verification ?. ssl ?. cname || 'waiting for SSL certificate' } </ pre >
143
- Value: < pre > { verification ?. ssl ?. value || 'waiting for SSL certificate' } </ pre >
144
- </ p >
145
- </ >
183
+ { dnsRecord ( verification ?. ssl ?. cname || 'waiting for SSL certificate' , verification ?. ssl ?. value || 'waiting for SSL certificate' ) }
184
+ </ div >
146
185
) }
147
- </ >
186
+ </ div >
148
187
)
149
188
}
150
189
@@ -179,7 +218,11 @@ export default function CustomDomainForm ({ sub }) {
179
218
}
180
219
} )
181
220
refetch ( )
182
- toaster . success ( 'domain updated successfully' )
221
+ if ( domain ) {
222
+ toaster . success ( 'started domain verification' )
223
+ } else {
224
+ toaster . success ( 'domain removed successfully' )
225
+ }
183
226
} catch ( error ) {
184
227
toaster . danger ( 'failed to update domain' , { error } )
185
228
}
0 commit comments