mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-23 05:17:49 -05:00
0f0b743a10
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
28 lines
956 B
TypeScript
28 lines
956 B
TypeScript
import { useEffect, useState } from "react";
|
|
import { TOrganizationRole } from "@formbricks/types/memberships";
|
|
import { getMembershipByUserIdOrganizationIdAction } from "./actions";
|
|
|
|
export const useMembershipRole = (environmentId: string, userId: string) => {
|
|
const [membershipRole, setMembershipRole] = useState<TOrganizationRole>();
|
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
const [error, setError] = useState<string>("");
|
|
|
|
useEffect(() => {
|
|
const getRole = async () => {
|
|
try {
|
|
setIsLoading(true);
|
|
const role = await getMembershipByUserIdOrganizationIdAction(environmentId, userId);
|
|
setMembershipRole(role);
|
|
setIsLoading(false);
|
|
} catch (err: any) {
|
|
const error = err?.message || "Something went wrong";
|
|
setError(error);
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
getRole();
|
|
}, [environmentId, userId]);
|
|
|
|
return { membershipRole, isLoading, error };
|
|
};
|