diff --git a/packages/hoppscotch-sh-admin/src/components.d.ts b/packages/hoppscotch-sh-admin/src/components.d.ts index d976a8968..38ba4e350 100644 --- a/packages/hoppscotch-sh-admin/src/components.d.ts +++ b/packages/hoppscotch-sh-admin/src/components.d.ts @@ -40,6 +40,7 @@ declare module '@vue/runtime-core' { SettingsServerRestart: typeof import('./components/settings/ServerRestart.vue')['default'] SettingsSmtpConfiguration: typeof import('./components/settings/SmtpConfiguration.vue')['default'] SetupDataSharing: typeof import('./components/setup/DataSharing.vue')['default'] + SetupDataSharingAndNewsletter: typeof import('./components/setup/DataSharingAndNewsletter.vue')['default'] TeamsAdd: typeof import('./components/teams/Add.vue')['default'] TeamsDetails: typeof import('./components/teams/Details.vue')['default'] TeamsInvite: typeof import('./components/teams/Invite.vue')['default'] diff --git a/packages/hoppscotch-sh-admin/src/components/setup/DataSharing.vue b/packages/hoppscotch-sh-admin/src/components/setup/DataSharingAndNewsletter.vue similarity index 100% rename from packages/hoppscotch-sh-admin/src/components/setup/DataSharing.vue rename to packages/hoppscotch-sh-admin/src/components/setup/DataSharingAndNewsletter.vue diff --git a/packages/hoppscotch-sh-admin/src/helpers/listmonk.ts b/packages/hoppscotch-sh-admin/src/helpers/listmonk.ts deleted file mode 100644 index 31a019a25..000000000 --- a/packages/hoppscotch-sh-admin/src/helpers/listmonk.ts +++ /dev/null @@ -1,147 +0,0 @@ -import * as E from 'fp-ts/Either'; -import { EmailCodec } from '~/helpers/Email'; -import axios, { AxiosResponse } from 'axios'; -import { - REQ_FAILED, - EMAIL_NOT_FOUND, - INVALID_EMAIL, - SUBSCRIBER_ALREADY_EXISTS, -} from '~/helpers/errors'; - -enum HttpStatus { - BAD_REQUEST = 400, - CONFLICT = 409, - NOT_FOUND = 404, -} - -export type ResponseError = { - message: string; - statusCode: HttpStatus; -}; - -const handleResponse = (response: AxiosResponse) => { - if (response.status >= 200 && response.status < 300) { - return E.right(response.data); - } else { - return E.left({ - statusCode: HttpStatus.BAD_REQUEST, - message: REQ_FAILED, - }); - } -}; - -const listmonkConfig = { - baseURL: `sdsd`, - apiURL: `sfs`, - listmonkUsername: `fsdfs`, - listmonkPassword: `fdsf`, - newsletterListID: parseInt('fasf', 10), -}; - -const listmonk = axios.create({ - baseURL: listmonkConfig.apiURL, - auth: { - username: listmonkConfig.listmonkUsername, - password: listmonkConfig.listmonkPassword, - }, -}); -const castToSubscriber = (subscriberResponse: any) => { - return { - id: subscriberResponse.id, - created_at: subscriberResponse.created_at, - updated_at: subscriberResponse.updated_at, - uuid: subscriberResponse.uuid, - email: subscriberResponse.email, - name: subscriberResponse.name, - status: subscriberResponse.status, - lists: subscriberResponse.lists.map((list: any) => ({ - subscription_status: list.subscription_status, - subscription_created_at: list.subscription_created_at, - subscription_updated_at: list.subscription_updated_at, - id: list.id, - })), - }; -}; - -const fetchSubscriberDetailsByEmail = async (emailID: string) => { - const subscribersURL = `${listmonkConfig.apiURL}/subscribers`; - const params = { - query: `email = '${emailID}'`, - }; - try { - const response = await listmonk.get(subscribersURL, { - params: params, - }); - if (response.status >= 200 && response.status < 300) { - // check length of response results array - if (!response.data.data.results.length) { - return E.left({ - statusCode: HttpStatus.NOT_FOUND, - message: EMAIL_NOT_FOUND, - }); - } - - // fetch subscriber data from response results array object and typecast to `Subscriber` type. - const subscriberRes = response.data.data.results[0]; - const subscriber = castToSubscriber(subscriberRes); - return E.right(subscriber); - } else { - return E.left({ - statusCode: HttpStatus.BAD_REQUEST, - message: REQ_FAILED, - }); - } - } catch (err: any) { - return E.left({ - message: err.response.statusText, - statusCode: err.response.status, - }); - } -}; - -export const addSubscriberNewsletterList = async ( - emailID: string, - subscriberName: string -) => { - // Validate email - const isEmailValid = EmailCodec.is(emailID); - if (!isEmailValid) - return E.left({ - message: INVALID_EMAIL, - statusCode: HttpStatus.BAD_REQUEST, - }); - - // Check if subscriber already exists - const subscriber = await fetchSubscriberDetailsByEmail(emailID); - if (E.isRight(subscriber)) { - return E.left({ - message: SUBSCRIBER_ALREADY_EXISTS, - statusCode: HttpStatus.CONFLICT, - }); - } - - // Add a new subscriber to newsletter - const addSubscriberURL = `${listmonkConfig.apiURL}/subscribers`; - const reqData = { - email: `${emailID}`, - name: `${subscriberName}`, - status: 'enabled', - lists: [listmonkConfig.newsletterListID], - preconfirm_subscriptions: true, - }; - - try { - const response = await listmonk.post(addSubscriberURL, reqData, { - headers: { - 'Content-Type': 'application/json', - }, - }); - - return handleResponse(response); - } catch (err: any) { - return E.left({ - message: err.response.statusText, - statusCode: err.response.status, - }); - } -}; diff --git a/packages/hoppscotch-sh-admin/src/modules/admin.ts b/packages/hoppscotch-sh-admin/src/modules/admin.ts index 1412823ac..20e575529 100644 --- a/packages/hoppscotch-sh-admin/src/modules/admin.ts +++ b/packages/hoppscotch-sh-admin/src/modules/admin.ts @@ -54,8 +54,6 @@ export default { * Else, the Setup page */ if (isGuestRoute(to.name)) { - console.log('hi'); - const name = isInfraNotSetup ? 'setup' : 'dashboard'; return next({ name }); }