diff --git a/src/react/context/defaults.ts b/src/react/context/defaults.ts index 3a8a6601a..3b4343f94 100644 --- a/src/react/context/defaults.ts +++ b/src/react/context/defaults.ts @@ -175,6 +175,8 @@ export const defaultReadConfig: EscolaLMSContextConfig = { userConsultations: { loading: false, }, + userWebinars: { loading: false }, + fetchUserWebinars: () => Promise.reject(), fields: { loading: false, list: [], @@ -183,6 +185,9 @@ export const defaultReadConfig: EscolaLMSContextConfig = { stationaryEvents: { loading: false, }, + stationaryEvent: { + loading: false, + }, tutorConsultations: { loading: false, }, @@ -192,8 +197,12 @@ export const defaultReadConfig: EscolaLMSContextConfig = { fetchTutorConsultations: () => Promise.reject(), approveConsultationTerm: (consultationTermId: number) => Promise.reject(), rejectConsultationTerm: (consultationTermId: number) => Promise.reject(), - generateJitsyMeeting: (consultationTermId: number) => Promise.reject(consultationTermId), + generateConsultationJitsy: (consultationTermId: number) => Promise.reject(consultationTermId), + generateWebinarJitsy: (webinarId: number) => Promise.reject(webinarId), webinars: { loading: false }, + webinar: { + loading: false, + }, events: { loading: false }, fetchEvents: (filter: API.EventsParams) => Promise.reject(), }; @@ -347,18 +356,27 @@ export const defaultApiConfig: EscolaLMSContextConfig = { tutorConsultations: { loading: false, }, + userWebinars: { loading: false }, + fetchUserWebinars: () => Promise.reject(), fetchFields: (filter: API.FieldsParams) => Promise.reject(), stationaryEvents: { loading: false, }, + stationaryEvent: { + loading: false, + }, fetchStationaryEvents: (filter: API.StationaryEventsParams) => Promise.reject(), bookConsultationTerm: (id: number, term: string) => Promise.reject(), fetchWebinars: (filter: API.WebinarParams) => Promise.reject(), webinars: { loading: false }, + webinar: { + loading: false, + }, fetchTutorConsultations: () => Promise.reject(), approveConsultationTerm: (consultationTermId: number) => Promise.reject(), rejectConsultationTerm: (consultationTermId: number) => Promise.reject(), - generateJitsyMeeting: (consultationTermId: number) => Promise.reject(consultationTermId), + generateConsultationJitsy: (consultationTermId: number) => Promise.reject(consultationTermId), + generateWebinarJitsy: (webinarId: number) => Promise.reject(webinarId), events: { loading: false }, fetchEvents: (filter: API.EventsParams) => Promise.reject(), }; diff --git a/src/react/context/index.tsx b/src/react/context/index.tsx index 2593341dc..b8bd7312d 100644 --- a/src/react/context/index.tsx +++ b/src/react/context/index.tsx @@ -31,7 +31,12 @@ import { rejectConsultation, } from "./../../services/consultations"; import { getSingleProduct } from "../../services/products"; -import { webinars as getWebinars } from "../../services/webinars"; +import { + getMyWebinars, + getWebinar, + webinars as getWebinars, + genereteJitsyWebinar, +} from "../../services/webinars"; import { events as getEvents } from "../../services/events"; import { settings as getSettings, config as getConfig } from "./../../services/settings"; import { uniqueTags as getUniqueTags } from "./../../services/tags"; @@ -318,6 +323,18 @@ export const EscolaLMSContextProvider: FunctionComponent >("lms", "stationaryEvents", getDefaultData("stationaryEvents")); + const [stationaryEvent, setStationaryEvent] = useLocalStorage< + ContextStateValue + >("lms", "stationaryEvent", getDefaultData("stationaryEvent")); + + const [webinar, setWebinar] = useLocalStorage< + ContextStateValue + >("lms", "webinar", getDefaultData("webinar")); + + const [userWebinars, setUserWebinars] = useLocalStorage< + ContextListState + >("lms", "userWebinars", getDefaultData("userWebinars")); + const abortControllers = useRef<{ cart: AbortController | null; }>({ @@ -389,6 +406,37 @@ export const EscolaLMSContextProvider: FunctionComponent { + setUserWebinars((prevState) => ({ ...prevState, loading: true })); + + return token + ? getMyWebinars(token) + .then((response) => { + if (response.success) { + setUserWebinars({ + loading: false, + list: response.data, + error: undefined, + }); + } + if (response.success === false) { + setUserWebinars((prevState) => ({ + ...prevState, + loading: false, + error: response, + })); + } + }) + .catch((error) => { + setUserWebinars((prevState) => ({ + ...prevState, + loading: false, + error: error, + })); + }) + : Promise.reject(); + }, [token]); + const fetchTutorConsultations = useCallback(() => { setTutorConsultations((prevState) => ({ ...prevState, loading: true })); return token @@ -471,13 +519,20 @@ export const EscolaLMSContextProvider: FunctionComponent { return token ? genereteJitsy(token, id) : Promise.reject(); }, [token], ); + const generateWebinarJitsy = useCallback( + (id: number) => { + return token ? genereteJitsyWebinar(token, id) : Promise.reject(); + }, + [token], + ); + const fetchCertificates = useCallback(() => { setCertificates((prevState) => ({ ...prevState, loading: true })); @@ -709,67 +764,61 @@ export const EscolaLMSContextProvider: FunctionComponent { - setWebinars((prevState) => ({ ...prevState, loading: true })); - return getWebinars(filter) - .then((response) => { - if (response.success) { - setWebinars({ - loading: false, - list: response.data, - error: undefined, - }); - } - if (response.success === false) { - setWebinars((prevState) => ({ - ...prevState, - loading: false, - error: response, - })); - } - }) - .catch((error) => { + const fetchWebinars = useCallback((filter: API.WebinarParams) => { + setWebinars((prevState) => ({ ...prevState, loading: true })); + return getWebinars(filter) + .then((response) => { + if (response.success) { + setWebinars({ + loading: false, + list: response.data, + error: undefined, + }); + } + if (response.success === false) { setWebinars((prevState) => ({ ...prevState, loading: false, - error: error, + error: response, })); - }); - }, - [setWebinars], - ); + } + }) + .catch((error) => { + setWebinars((prevState) => ({ + ...prevState, + loading: false, + error: error, + })); + }); + }, []); - const fetchEvents = useCallback( - (filter: API.EventsParams) => { - setEvents((prevState) => ({ ...prevState, loading: true })); - return getEvents(filter) - .then((response) => { - if (response.success) { - setEvents({ - loading: false, - list: response, - error: undefined, - }); - } - if (response.success === false) { - setEvents((prevState) => ({ - ...prevState, - loading: false, - error: response, - })); - } - }) - .catch((error) => { + const fetchEvents = useCallback((filter: API.EventsParams) => { + setEvents((prevState) => ({ ...prevState, loading: true })); + return getEvents(filter) + .then((response) => { + if (response.success) { + setEvents({ + loading: false, + list: response, + error: undefined, + }); + } + if (response.success === false) { setEvents((prevState) => ({ ...prevState, loading: false, - error: error, + error: response, })); - }); - }, - [setEvents], - ); + } + }) + .catch((error) => { + setEvents((prevState) => ({ + ...prevState, + loading: false, + error: error, + })); + }); + }, []); const fetchUserGroup = useCallback( (id) => { @@ -1112,7 +1161,7 @@ export const EscolaLMSContextProvider: FunctionComponent { setProgram((prevState) => ({ ...prevState, loading: true })); - return id + return id && token ? getCourseProgram(id, token) .then((response) => { if (response.success) { @@ -1655,11 +1704,16 @@ export const EscolaLMSContextProvider: FunctionComponent {children} diff --git a/src/react/context/types.ts b/src/react/context/types.ts index c27064573..178e53b2f 100644 --- a/src/react/context/types.ts +++ b/src/react/context/types.ts @@ -71,6 +71,9 @@ export interface EscolaLMSContextReadConfig { webinars: ContextListState; tutorConsultations: ContextPaginatedMetaState; events: ContextPaginatedMetaState; + webinar: ContextStateValue; + stationaryEvent: ContextStateValue; + userWebinars: ContextListState; } export interface EscolaLMSContextAPIConfig { @@ -133,9 +136,10 @@ export interface EscolaLMSContextAPIConfig { fetchTutorConsultations: () => Promise; approveConsultationTerm: (consultation: number) => Promise; rejectConsultationTerm: (consultation: number) => Promise; - generateJitsyMeeting: (consultation: number) => Promise>; + generateConsultationJitsy: (consultation: number) => Promise>; + generateWebinarJitsy: (webinarId: number) => Promise>; + fetchUserWebinars: () => Promise; } - export type EscolaLMSContextConfig = EscolaLMSContextReadConfig & EscolaLMSContextAPIConfig; export type SortProgram = (lessons: API.Lesson[]) => API.Lesson[]; diff --git a/src/services/stationary_events.ts b/src/services/stationary_events.ts index d774b532a..eb507b109 100644 --- a/src/services/stationary_events.ts +++ b/src/services/stationary_events.ts @@ -1,6 +1,6 @@ -import request from 'umi-request'; -import type { RequestOptionsInit } from 'umi-request'; -import * as API from '../types/api'; +import request from "umi-request"; +import type { RequestOptionsInit } from "umi-request"; +import * as API from "../types/api"; /** GET /api/stationary-events */ export async function stationaryEvents( @@ -8,8 +8,16 @@ export async function stationaryEvents( options?: RequestOptionsInit, ) { return request(`/api/stationary-events`, { - method: 'GET', + method: "GET", params, ...(options || {}), }); } + +/** GET /api/stationary-events/:id */ +export async function getStationaryEvent(id: number, options?: { [key: string]: any }) { + return request>(`/api/stationary-events/${id}`, { + method: "GET", + ...(options || {}), + }); +} diff --git a/src/services/webinars.ts b/src/services/webinars.ts index ec265d6c1..ae9cb6633 100644 --- a/src/services/webinars.ts +++ b/src/services/webinars.ts @@ -1,10 +1,10 @@ -import request from 'umi-request'; -import * as API from '../types/api'; +import request from "umi-request"; +import * as API from "../types/api"; /** GET /api/webinars */ export async function webinars(params: API.WebinarParams, options?: { [key: string]: any }) { return request(`/api/webinars`, { - method: 'GET', + method: "GET", params, ...(options || {}), }); @@ -13,7 +13,31 @@ export async function webinars(params: API.WebinarParams, options?: { [key: stri /** GET /api/webinars/:id */ export async function getWebinar(id: number, options?: { [key: string]: any }) { return request>(`/api/webinars/${id}`, { - method: 'GET', + method: "GET", ...(options || {}), }); } + +/** GET /api/webinars/me */ +export async function getMyWebinars(token: string) { + return request(`/api/webinars/me`, { + method: "GET", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); +} + +/** GET /api/webinars/generate-jitsi*/ +export async function genereteJitsyWebinar(token: string, id: number) { + return request>(`/api/webinars/generate-jitsi/${id}`, { + method: "GET", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); +} diff --git a/src/types/api.ts b/src/types/api.ts index f25c9b345..8233b84b3 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -239,14 +239,15 @@ export type Consultation = EscolaLms.Consultations.Models.Consultation & { product?: Product; executed_status?: null | "reported" | "not_reported" | "reject" | "approved"; executed_at?: string; - consultation_user_id?: number; + consultation_term_id?: number; is_ended?: boolean; is_started?: boolean; + in_coming?: boolean; author: User & { categories: Category[] }; }; export type Product = EscolaLms.Cart.Models.Product & { buyable?: boolean }; -export type Webinar = EscolaLms.Webinar.Models.Webinar & { product?: Product }; +export type Webinar = EscolaLms.Webinar.Models.Webinar & { product?: Product; program?: string }; export type CartProductParameters = { description: string; @@ -373,21 +374,21 @@ export type User = { data: UserItem; }; -export type UserItem = { - id: number; - name: string; - first_name: string; - last_name: string; - email: string; - is_active: boolean; - created_at: string; - onboarding_completed: boolean; - email_verified: boolean; - interests: string[]; - avatar: string; - path_avatar: string | null; - bio: string | null; - roles?: string[]; +export type UserItem = EscolaLms.Auth.Models.User & { + // id: number; + // name: string; + // first_name: string; + // last_name: string; + // email: string; + // is_active: boolean; + // created_at: string; + // onboarding_completed: boolean; + // email_verified: boolean; + // interests: string[]; + avatar?: string; + // path_avatar: string | null; + bio?: string | null; + // roles?: string[]; }; export type Lesson = { @@ -624,6 +625,7 @@ export type StationaryEvent = EscolaLms.StationaryEvents.Models.StationaryEvent title?: string; isScheduled?: boolean; appointmentDate?: string; + product?: Product | null; }; export type Event = { @@ -652,6 +654,10 @@ export type Event = { trainers?: EscolaLms.Auth.Models.User[] | null; tags?: EscolaLms.Tags.Models.Tag[] | null; yt_url?: string | null; + model?: string; + in_coming?: boolean; + is_ended?: boolean; + is_started?: boolean; }; export type SCORM = { @@ -967,4 +973,5 @@ export type AppointmentTerm = { user: UserItem & Record; is_started?: boolean; is_ended?: boolean; + in_coming?: boolean; };