UNPKG

@blocklet/ui-react

Version:

Some useful front-end web components that can be used in Blocklets.

55 lines (54 loc) 1.5 kB
import { useMemoizedFn as s } from "ahooks"; import c from "@arcblock/ux/lib/Toast"; import { getBlockletSDK as y } from "@blocklet/js-sdk"; import { formatAxiosError as u } from "../../UserCenter/libs/utils.js"; function x(g) { const n = y(), l = s(async ({ search: t, page: r = 1, pageSize: o = 20 }) => { try { return await n.user.getOrgs({ search: t, page: r, pageSize: o }); } catch (e) { return console.error(e), { orgs: [], paging: { page: r, pageSize: o, total: 0 } }; } }), i = s(async ({ name: t, description: r, avatar: o }) => { try { return (await n.user.createOrg({ name: t, description: r, avatar: o })).data; } catch (e) { return console.error(e), c.error(u(e)), null; } }), p = s(async (t, { name: r, description: o, avatar: e }) => { try { return (await n.user.updateOrg(t, { name: r, description: o, avatar: e })).data; } catch (a) { return console.error(a), c.error(u(a)), null; } }), d = s(async (t) => { try { return await n.user.getOrg(t); } catch (r) { return g.logout(), console.error(r), null; } }), m = s(async (t) => { try { const r = await n.user.getRole(t); return r.orgId ? await d(r.orgId) : null; } catch (r) { return console.error(r), null; } }); return { getOrgs: l, createOrg: i, updateOrg: p, getCurrentOrg: m }; } export { x as default };