Merge branch 'dev_environment' of gitlab.com:brandx/bxt-app into dev_environment
This commit is contained in:
commit
7c5332662d
7 changed files with 90 additions and 34 deletions
|
|
@ -42,6 +42,20 @@ export interface IGroupAPIContext {
|
|||
updateGroupPermissions: (id: number, users: User[]) => Promise<any>;
|
||||
}
|
||||
|
||||
function buildQueryString(params: Record<string, string | string[] | number | null | undefined>): string {
|
||||
// Filter out null, undefined, or empty string values
|
||||
const validParams = Object.entries(params)
|
||||
.filter(([_, value]) => value != null && value !== '')
|
||||
.map(([key, value]) => `${key}=${value}`);
|
||||
|
||||
if (validParams.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Join parameters with '&' and prepend '?'
|
||||
return `?${validParams.join('&')}`;
|
||||
}
|
||||
|
||||
export const GroupAPIContext = createContext<IGroupAPIContext>({} as IGroupAPIContext);
|
||||
|
||||
interface Props {}
|
||||
|
|
@ -53,8 +67,16 @@ export default function GroupProvider(props: PropsWithChildren<Props>) {
|
|||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addGroup = (group: pond.GroupSettings) => {
|
||||
let url = pondURL("/groups")
|
||||
if (as) url = pondURL("/groups?as=" + as)
|
||||
// let url = pondURL("/groups")
|
||||
// let keys = getContextKeys()
|
||||
// let types = getContextTypes()
|
||||
// if (as) url = pondURL("/groups?as=" + as)
|
||||
const params = {
|
||||
keys: getContextKeys(),
|
||||
types: getContextTypes(),
|
||||
as: getContextTypes().includes("team") ? undefined : as
|
||||
}
|
||||
let url = pondURL(`/groups${buildQueryString(params)}`)
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
post(url, group).then(resp => {
|
||||
return resolve(resp)
|
||||
|
|
@ -157,19 +179,25 @@ export default function GroupProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
) => {
|
||||
keys = keys ? keys : getContextKeys();
|
||||
types = types? types : getContextTypes();
|
||||
let url = "/groupPermissions/" + id
|
||||
if (as) {
|
||||
url = url + "?as=" + as +
|
||||
+
|
||||
(keys ? "?keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
} else {
|
||||
url = url +
|
||||
(keys ? "?keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
// keys = keys ? keys : getContextKeys();
|
||||
// types = types? types : getContextTypes();
|
||||
// let url = "/groupPermissions/" + id
|
||||
// if (as) {
|
||||
// url = url + "?as=" + as +
|
||||
// +
|
||||
// (keys ? "?keys=" + keys.toString() : "") +
|
||||
// (types ? "&types=" + types.toString() : "")
|
||||
// } else {
|
||||
// url = url +
|
||||
// (keys ? "?keys=" + keys.toString() : "") +
|
||||
// (types ? "&types=" + types.toString() : "")
|
||||
// }
|
||||
const params = {
|
||||
keys: getContextKeys(),
|
||||
types: getContextTypes(),
|
||||
as: getContextTypes().includes("team") ? undefined : as,
|
||||
}
|
||||
let url = `/groupPermissions/${id}${buildQueryString(params)}`
|
||||
return new Promise<AxiosResponse<pond.GetPermissionsResponse>>((resolve, reject) => {
|
||||
get<pond.GetPermissionsResponse>(pondURL(url)).then(resp => {
|
||||
resp.data = pond.GetPermissionsResponse.fromObject(resp.data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue