fix: admin auth related fixes

This commit is contained in:
sriram veeraghanta 2024-05-14 20:54:49 +05:30
parent 9b7b23f5a2
commit bcc4524f7f
80 changed files with 606 additions and 360 deletions

View file

@ -1,12 +1,12 @@
import { observable, action, computed, makeObservable, runInAction } from "mobx";
import set from "lodash/set";
import { observable, action, computed, makeObservable, runInAction } from "mobx";
import { IInstance, IInstanceAdmin, IInstanceConfiguration, IFormattedInstanceConfiguration } from "@plane/types";
// helpers
import { EInstanceStatus, TInstanceStatus } from "@/helpers";
// services
import { InstanceService } from "@/services/instance.service";
// root store
import { RootStore } from "@/store/root-store";
import { RootStore } from "@/store/root.store";
export interface IInstanceStore {
// issues
@ -18,11 +18,12 @@ export interface IInstanceStore {
// computed
formattedConfig: IFormattedInstanceConfiguration | undefined;
// action
hydrate: (data: any) => void;
fetchInstanceInfo: () => Promise<IInstance | undefined>;
updateInstanceInfo: (data: Partial<IInstance["instance"]>) => Promise<IInstance["instance"] | undefined>;
fetchInstanceAdmins: () => Promise<IInstanceAdmin[] | undefined>;
fetchInstanceConfigurations: () => Promise<IInstanceConfiguration[] | undefined>;
updateInstanceConfigurations: (data: Partial<IFormattedInstanceConfiguration>) => Promise<void>;
updateInstanceConfigurations: (data: Partial<IFormattedInstanceConfiguration>) => Promise<IInstanceConfiguration[]>;
}
export class InstanceStore implements IInstanceStore {
@ -45,6 +46,7 @@ export class InstanceStore implements IInstanceStore {
// computed
formattedConfig: computed,
// actions
hydrate: action,
fetchInstanceInfo: action,
fetchInstanceAdmins: action,
updateInstanceInfo: action,
@ -55,6 +57,10 @@ export class InstanceStore implements IInstanceStore {
this.instanceService = new InstanceService();
}
hydrate = (data: any) => {
if (data) this.instance = data;
};
/**
* computed value for instance configurations data for forms.
* @returns configurations in the form of {key, value} pair.
@ -148,13 +154,15 @@ export class InstanceStore implements IInstanceStore {
*/
updateInstanceConfigurations = async (data: Partial<IFormattedInstanceConfiguration>) => {
try {
await this.instanceService.updateInstanceConfigurations(data).then((response) => {
runInAction(() => {
this.instanceConfigurations = this.instanceConfigurations
? [...this.instanceConfigurations, ...response]
: response;
const response = await this.instanceService.updateInstanceConfigurations(data);
runInAction(() => {
this.instanceConfigurations = this.instanceConfigurations?.map((config) => {
const item = response.find((item) => item.key === config.key);
if (item) return item;
return config;
});
});
return response;
} catch (error) {
console.error("Error updating the instance configurations");
throw error;

View file

@ -1,7 +1,7 @@
import { enableStaticRendering } from "mobx-react-lite";
// stores
import { IThemeStore, ThemeStore } from "./theme.store";
import { IInstanceStore, InstanceStore } from "./instance.store";
import { IThemeStore, ThemeStore } from "./theme.store";
import { IUserStore, UserStore } from "./user.store";
enableStaticRendering(typeof window === "undefined");
@ -17,9 +17,14 @@ export class RootStore {
this.user = new UserStore(this);
}
hydrate(initialData: any) {
this.theme.hydrate(initialData.theme);
this.instance.hydrate(initialData.instance);
this.user.hydrate(initialData.user);
}
resetOnSignOut() {
localStorage.setItem("theme", "system");
this.instance = new InstanceStore(this);
this.user = new UserStore(this);
this.theme = new ThemeStore(this);

View file

@ -1,6 +1,6 @@
import { action, observable, makeObservable } from "mobx";
// root store
import { RootStore } from "@/store/root-store";
import { RootStore } from "@/store/root.store";
type TTheme = "dark" | "light";
export interface IThemeStore {
@ -9,6 +9,7 @@ export interface IThemeStore {
theme: string | undefined;
isSidebarCollapsed: boolean | undefined;
// actions
hydrate: (data: any) => void;
toggleNewUserPopup: () => void;
toggleSidebar: (collapsed: boolean) => void;
setTheme: (currentTheme: TTheme) => void;
@ -33,6 +34,10 @@ export class ThemeStore implements IThemeStore {
});
}
hydrate = (data: any) => {
if (data) this.theme = data;
};
/**
* @description Toggle the new user popup modal
*/

View file

@ -3,10 +3,10 @@ import { IUser } from "@plane/types";
// helpers
import { EUserStatus, TUserStatus } from "@/helpers";
// services
import { AuthService } from "@/services";
import { UserService } from "@/services/user.service";
// root store
import { RootStore } from "@/store/root-store";
import { AuthService } from "@/services";
import { RootStore } from "@/store/root.store";
export interface IUserStore {
// observables
@ -15,6 +15,7 @@ export interface IUserStore {
isUserLoggedIn: boolean | undefined;
currentUser: IUser | undefined;
// fetch actions
hydrate: (data: any) => void;
fetchCurrentUser: () => Promise<IUser>;
reset: () => void;
signOut: () => void;
@ -46,6 +47,10 @@ export class UserStore implements IUserStore {
this.authService = new AuthService();
}
hydrate = (data: any) => {
if (data) this.currentUser = data;
};
/**
* @description Fetches the current user
* @returns Promise<IUser>