Authenticated calls to Event API from Admin
This commit is contained in:
+10
-4
@@ -23,14 +23,17 @@ export interface Event {
|
||||
}
|
||||
|
||||
export async function getEvents(options: any = {}): Promise<Event[]> {
|
||||
const { onlyNonPast, limit } = options;
|
||||
const { onlyNonPast, limit, auth } = options;
|
||||
try {
|
||||
const params = {
|
||||
since: onlyNonPast ? (new Date()).toISOString() : undefined,
|
||||
limit,
|
||||
};
|
||||
const search = qs.stringify(params);
|
||||
const resp = await axios.get(`${url}?${search}`);
|
||||
const headers = auth ? { "Authorization": getAuthHeader() } : null;
|
||||
const resp = await axios.get(`${url}?${search}`, {
|
||||
headers
|
||||
});
|
||||
return resp.data["results"];
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@@ -38,9 +41,12 @@ export async function getEvents(options: any = {}): Promise<Event[]> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getEvent(id: number): Promise<Event> {
|
||||
export async function getEvent(id: number, auth = false): Promise<Event> {
|
||||
try {
|
||||
const resp = await axios.get(`${url}${id}/`);
|
||||
const headers = auth ? { "Authorization": getAuthHeader() } : null;
|
||||
const resp = await axios.get(`${url}${id}/`, {
|
||||
headers
|
||||
});
|
||||
return resp.data;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
@@ -48,7 +48,7 @@ class AdminEventPage extends React.Component<AdminEventPageProps, AdminEventPage
|
||||
}
|
||||
|
||||
fetchEvents = async () => {
|
||||
const getEventsPromise = getEvents();
|
||||
const getEventsPromise = getEvents({ auth: true });
|
||||
try {
|
||||
const events = await getEventsPromise;
|
||||
this.setState({
|
||||
|
||||
@@ -54,7 +54,7 @@ class EventCreatePage extends React.Component<EventCreatePageProps, EventCreateP
|
||||
|
||||
fetchInitialFormData = async (id) => {
|
||||
try {
|
||||
const data = await getEvent(id);
|
||||
const data = await getEvent(id, true);
|
||||
data.tags = data.tag_id as any;
|
||||
data.signupForm = data.signup_id as any;
|
||||
this.setState({
|
||||
|
||||
Reference in New Issue
Block a user