Files
formbricks/apps/web/lib/environments/changeEnvironments.ts
Johannes fe4d6a8ce8 Enable users to create a new team (#299)
* Add option to create a new team

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2023-05-28 19:11:23 +02:00

28 lines
1.0 KiB
TypeScript

export const changeEnvironment = (environmentType: string, environment: any, router: any) => {
const newEnvironmentId = environment.product.environments.find((e) => e.type === environmentType)?.id;
if (newEnvironmentId) {
router.push(`/environments/${newEnvironmentId}/`);
}
};
export const changeEnvironmentByProduct = (productId: string, environment: any, router: any) => {
const product = environment.availableProducts.find((p) => p.id === productId);
const newEnvironmentId = product?.environments[0]?.id;
if (newEnvironmentId) {
router.push(`/environments/${newEnvironmentId}/`);
}
};
export const changeEnvironmentByTeam = (teamId: string, memberships: any, router: any) => {
const newTeamMembership = memberships.find((m) => m.teamId === teamId);
const newTeamProduct = newTeamMembership?.team?.products?.[0];
if (newTeamProduct) {
const newEnvironmentId = newTeamProduct.environments.find((e) => e.type === "production")?.id;
if (newEnvironmentId) {
router.push(`/environments/${newEnvironmentId}/`);
}
}
};