@overmap-ai/core 1.0.30 → 1.0.31-display-invited-projects.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2688,6 +2688,13 @@ const projectSlice = createSlice({
2688
2688
  deleteProject: (state, action) => {
2689
2689
  delete state.projects[action.payload.id];
2690
2690
  state.recentProjectIds = state.recentProjectIds.filter((id) => id !== action.payload.id);
2691
+ },
2692
+ acceptProjectInvite: (state, action) => {
2693
+ if (action.payload in state.projects) {
2694
+ state.projects[action.payload].invited = false;
2695
+ } else {
2696
+ throw new Error("Accept project invite: user is not in this project");
2697
+ }
2691
2698
  }
2692
2699
  }
2693
2700
  });
@@ -2697,7 +2704,8 @@ const {
2697
2704
  updateOrCreateProjects: addOrReplaceProjects,
2698
2705
  setActiveProjectId,
2699
2706
  setCreateProjectType,
2700
- deleteProject
2707
+ deleteProject,
2708
+ acceptProjectInvite
2701
2709
  } = projectSlice.actions;
2702
2710
  const selectProjects = (state) => state.projectReducer.projects;
2703
2711
  const selectActiveProjectId = (state) => state.projectReducer.activeProjectId;
@@ -2721,6 +2729,10 @@ const selectProjectUsersAsMapping = createSelector(
2721
2729
  [selectProjectUsersIds, selectUsersAsMapping],
2722
2730
  (projectUserIds, users) => projectUserIds.reduce((accum, userId) => ({ ...accum, [userId]: users[userId] }), {})
2723
2731
  );
2732
+ const selectProjectsWithAccess = createSelector(
2733
+ [selectProjects],
2734
+ (projects) => Object.values(projects).filter((project) => !project.invited)
2735
+ );
2724
2736
  const selectSortedProjectUsers = createSelector(
2725
2737
  [selectCurrentUser, selectProjectUsersAsMapping, selectProjectAccessUserMapping],
2726
2738
  (currentUser, userMapping, projectAccessMapping) => {
@@ -4855,14 +4867,16 @@ class MainService extends BaseApiService {
4855
4867
  // Don't accept updateStore in ComponentService.list. Just return the offline objects and promise. Here, if
4856
4868
  // overwrite, use setComponents. Otherwise, use bulkAddComponents.
4857
4869
  async _processInitialData(data, overwrite) {
4858
- var _a2, _b;
4870
+ var _a2, _b, _c;
4859
4871
  const workspaces = {};
4860
4872
  const projects = [];
4861
4873
  const categories = [];
4862
4874
  const projectsData = data.projects;
4863
4875
  const { store } = this.client;
4864
- const oldProjectId = store.getState().projectReducer.activeProjectId;
4865
- let currentProjectId = oldProjectId ?? ((_a2 = projectsData[0]) == null ? void 0 : _a2.id);
4876
+ const oldProjectId = (_a2 = projectsData.find(
4877
+ (projectData) => projectData.id === store.getState().projectReducer.activeProjectId && !projectData.invited
4878
+ )) == null ? void 0 : _a2.id;
4879
+ let currentProjectId = oldProjectId ?? ((_b = projectsData.find((projectData) => !projectData.invited)) == null ? void 0 : _b.id);
4866
4880
  store.dispatch(setActiveProjectId(currentProjectId ?? null));
4867
4881
  let isProjectIdValid = false;
4868
4882
  for (const projectData of projectsData) {
@@ -4871,9 +4885,10 @@ class MainService extends BaseApiService {
4871
4885
  name: projectData.name,
4872
4886
  owner_organization: projectData.organization_owner,
4873
4887
  owner_user: projectData.user_owner,
4874
- bounds: projectData.bounds
4888
+ bounds: projectData.bounds,
4889
+ invited: projectData.invited || false
4875
4890
  });
4876
- if (currentProjectId === projectData.id) {
4891
+ if (currentProjectId === projectData.id && !projectData.invited) {
4877
4892
  isProjectIdValid = true;
4878
4893
  for (const workspaceData of projectData.workspaces) {
4879
4894
  const workspace = { ...workspaceData, project: projectData.id };
@@ -4890,6 +4905,7 @@ class MainService extends BaseApiService {
4890
4905
  store.dispatch(setCurrentUser(data.user));
4891
4906
  const organizationsData = data.organizations;
4892
4907
  store.dispatch(setOrganizations(organizationsData));
4908
+ const validProjects = projects.filter((project) => !project.invited);
4893
4909
  const firstOrg = organizationsData[0];
4894
4910
  const currProjObj = projects.find((project) => project.id === currentProjectId);
4895
4911
  const isOrgProject = !!(currProjObj == null ? void 0 : currProjObj.owner_organization);
@@ -4909,19 +4925,21 @@ class MainService extends BaseApiService {
4909
4925
  store.dispatch(addUsers(orgUsersResult));
4910
4926
  }
4911
4927
  if (!isProjectIdValid) {
4912
- if (projects.length !== 0) {
4913
- currentProjectId = projects[0].id;
4928
+ if (validProjects.length !== 0) {
4929
+ currentProjectId = validProjects[0].id;
4914
4930
  store.dispatch(setActiveProjectId(currentProjectId));
4915
- const projectData = projectsData[0];
4916
- for (const workspaceData of projectData.workspaces) {
4917
- const workspace = { ...workspaceData, project: projectData.id };
4918
- if (workspace.categories) {
4919
- for (const category of workspace.categories) {
4920
- categories.push(category);
4931
+ const projectData = projectsData.find((projectData2) => projectData2.id === currentProjectId);
4932
+ if (projectData) {
4933
+ for (const workspaceData of projectData.workspaces) {
4934
+ const workspace = { ...workspaceData, project: projectData.id };
4935
+ if (workspace.categories) {
4936
+ for (const category of workspace.categories) {
4937
+ categories.push(category);
4938
+ }
4921
4939
  }
4940
+ delete workspace.categories;
4941
+ workspaces[workspace.offline_id] = workspace;
4922
4942
  }
4923
- delete workspace.categories;
4924
- workspaces[workspace.offline_id] = workspace;
4925
4943
  }
4926
4944
  } else {
4927
4945
  currentProjectId = null;
@@ -4938,7 +4956,7 @@ class MainService extends BaseApiService {
4938
4956
  let currentWorkspaceId;
4939
4957
  const oldWorkspaceId = this.client.store.getState().workspaceReducer.activeWorkspaceId;
4940
4958
  if (overwrite || !oldWorkspaceId) {
4941
- currentWorkspaceId = (_b = Object.values(workspaces).at(0)) == null ? void 0 : _b.offline_id;
4959
+ currentWorkspaceId = (_c = Object.values(workspaces).at(0)) == null ? void 0 : _c.offline_id;
4942
4960
  } else {
4943
4961
  currentWorkspaceId = oldWorkspaceId;
4944
4962
  }
@@ -5249,6 +5267,17 @@ class ProjectService extends BaseApiService {
5249
5267
  blocks: []
5250
5268
  });
5251
5269
  }
5270
+ async acceptInvite(projectId) {
5271
+ return this.enqueueRequest({
5272
+ description: "Accept project invite",
5273
+ method: HttpMethod.PATCH,
5274
+ url: `/projects/${projectId}/accept-invite/`,
5275
+ blockers: [projectId.toString()],
5276
+ blocks: [projectId.toString()]
5277
+ }).then(() => {
5278
+ this.client.store.dispatch(acceptProjectInvite(projectId));
5279
+ });
5280
+ }
5252
5281
  }
5253
5282
  class UserFormService extends BaseApiService {
5254
5283
  add(state, initialRevision, url, ownerUser, ownerOrganization) {
@@ -10711,6 +10740,7 @@ export {
10711
10740
  WorkspaceService,
10712
10741
  YELLOW,
10713
10742
  _setLatestRetryTime,
10743
+ acceptProjectInvite,
10714
10744
  addAttachment,
10715
10745
  addAttachments,
10716
10746
  addCategory,
@@ -10959,6 +10989,7 @@ export {
10959
10989
  selectProjectUsersAsMapping,
10960
10990
  selectProjectUsersIds,
10961
10991
  selectProjects,
10992
+ selectProjectsWithAccess,
10962
10993
  selectRecentIssueIds,
10963
10994
  selectRecentIssuesAsSearchResults,
10964
10995
  selectRecentProjects,