@overmap-ai/core 1.0.31-org-switcher-and-bug-fixes.0 → 1.0.31

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.
@@ -2354,7 +2354,8 @@ var __publicField = (obj, key, value) => {
2354
2354
  const selectFavouriteProjects = (state) => state.userReducer.currentUser.profile.favourite_project_ids;
2355
2355
  const userReducer = userSlice.reducer;
2356
2356
  const initialState$a = {
2357
- organizationAccesses: {}
2357
+ organizationAccesses: {},
2358
+ activeOrganizationAccessId: null
2358
2359
  };
2359
2360
  const organizationAccessSlice = toolkit.createSlice({
2360
2361
  name: "organizationAccess",
@@ -2390,28 +2391,31 @@ var __publicField = (obj, key, value) => {
2390
2391
  `Tried to remove organization access with ID that doesn't exist: ${action.payload.offline_id}`
2391
2392
  );
2392
2393
  }
2394
+ },
2395
+ setActiveOrganizationAccessId: (state, action) => {
2396
+ state.activeOrganizationAccessId = action.payload;
2393
2397
  }
2394
2398
  }
2395
2399
  });
2396
- const { setOrganizationAccesses, updateOrganizationAccess, removeOrganizationAccess } = organizationAccessSlice.actions;
2400
+ const {
2401
+ setOrganizationAccesses,
2402
+ updateOrganizationAccess,
2403
+ removeOrganizationAccess,
2404
+ setActiveOrganizationAccessId
2405
+ } = organizationAccessSlice.actions;
2397
2406
  const selectOrganizationAccesses = (state) => {
2398
2407
  return state.organizationAccessReducer.organizationAccesses;
2399
2408
  };
2400
2409
  const selectOrganizationAccess = (organizationAccessId) => (state) => {
2401
2410
  return state.organizationAccessReducer.organizationAccesses[organizationAccessId];
2402
2411
  };
2403
- const selectActiveOrganizationAccess = toolkit.createSelector(
2404
- [selectCurrentUser, selectOrganizationAccesses],
2405
- (currentUser, organizationAccesses) => {
2406
- const activeOrganizationAccess = Object.values(organizationAccesses).find(
2407
- (organizationAccess) => organizationAccess.user === currentUser.id
2408
- );
2409
- if (!activeOrganizationAccess) {
2410
- return null;
2411
- }
2412
- return activeOrganizationAccess;
2412
+ const selectActiveOrganizationAccess = (state) => {
2413
+ const activeOrganizationAccessId = state.organizationAccessReducer.activeOrganizationAccessId;
2414
+ if (!activeOrganizationAccessId) {
2415
+ return null;
2413
2416
  }
2414
- );
2417
+ return state.organizationAccessReducer.organizationAccesses[activeOrganizationAccessId] ?? null;
2418
+ };
2415
2419
  const selectOrganizationAccessForUser = (user) => (state) => {
2416
2420
  return Object.values(state.organizationAccessReducer.organizationAccesses).find(
2417
2421
  (organizationAccess) => organizationAccess.user === user.id
@@ -2460,11 +2464,6 @@ var __publicField = (obj, key, value) => {
2460
2464
  const selectOrganizations = (state) => {
2461
2465
  return Object.values(state.organizationReducer.organizations);
2462
2466
  };
2463
- const selectOrganizationsWithAccess = (state) => {
2464
- return Object.values(state.organizationReducer.organizations).filter(
2465
- (organization) => organization.has_access
2466
- );
2467
- };
2468
2467
  const selectActiveOrganization = (state) => {
2469
2468
  const id = selectActiveOrganizationId(state);
2470
2469
  if (!id) {
@@ -2686,6 +2685,13 @@ var __publicField = (obj, key, value) => {
2686
2685
  deleteProject: (state, action) => {
2687
2686
  delete state.projects[action.payload.id];
2688
2687
  state.recentProjectIds = state.recentProjectIds.filter((id) => id !== action.payload.id);
2688
+ },
2689
+ acceptProjectInvite: (state, action) => {
2690
+ if (action.payload in state.projects) {
2691
+ state.projects[action.payload].invited = false;
2692
+ } else {
2693
+ throw new Error("Accept project invite: user is not in this project");
2694
+ }
2689
2695
  }
2690
2696
  }
2691
2697
  });
@@ -2695,7 +2701,8 @@ var __publicField = (obj, key, value) => {
2695
2701
  updateOrCreateProjects: addOrReplaceProjects,
2696
2702
  setActiveProjectId,
2697
2703
  setCreateProjectType,
2698
- deleteProject
2704
+ deleteProject,
2705
+ acceptProjectInvite
2699
2706
  } = projectSlice.actions;
2700
2707
  const selectProjects = (state) => state.projectReducer.projects;
2701
2708
  const selectActiveProjectId = (state) => state.projectReducer.activeProjectId;
@@ -2709,21 +2716,6 @@ var __publicField = (obj, key, value) => {
2709
2716
  const selectRecentProjects = (state) => {
2710
2717
  return state.projectReducer.recentProjectIds;
2711
2718
  };
2712
- const selectSortedProjects = toolkit.createSelector(
2713
- [selectActiveProject, selectProjects],
2714
- (activeProject, projects) => {
2715
- return Object.values(projects).sort((projectA, projectB) => {
2716
- if (activeProject) {
2717
- if (activeProject.id === projectA.id) {
2718
- return -1;
2719
- } else if (activeProject.id === projectB.id) {
2720
- return 1;
2721
- }
2722
- }
2723
- return projectA.name.toLowerCase().localeCompare(projectB.name.toLowerCase(), void 0, { numeric: true });
2724
- });
2725
- }
2726
- );
2727
2719
  const selectCreateProjectType = (state) => state.projectReducer.createProjectType;
2728
2720
  const projectReducer = projectSlice.reducer;
2729
2721
  const selectProjectUsersIds = toolkit.createSelector(
@@ -2734,6 +2726,10 @@ var __publicField = (obj, key, value) => {
2734
2726
  [selectProjectUsersIds, selectUsersAsMapping],
2735
2727
  (projectUserIds, users) => projectUserIds.reduce((accum, userId) => ({ ...accum, [userId]: users[userId] }), {})
2736
2728
  );
2729
+ const selectProjectsWithAccess = toolkit.createSelector(
2730
+ [selectProjects],
2731
+ (projects) => Object.values(projects).filter((project) => !project.invited)
2732
+ );
2737
2733
  const selectSortedProjectUsers = toolkit.createSelector(
2738
2734
  [selectCurrentUser, selectProjectUsersAsMapping, selectProjectAccessUserMapping],
2739
2735
  (currentUser, userMapping, projectAccessMapping) => {
@@ -4061,6 +4057,7 @@ var __publicField = (obj, key, value) => {
4061
4057
  store.dispatch(setLoggedIn(false));
4062
4058
  store.dispatch(clearTokens());
4063
4059
  store.dispatch(setActiveProjectId(null));
4060
+ store.dispatch(setActiveOrganizationAccessId(null));
4064
4061
  store.dispatch(setActiveWorkspaceId(null));
4065
4062
  store.dispatch({ type: constants.RESET_STATE });
4066
4063
  store.dispatch({ type: resetStore });
@@ -4867,14 +4864,16 @@ var __publicField = (obj, key, value) => {
4867
4864
  // Don't accept updateStore in ComponentService.list. Just return the offline objects and promise. Here, if
4868
4865
  // overwrite, use setComponents. Otherwise, use bulkAddComponents.
4869
4866
  async _processInitialData(data, overwrite) {
4870
- var _a2, _b;
4867
+ var _a2, _b, _c;
4871
4868
  const workspaces = {};
4872
4869
  const projects = [];
4873
4870
  const categories = [];
4874
4871
  const projectsData = data.projects;
4875
4872
  const { store } = this.client;
4876
- const oldProjectId = store.getState().projectReducer.activeProjectId;
4877
- let currentProjectId = oldProjectId ?? ((_a2 = projectsData[0]) == null ? void 0 : _a2.id);
4873
+ const oldProjectId = (_a2 = projectsData.find(
4874
+ (projectData) => projectData.id === store.getState().projectReducer.activeProjectId && !projectData.invited
4875
+ )) == null ? void 0 : _a2.id;
4876
+ let currentProjectId = oldProjectId ?? ((_b = projectsData.find((projectData) => !projectData.invited)) == null ? void 0 : _b.id);
4878
4877
  store.dispatch(setActiveProjectId(currentProjectId ?? null));
4879
4878
  let isProjectIdValid = false;
4880
4879
  for (const projectData of projectsData) {
@@ -4883,9 +4882,10 @@ var __publicField = (obj, key, value) => {
4883
4882
  name: projectData.name,
4884
4883
  owner_organization: projectData.organization_owner,
4885
4884
  owner_user: projectData.user_owner,
4886
- bounds: projectData.bounds
4885
+ bounds: projectData.bounds,
4886
+ invited: projectData.invited || false
4887
4887
  });
4888
- if (currentProjectId === projectData.id) {
4888
+ if (currentProjectId === projectData.id && !projectData.invited) {
4889
4889
  isProjectIdValid = true;
4890
4890
  for (const workspaceData of projectData.workspaces) {
4891
4891
  const workspace = { ...workspaceData, project: projectData.id };
@@ -4900,41 +4900,43 @@ var __publicField = (obj, key, value) => {
4900
4900
  }
4901
4901
  }
4902
4902
  store.dispatch(setCurrentUser(data.user));
4903
- store.dispatch(addUsers(data.project_owners));
4904
4903
  const organizationsData = data.organizations;
4905
4904
  store.dispatch(setOrganizations(organizationsData));
4906
- const activeOrganizationId = store.getState().organizationReducer.activeOrganizationId;
4907
- const firstOrg = organizationsData.find((organization) => organization.has_access);
4905
+ const validProjects = projects.filter((project) => !project.invited);
4906
+ const firstOrg = organizationsData[0];
4908
4907
  const currProjObj = projects.find((project) => project.id === currentProjectId);
4909
4908
  const isOrgProject = !!(currProjObj == null ? void 0 : currProjObj.owner_organization);
4910
- const userIsInProjectOrg = isOrgProject && organizationsData.some(
4911
- (organization) => organization.has_access && organization.id === currProjObj.owner_organization
4912
- );
4909
+ const userIsInProjectOrg = isOrgProject && organizationsData.some((organization) => organization.id === currProjObj.owner_organization);
4913
4910
  let currentOrgId = null;
4914
- if (activeOrganizationId) {
4915
- currentOrgId = activeOrganizationId;
4916
- } else if (userIsInProjectOrg) {
4911
+ if (userIsInProjectOrg) {
4917
4912
  currentOrgId = currProjObj.owner_organization;
4918
4913
  } else if (firstOrg) {
4919
4914
  currentOrgId = firstOrg.id;
4920
4915
  }
4921
4916
  if (currentOrgId) {
4922
- await this.client.organizations.fetchInitialOrganizationData(currentOrgId, false);
4917
+ store.dispatch(setActiveOrganizationId(currentOrgId));
4918
+ const orgUsersResultPromise = this.fetchOrganizationUsers(currentOrgId);
4919
+ const organizationAccessRefreshPromise = this.client.organizationAccess.refreshStore();
4920
+ const orgUsersResult = await orgUsersResultPromise;
4921
+ await organizationAccessRefreshPromise;
4922
+ store.dispatch(addUsers(orgUsersResult));
4923
4923
  }
4924
4924
  if (!isProjectIdValid) {
4925
- if (projects.length !== 0) {
4926
- currentProjectId = projects[0].id;
4925
+ if (validProjects.length !== 0) {
4926
+ currentProjectId = validProjects[0].id;
4927
4927
  store.dispatch(setActiveProjectId(currentProjectId));
4928
- const projectData = projectsData[0];
4929
- for (const workspaceData of projectData.workspaces) {
4930
- const workspace = { ...workspaceData, project: projectData.id };
4931
- if (workspace.categories) {
4932
- for (const category of workspace.categories) {
4933
- categories.push(category);
4928
+ const projectData = projectsData.find((projectData2) => projectData2.id === currentProjectId);
4929
+ if (projectData) {
4930
+ for (const workspaceData of projectData.workspaces) {
4931
+ const workspace = { ...workspaceData, project: projectData.id };
4932
+ if (workspace.categories) {
4933
+ for (const category of workspace.categories) {
4934
+ categories.push(category);
4935
+ }
4934
4936
  }
4937
+ delete workspace.categories;
4938
+ workspaces[workspace.offline_id] = workspace;
4935
4939
  }
4936
- delete workspace.categories;
4937
- workspaces[workspace.offline_id] = workspace;
4938
4940
  }
4939
4941
  } else {
4940
4942
  currentProjectId = null;
@@ -4951,7 +4953,7 @@ var __publicField = (obj, key, value) => {
4951
4953
  let currentWorkspaceId;
4952
4954
  const oldWorkspaceId = this.client.store.getState().workspaceReducer.activeWorkspaceId;
4953
4955
  if (overwrite || !oldWorkspaceId) {
4954
- currentWorkspaceId = (_b = Object.values(workspaces).at(0)) == null ? void 0 : _b.offline_id;
4956
+ currentWorkspaceId = (_c = Object.values(workspaces).at(0)) == null ? void 0 : _c.offline_id;
4955
4957
  } else {
4956
4958
  currentWorkspaceId = oldWorkspaceId;
4957
4959
  }
@@ -4972,6 +4974,7 @@ var __publicField = (obj, key, value) => {
4972
4974
  void this.client.userForms.refreshStore().then(() => {
4973
4975
  void this.client.userFormSubmissions.refreshStore().then();
4974
4976
  });
4977
+ void this.client.emailDomains.refreshStore().then();
4975
4978
  }
4976
4979
  if (currentProjectId) {
4977
4980
  const [_offlineAttachments, promise] = this.client.attachments.fetchAll(currentProjectId);
@@ -5261,6 +5264,17 @@ var __publicField = (obj, key, value) => {
5261
5264
  blocks: []
5262
5265
  });
5263
5266
  }
5267
+ async acceptInvite(projectId) {
5268
+ return this.enqueueRequest({
5269
+ description: "Accept project invite",
5270
+ method: HttpMethod.PATCH,
5271
+ url: `/projects/${projectId}/accept-invite/`,
5272
+ blockers: [projectId.toString()],
5273
+ blocks: [projectId.toString()]
5274
+ }).then(() => {
5275
+ this.client.store.dispatch(acceptProjectInvite(projectId));
5276
+ });
5277
+ }
5264
5278
  }
5265
5279
  class UserFormService extends BaseApiService {
5266
5280
  add(state, initialRevision, url, ownerUser, ownerOrganization) {
@@ -5672,8 +5686,16 @@ var __publicField = (obj, key, value) => {
5672
5686
  blockers: [],
5673
5687
  blocks: []
5674
5688
  });
5689
+ const currentUser = state.userReducer.currentUser;
5675
5690
  const organizationAccesses = result;
5691
+ const activeOrganizationAccess = organizationAccesses.find(
5692
+ (organizationAccess) => organizationAccess.user === currentUser.id
5693
+ );
5694
+ if (!activeOrganizationAccess) {
5695
+ throw new Error("Current user does not have an organization access instance");
5696
+ }
5676
5697
  store.dispatch(setOrganizationAccesses(organizationAccesses));
5698
+ store.dispatch(setActiveOrganizationAccessId(activeOrganizationAccess.offline_id));
5677
5699
  }
5678
5700
  }
5679
5701
  const cachedRequestPromises = {};
@@ -5941,37 +5963,6 @@ var __publicField = (obj, key, value) => {
5941
5963
  }
5942
5964
  }
5943
5965
  class OrganizationService extends BaseApiService {
5944
- async fetchInitialOrganizationData(organization_id, showLoading) {
5945
- if (showLoading) {
5946
- this.client.store.dispatch(setIsFetchingInitialData(true));
5947
- }
5948
- return this.enqueueRequest({
5949
- description: "Get initial organization data",
5950
- method: HttpMethod.GET,
5951
- url: `/organizations/${organization_id}/initial-data/`,
5952
- payload: {},
5953
- isAuthNeeded: true,
5954
- blockers: [],
5955
- blocks: []
5956
- }).then((result) => {
5957
- this._processInitialOrganizationData(result, showLoading);
5958
- return result;
5959
- });
5960
- }
5961
- _processInitialOrganizationData(data, showLoading) {
5962
- const { store } = this.client;
5963
- const activeOrganization = data.organization;
5964
- const organizationAccesses = data.organization_accesses;
5965
- const email_domains = data.email_domains;
5966
- const users = data.users;
5967
- store.dispatch(addUsers(users));
5968
- store.dispatch(setActiveOrganizationId(activeOrganization.id));
5969
- store.dispatch(setOrganizationAccesses(organizationAccesses));
5970
- store.dispatch(setEmailDomains(email_domains));
5971
- if (showLoading) {
5972
- store.dispatch(setIsFetchingInitialData(false));
5973
- }
5974
- }
5975
5966
  async create(name) {
5976
5967
  const result = await this.enqueueRequest({
5977
5968
  description: "Create organization",
@@ -10745,6 +10736,7 @@ var __publicField = (obj, key, value) => {
10745
10736
  exports2.WorkspaceService = WorkspaceService;
10746
10737
  exports2.YELLOW = YELLOW;
10747
10738
  exports2._setLatestRetryTime = _setLatestRetryTime;
10739
+ exports2.acceptProjectInvite = acceptProjectInvite;
10748
10740
  exports2.addAttachment = addAttachment;
10749
10741
  exports2.addAttachments = addAttachments;
10750
10742
  exports2.addCategory = addCategory;
@@ -10982,7 +10974,6 @@ var __publicField = (obj, key, value) => {
10982
10974
  exports2.selectOrganizationUsersAsMapping = selectOrganizationUsersAsMapping;
10983
10975
  exports2.selectOrganizationUsersIds = selectOrganizationUsersIds;
10984
10976
  exports2.selectOrganizations = selectOrganizations;
10985
- exports2.selectOrganizationsWithAccess = selectOrganizationsWithAccess;
10986
10977
  exports2.selectPermittedWorkspaceIds = selectPermittedWorkspaceIds;
10987
10978
  exports2.selectPhotoAttachmentsOfIssue = selectPhotoAttachmentsOfIssue;
10988
10979
  exports2.selectProjectAccess = selectProjectAccess;
@@ -10994,6 +10985,7 @@ var __publicField = (obj, key, value) => {
10994
10985
  exports2.selectProjectUsersAsMapping = selectProjectUsersAsMapping;
10995
10986
  exports2.selectProjectUsersIds = selectProjectUsersIds;
10996
10987
  exports2.selectProjects = selectProjects;
10988
+ exports2.selectProjectsWithAccess = selectProjectsWithAccess;
10997
10989
  exports2.selectRecentIssueIds = selectRecentIssueIds;
10998
10990
  exports2.selectRecentIssuesAsSearchResults = selectRecentIssuesAsSearchResults;
10999
10991
  exports2.selectRecentProjects = selectRecentProjects;
@@ -11003,7 +10995,6 @@ var __publicField = (obj, key, value) => {
11003
10995
  exports2.selectSortedEmailDomains = selectSortedEmailDomains;
11004
10996
  exports2.selectSortedOrganizationUsers = selectSortedOrganizationUsers;
11005
10997
  exports2.selectSortedProjectUsers = selectSortedProjectUsers;
11006
- exports2.selectSortedProjects = selectSortedProjects;
11007
10998
  exports2.selectStageMapping = selectStageMapping;
11008
10999
  exports2.selectStages = selectStages;
11009
11000
  exports2.selectStagesFromComponentType = selectStagesFromComponentType;
@@ -11025,6 +11016,7 @@ var __publicField = (obj, key, value) => {
11025
11016
  exports2.selectWorkspaceMapping = selectWorkspaceMapping;
11026
11017
  exports2.selectWorkspaces = selectWorkspaces;
11027
11018
  exports2.setActiveIssueId = setActiveIssueId;
11019
+ exports2.setActiveOrganizationAccessId = setActiveOrganizationAccessId;
11028
11020
  exports2.setActiveOrganizationId = setActiveOrganizationId;
11029
11021
  exports2.setActiveProjectFileId = setActiveProjectFileId;
11030
11022
  exports2.setActiveProjectId = setActiveProjectId;