import api from '../utils/api'

export const SET_DOMAINS_VALUE = Symbol()
export const SET_DOMAINS_FETCHING = Symbol()
export const SET_DOMAINS_ERROR = Symbol()
export const RESET_DOMAINS = Symbol()

export const setDomainsValue = (payload) => ({
	type: SET_DOMAINS_VALUE,
	payload
})

export const setDomainsFetching = (payload) => ({
	type: SET_DOMAINS_FETCHING,
	payload
})

export const setDomainsError = (payload) => ({
	type: SET_DOMAINS_ERROR,
	payload
})

export const resetDomains = () => ({
	type: RESET_DOMAINS
})

export const fetchDomains = (props) => async (dispatch) => {

	dispatch(setDomainsFetching(true))
	dispatch(setDomainsError())

	try {

		const data = await api('/domains', {
			method: 'get',
			props
		})

		dispatch(setDomainsValue(data))

	} catch (err) {

		dispatch(setDomainsError(err))

	} finally {

		dispatch(setDomainsFetching(false))

	}

}

export const updateDomain = (props, domainId, state) => async (dispatch) => {

	dispatch(setDomainsFetching(true))
	dispatch(setDomainsError())

	try {

		await api(`/domains/${ domainId }`, {
			method: 'put',
			body: JSON.stringify(state),
			props
		})

		dispatch(fetchDomains(props))

	} catch (err) {

		dispatch(setDomainsError(err))

	} finally {

		dispatch(setDomainsFetching(false))

	}

}
@@ -1255,28 +1255,434 @@
 mainsFetching(false))%0A%0A%09%7D%0A%0A%7D
+%0A%0Aexport const deleteDomain = (props, domainId, state) =%3E async (dispatch) =%3E %7B%0A%0A%09dispatch(setDomainsFetching(true))%0A%09dispatch(setDomainsError())%0A%0A%09try %7B%0A%0A%09%09await api(%60/domains/$%7B domainId %7D%60, %7B%0A%09%09%09method: 'delete',%0A%09%09%09body: JSON.stringify(state),%0A%09%09%09props%0A%09%09%7D)%0A%0A%09%09dispatch(fetchDomains(props))%0A%0A%09%7D catch (err) %7B%0A%0A%09%09dispatch(setDomainsError(err))%0A%0A%09%7D finally %7B%0A%0A%09%09dispatch(setDomainsFetching(false))%0A%0A%09%7D%0A%0A%7D

Add delete domain function