Repository URL to install this package:
|
Version:
1.1.3 ▾
|
import { paywallStatus, createCalendarError, getCalendarError, unarchiveError } from '../constants/paywall';
import { createCalendarRequest, getCalendarRequest, unarchiveActivityRequest } from './requests';
import { recaptchaError } from '../constants/common';
export const createCalendar = ({
token,
apiHost,
slots = [],
calendarDetails = {},
resolve,
captchaToken,
primaryCalendarAccountId,
}) =>
createCalendarRequest({
token,
captchaToken,
apiHost,
slots,
calendarDetails,
primaryCalendarAccountId,
})
.then(async res => {
const calendarResponse = await res.text();
const parsedCalendarResponse = JSON.parse(calendarResponse);
if (!res.ok) {
if (parsedCalendarResponse.code === 17) {
throw new Error(recaptchaError);
}
throw new Error(parsedCalendarResponse.message);
}
resolve({
status: paywallStatus.PASS,
payload: {
externalId: parsedCalendarResponse.externalId,
},
});
})
.catch(e => {
resolve({ ...createCalendarError, message: e.message });
});
export const duplicateCalendar = ({ token, captchaToken, apiHost, id, resolve, primaryCalendarAccountId }) => {
getCalendarRequest({ token, captchaToken, id, apiHost })
.then(async res => {
const calendarResponse = await res.text();
const parsedCalendarResponse = JSON.parse(calendarResponse);
if (!res.ok) {
throw new Error(parsedCalendarResponse.message);
}
const { slots, place, description, subject, duration } = parsedCalendarResponse;
const calendarDetails = {
place,
description,
subject,
duration,
};
const filteredSlots = slots
.filter(slot => +new Date(slot.start) > +new Date())
.map(slot => ({ ...slot, attendee: null }));
createCalendar({
token,
captchaToken,
apiHost,
slots: filteredSlots,
calendarDetails,
resolve,
primaryCalendarAccountId,
});
})
.catch(e => {
resolve({ ...getCalendarError, message: e.message });
});
};
export const unarchiveActivity = ({ token, apiHost, id, resolve }) =>
unarchiveActivityRequest({ token, apiHost, id })
.then(() => {
resolve({ status: paywallStatus.PASS });
})
.catch(e => {
resolve({ ...unarchiveError, message: e.message });
});