@selfcommunity/react-core
Version:
React Core Components useful for integrating UI Community components (react-ui).
39 lines (38 loc) • 1.38 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const Errors_1 = require("../constants/Errors");
const api_services_1 = require("@selfcommunity/api-services");
const utils_1 = require("@selfcommunity/utils");
/**
:::info
This custom hook is used to fetch the list of user providers.
:::
* @param object
* @param object.id
* @param object.providers
*/
function useSCFetchUserProviders({ id, providers = null }) {
const [scUserProviders, setSCUserProviders] = (0, react_1.useState)(providers || []);
const [error, setError] = (0, react_1.useState)(null);
/**
* If id resolve the obj
*/
(0, react_1.useEffect)(() => {
if (providers !== null) {
return;
}
// Retrieve provider associations if doues not exists
api_services_1.UserService.getProviderAssociations(id)
.then((providers) => {
setSCUserProviders(providers);
})
.catch((err) => {
setError(`User with id ${id} not found`);
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, `User with id ${id} not found`);
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
});
}, [id, providers]);
return { scUserProviders, setSCUserProviders, error };
}
exports.default = useSCFetchUserProviders;
;