@@ -0,0 +1,29 @@
|
||||
import {useMutation} from '@tanstack/react-query';
|
||||
import {apiClient} from '@common/http/query-client';
|
||||
import {BackendResponse} from '@common/http/backend-response/backend-response';
|
||||
import {UseFormReturn} from 'react-hook-form';
|
||||
import {onFormQueryError} from '@common/errors/on-form-query-error';
|
||||
|
||||
interface Response extends BackendResponse {
|
||||
serverIp: string;
|
||||
}
|
||||
|
||||
export interface AuthorizeDomainConnectPayload {
|
||||
host: string;
|
||||
}
|
||||
|
||||
// check if is this host is not connected already and if user has permissions to connect domains
|
||||
export function useAuthorizeDomainConnect(
|
||||
form: UseFormReturn<AuthorizeDomainConnectPayload>,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (props: AuthorizeDomainConnectPayload) => authorize(props),
|
||||
onError: err => onFormQueryError(err, form),
|
||||
});
|
||||
}
|
||||
|
||||
function authorize(payload: AuthorizeDomainConnectPayload): Promise<Response> {
|
||||
return apiClient
|
||||
.post('secure/custom-domain/authorize/store', payload)
|
||||
.then(r => r.data);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import {useMutation, useQueryClient} from '@tanstack/react-query';
|
||||
import {apiClient} from '@common/http/query-client';
|
||||
import {useTrans} from '@common/i18n/use-trans';
|
||||
import {BackendResponse} from '@common/http/backend-response/backend-response';
|
||||
import {showHttpErrorToast} from '@common/utils/http/show-http-error-toast';
|
||||
import {message} from '@common/i18n/message';
|
||||
import {toast} from '@common/ui/toast/toast';
|
||||
import {DatatableDataQueryKey} from '@common/datatable/requests/paginated-resources';
|
||||
import {CustomDomain} from '@common/custom-domains/custom-domain';
|
||||
|
||||
interface Response extends BackendResponse {
|
||||
domain: CustomDomain;
|
||||
}
|
||||
|
||||
interface Payload {
|
||||
host: string;
|
||||
global?: boolean;
|
||||
}
|
||||
|
||||
export function useConnectDomain() {
|
||||
const {trans} = useTrans();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (props: Payload) => connectDomain(props),
|
||||
onSuccess: response => {
|
||||
toast.positive(
|
||||
trans(
|
||||
message('“:domain” connected', {
|
||||
values: {domain: response.domain.host},
|
||||
}),
|
||||
),
|
||||
);
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: DatatableDataQueryKey('custom-domain'),
|
||||
});
|
||||
},
|
||||
onError: err => showHttpErrorToast(err),
|
||||
});
|
||||
}
|
||||
|
||||
function connectDomain(payload: Payload): Promise<Response> {
|
||||
return apiClient.post('custom-domain', payload).then(r => r.data);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import {useMutation} from '@tanstack/react-query';
|
||||
import {apiClient, queryClient} from '@common/http/query-client';
|
||||
import {useTrans} from '@common/i18n/use-trans';
|
||||
import {BackendResponse} from '@common/http/backend-response/backend-response';
|
||||
import {showHttpErrorToast} from '@common/utils/http/show-http-error-toast';
|
||||
import {message} from '@common/i18n/message';
|
||||
import {toast} from '@common/ui/toast/toast';
|
||||
import {DatatableDataQueryKey} from '@common/datatable/requests/paginated-resources';
|
||||
import {CustomDomain} from '@common/custom-domains/custom-domain';
|
||||
import {removeProtocol} from '@common/utils/urls/remove-protocol';
|
||||
|
||||
interface Response extends BackendResponse {}
|
||||
|
||||
interface Payload {
|
||||
domain: CustomDomain;
|
||||
}
|
||||
|
||||
export function useDeleteDomain() {
|
||||
const {trans} = useTrans();
|
||||
return useMutation({
|
||||
mutationFn: (props: Payload) => deleteDomain(props),
|
||||
onSuccess: (response, props) => {
|
||||
toast.positive(
|
||||
trans(
|
||||
message('“:domain” removed', {
|
||||
values: {domain: removeProtocol(props.domain.host)},
|
||||
}),
|
||||
),
|
||||
);
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: DatatableDataQueryKey('custom-domain'),
|
||||
});
|
||||
},
|
||||
onError: err => showHttpErrorToast(err),
|
||||
});
|
||||
}
|
||||
|
||||
function deleteDomain({domain}: Payload): Promise<Response> {
|
||||
return apiClient.delete(`custom-domain/${domain.id}`).then(r => r.data);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import {useMutation} from '@tanstack/react-query';
|
||||
import {apiClient, queryClient} from '@common/http/query-client';
|
||||
import {BackendResponse} from '@common/http/backend-response/backend-response';
|
||||
import {showHttpErrorToast} from '@common/utils/http/show-http-error-toast';
|
||||
import {DatatableDataQueryKey} from '@common/datatable/requests/paginated-resources';
|
||||
import {CustomDomain} from '@common/custom-domains/custom-domain';
|
||||
|
||||
interface Response extends BackendResponse {
|
||||
domain: CustomDomain;
|
||||
}
|
||||
|
||||
interface Payload {
|
||||
domainId: number | string;
|
||||
host?: string;
|
||||
global?: boolean;
|
||||
resource_id?: number | null;
|
||||
resource_type?: string | null;
|
||||
}
|
||||
|
||||
export function useUpdateDomain() {
|
||||
return useMutation({
|
||||
mutationFn: (props: Payload) => updateDomain(props),
|
||||
onSuccess: (response, props) => {
|
||||
return queryClient.invalidateQueries({
|
||||
queryKey: DatatableDataQueryKey('custom-domain'),
|
||||
});
|
||||
},
|
||||
onError: err => showHttpErrorToast(err),
|
||||
});
|
||||
}
|
||||
|
||||
function updateDomain(payload: Payload): Promise<Response> {
|
||||
return apiClient
|
||||
.put(`custom-domain/${payload.domainId}`, payload)
|
||||
.then(r => r.data);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import {useMutation} from '@tanstack/react-query';
|
||||
import {apiClient} from '@common/http/query-client';
|
||||
import {BackendResponse} from '@common/http/backend-response/backend-response';
|
||||
|
||||
interface Response extends BackendResponse {
|
||||
result: 'connected' | null;
|
||||
}
|
||||
|
||||
interface Payload {
|
||||
host: string;
|
||||
}
|
||||
|
||||
export function useValidateDomainDns() {
|
||||
return useMutation({
|
||||
mutationFn: (props: Payload) => authorize(props),
|
||||
});
|
||||
}
|
||||
|
||||
function authorize(payload: Payload): Promise<Response> {
|
||||
return apiClient
|
||||
.post('secure/custom-domain/validate/2BrM45vvfS/api', payload)
|
||||
.then(r => r.data);
|
||||
}
|
||||
Reference in New Issue
Block a user