Merge branch 'field_dashboard' into staging_environment
This commit is contained in:
commit
943a6e4132
23 changed files with 1243 additions and 217 deletions
|
|
@ -5,10 +5,11 @@ import { useGlobalState } from "providers";
|
|||
import React, { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { or } from "utils";
|
||||
import { pondURL } from "./pond";
|
||||
import { permissionToString } from "pbHelpers/Permission";
|
||||
|
||||
export interface IFieldAPIContext {
|
||||
addField: (field: pond.FieldSettings, otherTeam?: string) => Promise<any>;
|
||||
getField: (fieldId: string, otherTeam?: string) => Promise<any>;
|
||||
getField: (fieldId: string, otherTeam?: string) => Promise<AxiosResponse<pond.Field>>;
|
||||
listFields: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
|
|
@ -24,7 +25,15 @@ export interface IFieldAPIContext {
|
|||
field: pond.FieldSettings,
|
||||
asRoot?: true,
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
|
||||
) => Promise<AxiosResponse<pond.UpdateFieldResponse>>;
|
||||
shareAll: (
|
||||
email: string,
|
||||
permissions: pond.Permission[],
|
||||
) => Promise<AxiosResponse<any>>
|
||||
shareAllByKey: (
|
||||
key: string,
|
||||
permissions: pond.Permission[]
|
||||
) => Promise<AxiosResponse<any>>
|
||||
}
|
||||
|
||||
export const FieldAPIContext = createContext<IFieldAPIContext>({} as IFieldAPIContext);
|
||||
|
|
@ -44,8 +53,8 @@ export default function FieldProvider(props: PropsWithChildren<Props>) {
|
|||
|
||||
const getField = (fieldId: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return get(pondURL("/field/" + fieldId + "?as=" + view));
|
||||
return get(pondURL("/field/" + fieldId));
|
||||
if (view) return get<pond.Field>(pondURL("/field/" + fieldId + "?as=" + view));
|
||||
return get<pond.Field>(pondURL("/field/" + fieldId));
|
||||
};
|
||||
|
||||
const removeField = (key: string, otherTeam?: string) => {
|
||||
|
|
@ -93,6 +102,36 @@ export default function FieldProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const shareAll = (email: string, permissions: pond.Permission[]) => {
|
||||
let url = pondURL("/shareAllFields")
|
||||
if (as) url = url + "?as=" + as
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
post(url, {
|
||||
email: email,
|
||||
permissions: permissions.map(permission => permissionToString(permission))
|
||||
}).then(resp => {
|
||||
return resolve(resp)
|
||||
}).catch(err => {
|
||||
return reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const shareAllByKey = (key: string, permissions: pond.Permission[]) => {
|
||||
let url = pondURL("/shareAllFieldsByKey")
|
||||
if (as) url = url + "?as=" + as
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
post(url, {
|
||||
key: key,
|
||||
permissions: permissions.map(permission => permissionToString(permission))
|
||||
}).then(resp => {
|
||||
return resolve(resp)
|
||||
}).catch(err => {
|
||||
return reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<FieldAPIContext.Provider
|
||||
value={{
|
||||
|
|
@ -100,7 +139,9 @@ export default function FieldProvider(props: PropsWithChildren<Props>) {
|
|||
getField,
|
||||
listFields,
|
||||
removeField,
|
||||
updateField
|
||||
updateField,
|
||||
shareAll,
|
||||
shareAllByKey
|
||||
}}>
|
||||
{children}
|
||||
</FieldAPIContext.Provider>
|
||||
|
|
|
|||
|
|
@ -135,7 +135,6 @@ export default function PermissionProvider(props: PropsWithChildren<Props>) {
|
|||
let url = pondURL("/" + scope.kind + "s/" + scope.key + "/shareByKey")
|
||||
if (as) url = pondURL(`/${scope.kind}s/${scope.key}/shareByKey?as=${as}`)
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
|
||||
post(url, {
|
||||
key: key,
|
||||
permissions: permissions.map(permission => permissionToString(permission))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue