1
- import { useState } from 'react'
2
1
import { Badge } from 'react-bootstrap'
3
2
import { Form , Input , SubmitButton } from './form'
4
3
import { gql , useMutation } from '@apollo/client'
5
4
import Info from './info'
6
5
import { customDomainSchema } from '@/lib/validate'
7
6
import ActionTooltip from './action-tooltip'
7
+ import { useToast } from '@/components/toast'
8
8
9
9
const UPDATE_CUSTOM_DOMAIN = gql `
10
10
mutation UpdateCustomDomain($subName: String!, $domain: String!) {
@@ -17,23 +17,19 @@ const UPDATE_CUSTOM_DOMAIN = gql`
17
17
18
18
// TODO: verification states should refresh
19
19
export default function CustomDomainForm ( { sub } ) {
20
- const [ updateCustomDomain ] = useMutation ( UPDATE_CUSTOM_DOMAIN )
21
- const [ error , setError ] = useState ( null )
22
- const [ success , setSuccess ] = useState ( false )
20
+ const [ updateCustomDomain ] = useMutation ( UPDATE_CUSTOM_DOMAIN , {
21
+ refetchQueries : [ 'Sub' ]
22
+ } )
23
+ const toaster = useToast ( )
23
24
24
25
const onSubmit = async ( { domain } ) => {
25
- setError ( null )
26
- setSuccess ( false )
27
- console . log ( 'domain' , domain )
28
-
29
- const { data } = await updateCustomDomain ( {
26
+ await updateCustomDomain ( {
30
27
variables : {
31
28
subName : sub . name ,
32
29
domain
33
30
}
34
31
} )
35
- console . log ( 'success' , data )
36
- setSuccess ( true )
32
+ toaster . success ( 'domain updated successfully' )
37
33
}
38
34
39
35
const getStatusBadge = ( status ) => {
@@ -70,9 +66,7 @@ export default function CustomDomainForm ({ sub }) {
70
66
< Input
71
67
label = {
72
68
< div className = 'd-flex align-items-center gap-2' >
73
- < span > domain</ span >
74
- { error && < Info variant = 'danger' > error</ Info > }
75
- { success && < Info variant = 'success' > Domain settings updated successfully!</ Info > }
69
+ < span > custom domain</ span >
76
70
{ sub ?. customDomain && (
77
71
< >
78
72
< div className = 'd-flex align-items-center gap-2' >
0 commit comments