diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 41e3b90886..291416f828 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -33,7 +33,7 @@ jobs: - name: Count number of lines run: | chmod +x ./.github/workflows/countline.py - ./.github/workflows/countline.py --lines 1000 --exclude_files src/screens/LoginPage/LoginPage.tsx + ./.github/workflows/countline.py --lines 600 --exclude_files src/screens/LoginPage/LoginPage.tsx - name: Get changed TypeScript files id: changed-files diff --git a/src/GraphQl/Mutations/CommentMutations.ts b/src/GraphQl/Mutations/CommentMutations.ts new file mode 100644 index 0000000000..7a2ca00c83 --- /dev/null +++ b/src/GraphQl/Mutations/CommentMutations.ts @@ -0,0 +1,58 @@ +import gql from 'graphql-tag'; + +/** + * GraphQL mutation to create a new comment on a post. + * + * @param comment - The text content of the comment. + * @param postId - The ID of the post to which the comment is being added. + * @returns The created comment object. + */ + +export const CREATE_COMMENT_POST = gql` + mutation createComment($comment: String!, $postId: ID!) { + createComment(data: { text: $comment }, postId: $postId) { + _id + creator { + _id + firstName + lastName + email + } + likeCount + likedBy { + _id + } + text + } + } +`; + +/** + * GraphQL mutation to like a comment. + * + * @param commentId - The ID of the comment to be liked. + * @returns The liked comment object. + */ + +export const LIKE_COMMENT = gql` + mutation likeComment($commentId: ID!) { + likeComment(id: $commentId) { + _id + } + } +`; + +/** + * GraphQL mutation to unlike a comment. + * + * @param commentId - The ID of the comment to be unliked. + * @returns The unliked comment object. + */ + +export const UNLIKE_COMMENT = gql` + mutation unlikeComment($commentId: ID!) { + unlikeComment(id: $commentId) { + _id + } + } +`; diff --git a/src/GraphQl/Mutations/EventAttendeeMutations.ts b/src/GraphQl/Mutations/EventAttendeeMutations.ts new file mode 100644 index 0000000000..345a8cb1cb --- /dev/null +++ b/src/GraphQl/Mutations/EventAttendeeMutations.ts @@ -0,0 +1,63 @@ +import gql from 'graphql-tag'; + +/** + * GraphQL mutation to add an attendee to an event. + * + * @param userId - The ID of the user being added as an attendee. + * @param eventId - The ID of the event to which the user is being added as an attendee. + * @returns The updated event object with the added attendee. + */ + +export const ADD_EVENT_ATTENDEE = gql` + mutation addEventAttendee($userId: ID!, $eventId: ID!) { + addEventAttendee(data: { userId: $userId, eventId: $eventId }) { + _id + } + } +`; + +/** + * GraphQL mutation to remove an attendee from an event. + * + * @param userId - The ID of the user being removed as an attendee. + * @param eventId - The ID of the event from which the user is being removed as an attendee. + * @returns The updated event object without the removed attendee. + */ + +export const REMOVE_EVENT_ATTENDEE = gql` + mutation removeEventAttendee($userId: ID!, $eventId: ID!) { + removeEventAttendee(data: { userId: $userId, eventId: $eventId }) { + _id + } + } +`; + +/** + * GraphQL mutation to mark a user's check-in at an event. + * + * @param userId - The ID of the user checking in. + * @param eventId - The ID of the event at which the user is checking in. + * @param allotedRoom - The room assigned to the user during check-in (optional). + * @param allotedSeat - The seat assigned to the user during check-in (optional). + * @returns The updated event object with the user's check-in information. + */ + +export const MARK_CHECKIN = gql` + mutation checkIn( + $userId: ID! + $eventId: ID! + $allotedRoom: String + $allotedSeat: String + ) { + checkIn( + data: { + userId: $userId + eventId: $eventId + allotedRoom: $allotedRoom + allotedSeat: $allotedSeat + } + ) { + _id + } + } +`; diff --git a/src/GraphQl/Mutations/EventTaskMutations.ts b/src/GraphQl/Mutations/EventTaskMutations.ts new file mode 100644 index 0000000000..d7c784f8ab --- /dev/null +++ b/src/GraphQl/Mutations/EventTaskMutations.ts @@ -0,0 +1,65 @@ +import gql from 'graphql-tag'; + +/** + * GraphQL mutation to update an event project task. + * + * @param title - The updated title of the task. + * @param description - The updated description of the task. + * @param taskId - The ID of the task to be updated. + * @param deadline - The updated deadline for the task. + * @param completed - The updated completion status of the task. + * @returns The updated task object. + */ + +export const UPDATE_EVENT_PROJECT_TASK_MUTATION = gql` + mutation UpdateEventTask( + $title: String! + $description: String! + $taskId: ID! + $deadline: DateTime! + $completed: Boolean! + ) { + updateTask( + id: $taskId + data: { + title: $title + description: $description + deadline: $deadline + completed: $completed + } + ) { + _id + } + } +`; + +/** + * GraphQL mutation to delete an event project task. + * + * @param id - The ID of the task to be deleted. + * @returns The deleted task object. + */ + +export const DELETE_EVENT_TASK_MUTATION = gql` + mutation DeleteTask($id: ID!) { + removeTask(id: $id) { + _id + } + } +`; + +/** + * GraphQL mutation to set volunteers for an event project task. + * + * @param id - The ID of the task for which volunteers are being set. + * @param volunteers - An array of user IDs representing the volunteers for the task. + * @returns The updated task object with the assigned volunteers. + */ + +export const SET_TASK_VOLUNTEERS_MUTATION = gql` + mutation SetTaskVolunteers($id: ID!, $volunteers: [ID]!) { + setTaskVolunteers(id: $id, volunteers: $volunteers) { + _id + } + } +`; diff --git a/src/GraphQl/Mutations/OrganizationMutations.ts b/src/GraphQl/Mutations/OrganizationMutations.ts new file mode 100644 index 0000000000..70c568068a --- /dev/null +++ b/src/GraphQl/Mutations/OrganizationMutations.ts @@ -0,0 +1,145 @@ +import gql from 'graphql-tag'; + +// Changes the role of a user in an organization +/** + * GraphQL mutation to update the role of a user in an organization. + * + * @param organizationId - The ID of the organization in which the user's role is being updated. + * @param userId - The ID of the user whose role is being updated. + * @param role - The new role to be assigned to the user in the organization. + * @returns The updated user object with the new role in the organization. + */ +export const UPDATE_USER_ROLE_IN_ORG_MUTATION = gql` + mutation updateUserRoleInOrganization( + $organizationId: ID! + $userId: ID! + $role: String! + ) { + updateUserRoleInOrganization( + organizationId: $organizationId + userId: $userId + role: $role + ) { + _id + } + } +`; + +/** + * GraphQL mutation to create a sample organization. + * + * @returns The created sample organization object. + */ + +export const CREATE_SAMPLE_ORGANIZATION_MUTATION = gql` + mutation { + createSampleOrganization + } +`; + +/** + * GraphQL mutation to remove a sample organization. + * + * @returns The removed sample organization object. + */ + +export const REMOVE_SAMPLE_ORGANIZATION_MUTATION = gql` + mutation { + removeSampleOrganization + } +`; + +/** + * GraphQL mutation to create a direct chat between users in an organization. + * + * @param userIds - An array of user IDs participating in the direct chat. + * @param organizationId - The ID of the organization where the direct chat is created. + * @returns The created direct chat object. + */ + +export const CREATE_DIRECT_CHAT = gql` + mutation createDirectChat($userIds: [ID!]!, $organizationId: ID!) { + createDirectChat( + data: { userIds: $userIds, organizationId: $organizationId } + ) { + _id + } + } +`; +//Plugin WebSocket listner + +/** + * GraphQL subscription to listen for updates on plugins. + * + * @returns An object containing information about the updated plugin. + */ + +export const PLUGIN_SUBSCRIPTION = gql` + subscription onPluginUpdate { + onPluginUpdate { + pluginName + _id + pluginDesc + uninstalledOrgs + } + } +`; + +/** + * GraphQL mutation to toggle the pinned status of a post. + * + * @param id - The ID of the post to be toggled. + * @returns The updated post object with the new pinned status. + */ + +export const TOGGLE_PINNED_POST = gql` + mutation TogglePostPin($id: ID!) { + togglePostPin(id: $id) { + _id + } + } +`; + +/** + * GraphQL mutation to add a custom field to an organization. + * + * @param organizationId - The ID of the organization where the custom field is being added. + * @param type - The type of the custom field (e.g., String, Number). + * @param name - The name of the custom field. + * @returns The added organization custom field object. + */ + +export const ADD_CUSTOM_FIELD = gql` + mutation ($organizationId: ID!, $type: String!, $name: String!) { + addOrganizationCustomField( + organizationId: $organizationId + type: $type + name: $name + ) { + name + type + } + } +`; + +// Handles custom organization fields + +/** + * GraphQL mutation to remove a custom field from an organization. + * + * @param organizationId - The ID of the organization from which the custom field is being removed. + * @param customFieldId - The ID of the custom field to be removed. + * @returns The removed organization custom field object. + */ + +export const REMOVE_CUSTOM_FIELD = gql` + mutation ($organizationId: ID!, $customFieldId: ID!) { + removeOrganizationCustomField( + organizationId: $organizationId + customFieldId: $customFieldId + ) { + type + name + } + } +`; diff --git a/src/GraphQl/Mutations/mutations.ts b/src/GraphQl/Mutations/mutations.ts index 00c6892a8c..455fe4c8cd 100644 --- a/src/GraphQl/Mutations/mutations.ts +++ b/src/GraphQl/Mutations/mutations.ts @@ -1,9 +1,5 @@ import gql from 'graphql-tag'; -// List of the mutations used in the code - -// to unblock the user - export const UNBLOCK_USER_MUTATION = gql` mutation UnblockUser($userId: ID!, $orgId: ID!) { unblockUser(organizationId: $orgId, userId: $userId) { @@ -576,196 +572,27 @@ export const ADD_EVENT_PROJECT_TASK_MUTATION = gql` } } `; +// Changes the role of a event in an organization and add and remove the event from the organization +export { UPDATE_EVENT_PROJECT_TASK_MUTATION } from './EventTaskMutations'; +export { DELETE_EVENT_TASK_MUTATION } from './EventTaskMutations'; +export { SET_TASK_VOLUNTEERS_MUTATION } from './EventTaskMutations'; -export const UPDATE_EVENT_PROJECT_TASK_MUTATION = gql` - mutation UpdateEventTask( - $title: String! - $description: String! - $taskId: ID! - $deadline: DateTime! - $completed: Boolean! - ) { - updateTask( - id: $taskId - data: { - title: $title - description: $description - deadline: $deadline - completed: $completed - } - ) { - _id - } - } -`; - -export const DELETE_EVENT_TASK_MUTATION = gql` - mutation DeleteTask($id: ID!) { - removeTask(id: $id) { - _id - } - } -`; - -export const SET_TASK_VOLUNTEERS_MUTATION = gql` - mutation SetTaskVolunteers($id: ID!, $volunteers: [ID]!) { - setTaskVolunteers(id: $id, volunteers: $volunteers) { - _id - } - } -`; - -export const ADD_EVENT_ATTENDEE = gql` - mutation addEventAttendee($userId: ID!, $eventId: ID!) { - addEventAttendee(data: { userId: $userId, eventId: $eventId }) { - _id - } - } -`; - -export const REMOVE_EVENT_ATTENDEE = gql` - mutation removeEventAttendee($userId: ID!, $eventId: ID!) { - removeEventAttendee(data: { userId: $userId, eventId: $eventId }) { - _id - } - } -`; - -export const MARK_CHECKIN = gql` - mutation checkIn( - $userId: ID! - $eventId: ID! - $allotedRoom: String - $allotedSeat: String - ) { - checkIn( - data: { - userId: $userId - eventId: $eventId - allotedRoom: $allotedRoom - allotedSeat: $allotedSeat - } - ) { - _id - } - } -`; - -export const CREATE_COMMENT_POST = gql` - mutation createComment($comment: String!, $postId: ID!) { - createComment(data: { text: $comment }, postId: $postId) { - _id - creator { - _id - firstName - lastName - email - } - likeCount - likedBy { - _id - } - text - } - } -`; - -export const LIKE_COMMENT = gql` - mutation likeComment($commentId: ID!) { - likeComment(id: $commentId) { - _id - } - } -`; +// Changes the role of a event in an organization and add and remove the event from the organization +export { ADD_EVENT_ATTENDEE } from './EventAttendeeMutations'; +export { REMOVE_EVENT_ATTENDEE } from './EventAttendeeMutations'; +export { MARK_CHECKIN } from './EventAttendeeMutations'; -export const UNLIKE_COMMENT = gql` - mutation unlikeComment($commentId: ID!) { - unlikeComment(id: $commentId) { - _id - } - } -`; +// Create the new comment on a post and Like and Unlike the comment +export { CREATE_COMMENT_POST } from './CommentMutations'; +export { LIKE_COMMENT } from './CommentMutations'; +export { UNLIKE_COMMENT } from './CommentMutations'; // Changes the role of a user in an organization -export const UPDATE_USER_ROLE_IN_ORG_MUTATION = gql` - mutation updateUserRoleInOrganization( - $organizationId: ID! - $userId: ID! - $role: String! - ) { - updateUserRoleInOrganization( - organizationId: $organizationId - userId: $userId - role: $role - ) { - _id - } - } -`; - -export const CREATE_SAMPLE_ORGANIZATION_MUTATION = gql` - mutation { - createSampleOrganization - } -`; - -export const REMOVE_SAMPLE_ORGANIZATION_MUTATION = gql` - mutation { - removeSampleOrganization - } -`; - -export const CREATE_DIRECT_CHAT = gql` - mutation createDirectChat($userIds: [ID!]!, $organizationId: ID!) { - createDirectChat( - data: { userIds: $userIds, organizationId: $organizationId } - ) { - _id - } - } -`; - -//Plugin WebSocket listner -export const PLUGIN_SUBSCRIPTION = gql` - subscription onPluginUpdate { - onPluginUpdate { - pluginName - _id - pluginDesc - uninstalledOrgs - } - } -`; -export const TOGGLE_PINNED_POST = gql` - mutation TogglePostPin($id: ID!) { - togglePostPin(id: $id) { - _id - } - } -`; - -// Handles custom organization fields -export const ADD_CUSTOM_FIELD = gql` - mutation ($organizationId: ID!, $type: String!, $name: String!) { - addOrganizationCustomField( - organizationId: $organizationId - type: $type - name: $name - ) { - name - type - } - } -`; - -export const REMOVE_CUSTOM_FIELD = gql` - mutation ($organizationId: ID!, $customFieldId: ID!) { - removeOrganizationCustomField( - organizationId: $organizationId - customFieldId: $customFieldId - ) { - type - name - } - } -`; +export { UPDATE_USER_ROLE_IN_ORG_MUTATION } from './OrganizationMutations'; +export { CREATE_SAMPLE_ORGANIZATION_MUTATION } from './OrganizationMutations'; +export { REMOVE_SAMPLE_ORGANIZATION_MUTATION } from './OrganizationMutations'; +export { CREATE_DIRECT_CHAT } from './OrganizationMutations'; +export { PLUGIN_SUBSCRIPTION } from './OrganizationMutations'; +export { TOGGLE_PINNED_POST } from './OrganizationMutations'; +export { ADD_CUSTOM_FIELD } from './OrganizationMutations'; +export { REMOVE_CUSTOM_FIELD } from './OrganizationMutations'; diff --git a/src/GraphQl/Queries/OrganizationQueries.ts b/src/GraphQl/Queries/OrganizationQueries.ts new file mode 100644 index 0000000000..97a69d5175 --- /dev/null +++ b/src/GraphQl/Queries/OrganizationQueries.ts @@ -0,0 +1,188 @@ +// OrganizationQueries.js +import gql from 'graphql-tag'; + +// display posts + +/** + * GraphQL query to retrieve posts by organization. + * + * @param id - The ID of the organization for which posts are being retrieved. + * @returns The list of posts associated with the organization. + */ + +export const ORGANIZATION_POST_LIST = gql` + query PostsByOrganization($id: ID!) { + postsByOrganization(id: $id) { + _id + title + text + imageUrl + videoUrl + creator { + _id + firstName + lastName + email + } + createdAt + } + } +`; + +/** + * GraphQL query to retrieve posts by organization with additional filtering options. + * + * @param id - The ID of the organization for which posts are being retrieved. + * @param title_contains - Optional. Filter posts by title containing a specified string. + * @param text_contains - Optional. Filter posts by text containing a specified string. + * @returns The list of posts associated with the organization based on the applied filters. + */ + +export const ORGANIZATION_POST_CONNECTION_LIST = gql` + query PostsByOrganizationConnection( + $id: ID! + $title_contains: String + $text_contains: String + ) { + postsByOrganizationConnection( + id: $id + where: { title_contains: $title_contains, text_contains: $text_contains } + orderBy: createdAt_DESC + ) { + edges { + _id + title + text + imageUrl + videoUrl + creator { + _id + firstName + lastName + email + } + createdAt + likeCount + commentCount + comments { + _id + creator { + _id + firstName + lastName + email + } + likeCount + likedBy { + _id + } + text + } + likedBy { + _id + firstName + lastName + } + pinned + } + } + } +`; + +/** + * GraphQL query to retrieve organizations based on user connection. + * + * @param first - Optional. Number of organizations to retrieve in the first batch. + * @param skip - Optional. Number of organizations to skip before starting to collect the result set. + * @param filter - Optional. Filter organizations by a specified string. + * @param id - Optional. The ID of a specific organization to retrieve. + * @returns The list of organizations based on the applied filters. + */ + +export const USER_ORGANIZATION_CONNECTION = gql` + query organizationsConnection( + $first: Int + $skip: Int + $filter: String + $id: ID + ) { + organizationsConnection( + first: $first + skip: $skip + where: { name_contains: $filter, id: $id } + orderBy: name_ASC + ) { + _id + name + image + description + userRegistrationRequired + creator { + firstName + lastName + } + } + } +`; + +/** + * GraphQL query to retrieve organizations joined by a user. + * + * @param id - The ID of the user for which joined organizations are being retrieved. + * @returns The list of organizations joined by the user. + */ + +export const USER_JOINED_ORGANIZATIONS = gql` + query UserJoinedOrganizations($id: ID!) { + users(where: { id: $id }) { + joinedOrganizations { + _id + name + description + image + } + } + } +`; + +/** + * GraphQL query to retrieve organizations created by a user. + * + * @param id - The ID of the user for which created organizations are being retrieved. + * @returns The list of organizations created by the user. + */ + +export const USER_CREATED_ORGANIZATIONS = gql` + query UserJoinedOrganizations($id: ID!) { + users(where: { id: $id }) { + createdOrganizations { + _id + name + description + image + } + } + } +`; + +/** + * GraphQL query to retrieve the list of admins for a specific organization. + * + * @param id - The ID of the organization for which admins are being retrieved. + * @returns The list of admins associated with the organization. + */ + +export const ORGANIZATION_ADMINS_LIST = gql` + query Organizations($id: ID!) { + organizations(id: $id) { + _id + admins { + _id + image + firstName + lastName + email + } + } + } +`; diff --git a/src/GraphQl/Queries/PlugInQueries.ts b/src/GraphQl/Queries/PlugInQueries.ts new file mode 100644 index 0000000000..b3f671a3a0 --- /dev/null +++ b/src/GraphQl/Queries/PlugInQueries.ts @@ -0,0 +1,216 @@ +import gql from 'graphql-tag'; + +/** + * GraphQL query to retrieve a list of plugins. + * + * @returns The list of plugins with details such as ID, name, creator, description, and uninstalled organizations. + */ + +export const PLUGIN_GET = gql` + query getPluginList { + getPlugins { + _id + pluginName + pluginCreatedBy + pluginDesc + uninstalledOrgs + } + } +`; + +/** + * GraphQL query to retrieve a list of advertisements. + * + * @returns The list of advertisements with details such as ID, name, type, organization ID, link, start date, and end date. + */ + +export const ADVERTISEMENTS_GET = gql` + query getAdvertisement { + getAdvertisements { + _id + name + type + orgId + link + endDate + startDate + } + } +`; + +/** + * GraphQL query to retrieve a list of events based on organization connection. + * + * @param organization_id - The ID of the organization for which events are being retrieved. + * @param title_contains - Optional. Filter events by title containing a specified string. + * @param description_contains - Optional. Filter events by description containing a specified string. + * @param location_contains - Optional. Filter events by location containing a specified string. + * @param first - Optional. Number of events to retrieve in the first batch. + * @param skip - Optional. Number of events to skip before starting to collect the result set. + * @returns The list of events associated with the organization based on the applied filters. + */ + +export const ORGANIZATION_EVENTS_CONNECTION = gql` + query EventsByOrganizationConnection( + $organization_id: ID! + $title_contains: String + $description_contains: String + $location_contains: String + $first: Int + $skip: Int + ) { + eventsByOrganizationConnection( + where: { + organization_id: $organization_id + title_contains: $title_contains + description_contains: $description_contains + location_contains: $location_contains + } + first: $first + skip: $skip + ) { + _id + title + description + startDate + endDate + location + startTime + endTime + allDay + recurring + isPublic + isRegisterable + creator { + _id + firstName + lastName + } + attendees { + _id + } + } + } +`; + +/** + * GraphQL query to retrieve a list of tasks assigned to a user. + * + * @param id - The ID of the user for which assigned tasks are being retrieved. + * @returns The list of tasks assigned to the user with details such as ID, title, description, deadline, volunteers, creation date, completion status, associated event, and creator. + */ + +export const USER_TASKS_LIST = gql` + query User($id: ID!) { + user(id: $id) { + _id + assignedTasks { + _id + title + description + deadline + volunteers { + _id + firstName + lastName + email + } + createdAt + completed + event { + _id + title + organization { + _id + name + image + } + } + creator { + _id + firstName + lastName + } + } + } + } +`; + +/** + * GraphQL query to retrieve a list of direct chats based on user ID. + * + * @param id - The ID of the user for which direct chats are being retrieved. + * @returns The list of direct chats associated with the user, including details such as ID, creator, messages, organization, and participating users. + */ + +export const DIRECT_CHATS_LIST = gql` + query DirectChatsByUserID($id: ID!) { + directChatsByUserID(id: $id) { + _id + creator { + _id + firstName + lastName + email + } + messages { + _id + createdAt + messageContent + receiver { + _id + firstName + lastName + email + } + sender { + _id + firstName + lastName + email + } + } + organization { + _id + name + } + users { + _id + firstName + lastName + email + image + } + } + } +`; + +/** + * GraphQL query to check if an organization is a sample organization. + * + * @param isSampleOrganizationId - The ID of the organization being checked. + * @returns A boolean indicating whether the organization is a sample organization. + */ + +export const IS_SAMPLE_ORGANIZATION_QUERY = gql` + query ($isSampleOrganizationId: ID!) { + isSampleOrganization(id: $isSampleOrganizationId) + } +`; + +/** + * GraphQL query to retrieve custom fields for a specific organization. + * + * @param customFieldsByOrganizationId - The ID of the organization for which custom fields are being retrieved. + * @returns The list of custom fields associated with the organization, including details such as ID, type, and name. + */ + +export const ORGANIZATION_CUSTOM_FIELDS = gql` + query ($customFieldsByOrganizationId: ID!) { + customFieldsByOrganization(id: $customFieldsByOrganizationId) { + _id + type + name + } + } +`; diff --git a/src/GraphQl/Queries/Queries.ts b/src/GraphQl/Queries/Queries.ts index 3b3631336a..5fd02f8e72 100644 --- a/src/GraphQl/Queries/Queries.ts +++ b/src/GraphQl/Queries/Queries.ts @@ -1,7 +1,6 @@ import gql from 'graphql-tag'; //Query List - // Check Auth export const CHECK_AUTH = gql` @@ -557,307 +556,19 @@ export const MEMBERSHIP_REQUEST = gql` } `; -// display posts - -export const ORGANIZATION_POST_LIST = gql` - query PostsByOrganization($id: ID!) { - postsByOrganization(id: $id) { - _id - title - text - imageUrl - videoUrl - creator { - _id - firstName - lastName - email - } - createdAt - } - } -`; - -export const ORGANIZATION_POST_CONNECTION_LIST = gql` - query PostsByOrganizationConnection( - $id: ID! - $title_contains: String - $text_contains: String - ) { - postsByOrganizationConnection( - id: $id - where: { title_contains: $title_contains, text_contains: $text_contains } - orderBy: createdAt_DESC - ) { - edges { - _id - title - text - imageUrl - videoUrl - creator { - _id - firstName - lastName - email - } - createdAt - likeCount - commentCount - comments { - _id - creator { - _id - firstName - lastName - email - } - likeCount - likedBy { - _id - } - text - } - likedBy { - _id - firstName - lastName - } - pinned - } - } - } -`; - -export const USER_ORGANIZATION_CONNECTION = gql` - query organizationsConnection( - $first: Int - $skip: Int - $filter: String - $id: ID - ) { - organizationsConnection( - first: $first - skip: $skip - where: { name_contains: $filter, id: $id } - orderBy: name_ASC - ) { - _id - name - image - description - userRegistrationRequired - creator { - firstName - lastName - } - } - } -`; - -export const USER_JOINED_ORGANIZATIONS = gql` - query UserJoinedOrganizations($id: ID!) { - users(where: { id: $id }) { - joinedOrganizations { - _id - name - description - image - } - } - } -`; - -export const USER_CREATED_ORGANIZATIONS = gql` - query UserJoinedOrganizations($id: ID!) { - users(where: { id: $id }) { - createdOrganizations { - _id - name - description - image - } - } - } -`; - -export const ORGANIZATION_ADMINS_LIST = gql` - query Organizations($id: ID!) { - organizations(id: $id) { - _id - admins { - _id - image - firstName - lastName - email - } - } - } -`; - -/** - * {@label PLUGIN_GET} - * @remarks - * used to fetch list of plugins - */ -export const PLUGIN_GET = gql` - query getPluginList { - getPlugins { - _id - pluginName - pluginCreatedBy - pluginDesc - uninstalledOrgs - } - } -`; -export const ADVERTISEMENTS_GET = gql` - query getAdvertisement { - getAdvertisements { - _id - name - type - orgId - link - endDate - startDate - } - } -`; -export const ORGANIZATION_EVENTS_CONNECTION = gql` - query EventsByOrganizationConnection( - $organization_id: ID! - $title_contains: String - $description_contains: String - $location_contains: String - $first: Int - $skip: Int - ) { - eventsByOrganizationConnection( - where: { - organization_id: $organization_id - title_contains: $title_contains - description_contains: $description_contains - location_contains: $location_contains - } - first: $first - skip: $skip - ) { - _id - title - description - startDate - endDate - location - startTime - endTime - allDay - recurring - isPublic - isRegisterable - creator { - _id - firstName - lastName - } - attendees { - _id - } - } - } -`; - -export const USER_TASKS_LIST = gql` - query User($id: ID!) { - user(id: $id) { - _id - assignedTasks { - _id - title - description - deadline - volunteers { - _id - firstName - lastName - email - } - createdAt - completed - event { - _id - title - organization { - _id - name - image - } - } - creator { - _id - firstName - lastName - } - } - } - } -`; - -export const DIRECT_CHATS_LIST = gql` - query DirectChatsByUserID($id: ID!) { - directChatsByUserID(id: $id) { - _id - creator { - _id - firstName - lastName - email - } - messages { - _id - createdAt - messageContent - receiver { - _id - firstName - lastName - email - } - sender { - _id - firstName - lastName - email - } - } - organization { - _id - name - } - users { - _id - firstName - lastName - email - image - } - } - } -`; - -export const IS_SAMPLE_ORGANIZATION_QUERY = gql` - query ($isSampleOrganizationId: ID!) { - isSampleOrganization(id: $isSampleOrganizationId) - } -`; +// to take the list of the blocked users +export { PLUGIN_GET } from './PlugInQueries'; +export { ADVERTISEMENTS_GET } from './PlugInQueries'; +export { ORGANIZATION_EVENTS_CONNECTION } from './PlugInQueries'; +export { USER_TASKS_LIST } from './PlugInQueries'; +export { DIRECT_CHATS_LIST } from './PlugInQueries'; +export { IS_SAMPLE_ORGANIZATION_QUERY } from './PlugInQueries'; +export { ORGANIZATION_CUSTOM_FIELDS } from './PlugInQueries'; -export const ORGANIZATION_CUSTOM_FIELDS = gql` - query ($customFieldsByOrganizationId: ID!) { - customFieldsByOrganization(id: $customFieldsByOrganizationId) { - _id - type - name - } - } -`; +// display posts +export { ORGANIZATION_POST_LIST } from './OrganizationQueries'; +export { ORGANIZATION_POST_CONNECTION_LIST } from './OrganizationQueries'; +export { USER_ORGANIZATION_CONNECTION } from './OrganizationQueries'; +export { USER_JOINED_ORGANIZATIONS } from './OrganizationQueries'; +export { USER_CREATED_ORGANIZATIONS } from './OrganizationQueries'; +export { ORGANIZATION_ADMINS_LIST } from './OrganizationQueries'; diff --git a/src/screens/OrgList/OrgList.tsx b/src/screens/OrgList/OrgList.tsx index d303657082..f6923bebc0 100644 --- a/src/screens/OrgList/OrgList.tsx +++ b/src/screens/OrgList/OrgList.tsx @@ -14,14 +14,13 @@ import OrgListCard from 'components/OrgListCard/OrgListCard'; import SuperAdminScreen from 'components/SuperAdminScreen/SuperAdminScreen'; import type { ChangeEvent } from 'react'; import React, { useEffect, useState } from 'react'; -import { Col, Dropdown, Form, Row } from 'react-bootstrap'; +import { Dropdown, Form } from 'react-bootstrap'; import Button from 'react-bootstrap/Button'; import Modal from 'react-bootstrap/Modal'; import { useTranslation } from 'react-i18next'; import InfiniteScroll from 'react-infinite-scroll-component'; import { Link } from 'react-router-dom'; import { toast } from 'react-toastify'; -import convertToBase64 from 'utils/convertToBase64'; import { errorHandler } from 'utils/errorHandler'; import type { InterfaceOrgConnectionInfoType, @@ -29,6 +28,7 @@ import type { InterfaceUserType, } from 'utils/interfaces'; import styles from './OrgList.module.css'; +import OrganizationModal from './OrganizationModal'; function orgList(): JSX.Element { const { t } = useTranslation('translation', { keyPrefix: 'orgList' }); @@ -484,171 +484,29 @@ function orgList(): JSX.Element { )} {/* Create Organization Modal */} - - - - {t('createOrganization')} - - -
- - {t('name')} - { - const inputText = e.target.value; - if (inputText.length < 50) { - setFormState({ - ...formState, - name: e.target.value, - }); - } - }} - /> - {t('description')} - { - const descriptionText = e.target.value; - if (descriptionText.length < 200) { - setFormState({ - ...formState, - descrip: e.target.value, - }); - } - }} - /> - {t('location')} - { - const locationText = e.target.value; - if (locationText.length < 100) { - setFormState({ - ...formState, - location: e.target.value, - }); - } - }} - /> - - - - - {t('userRegistrationRequired')} - - - setFormState({ - ...formState, - userRegistrationRequired: - !formState.userRegistrationRequired, - }) - } - /> - - - - {t('visibleInSearch')} - - - setFormState({ - ...formState, - visible: !formState.visible, - }) - } - /> - - - {t('displayImage')} - => { - const target = e.target as HTMLInputElement; - const file = target.files && target.files[0]; - /* istanbul ignore else */ - if (file) - setFormState({ - ...formState, - image: await convertToBase64(file), - }); - }} - data-testid="organisationImage" - /> - - - -
-
- {t('OR')} -
- {userData && - ((userData.user.userType === 'ADMIN' && - userData.user.adminFor.length > 0) || - userData.user.userType === 'SUPERADMIN') && ( -
- -
- )} - -
-
-
{' '} + {/** + * Renders the `OrganizationModal` component. + * + * @param showModal - A boolean indicating whether the modal should be displayed. + * @param toggleModal - A function to toggle the visibility of the modal. + * @param formState - The state of the form in the organization modal. + * @param setFormState - A function to update the state of the form in the organization modal. + * @param createOrg - A function to handle the submission of the organization creation form. + * @param t - A translation function for localization. + * @param userData - Information about the current user. + * @param triggerCreateSampleOrg - A function to trigger the creation of a sample organization. + * @returns JSX element representing the `OrganizationModal`. + */} + {/* Plugin Notification Modal after Org is Created */} diff --git a/src/screens/OrgList/OrganizationModal.tsx b/src/screens/OrgList/OrganizationModal.tsx new file mode 100644 index 0000000000..5c1e608136 --- /dev/null +++ b/src/screens/OrgList/OrganizationModal.tsx @@ -0,0 +1,235 @@ +import React from 'react'; +import { Modal, Form, Row, Col, Button } from 'react-bootstrap'; +import convertToBase64 from 'utils/convertToBase64'; +import type { ChangeEvent } from 'react'; +import styles from './OrgList.module.css'; + +/** + * Represents the state of the form in the organization modal. + */ +interface InterfaceFormStateType { + name: string; + descrip: string; + userRegistrationRequired: boolean; + visible: boolean; + location: string; + image: string; +} + +/** + * Represents a user type. + */ +interface InterfaceUserType { + user: { + firstName: string; + lastName: string; + image: string | null; + email: string; + userType: string; + adminFor: { + _id: string; + name: string; + image: string | null; + }[]; + }; + // Add more properties if needed +} + +/** + * Represents the properties of the OrganizationModal component. + */ +interface InterfaceOrganizationModalProps { + showModal: boolean; + toggleModal: () => void; + formState: InterfaceFormStateType; + setFormState: (state: React.SetStateAction) => void; + createOrg: (e: ChangeEvent) => Promise; + t: (key: string) => string; + userData: InterfaceUserType | undefined; + triggerCreateSampleOrg: () => void; +} + +/** + * Represents the organization modal component. + */ + +const OrganizationModal: React.FC = ({ + showModal, + toggleModal, + formState, + setFormState, + createOrg, + t, + userData, + triggerCreateSampleOrg, +}) => { + return ( + + + + {t('createOrganization')} + + +
+ + {t('name')} + { + const inputText = e.target.value; + if (inputText.length < 50) { + setFormState({ + ...formState, + name: e.target.value, + }); + } + }} + /> + {t('description')} + { + const descriptionText = e.target.value; + if (descriptionText.length < 200) { + setFormState({ + ...formState, + descrip: e.target.value, + }); + } + }} + /> + {t('location')} + { + const locationText = e.target.value; + if (locationText.length < 100) { + setFormState({ + ...formState, + location: e.target.value, + }); + } + }} + /> + + + + + {t('userRegistrationRequired')} + + + setFormState({ + ...formState, + userRegistrationRequired: + !formState.userRegistrationRequired, + }) + } + /> + + + + {t('visibleInSearch')} + + + setFormState({ + ...formState, + visible: !formState.visible, + }) + } + /> + + + {t('displayImage')} + => { + const target = e.target as HTMLInputElement; + const file = target.files && target.files[0]; + /* istanbul ignore else */ + if (file) + setFormState({ + ...formState, + image: await convertToBase64(file), + }); + }} + data-testid="organisationImage" + /> + + + +
+
+ {t('OR')} +
+ {userData && + ((userData.user.userType === 'ADMIN' && + userData.user.adminFor.length > 0) || + userData.user.userType === 'SUPERADMIN') && ( +
+ +
+ )} + +
+
+
+ ); +}; + +export default OrganizationModal;