Files
t3code/apps/mobile/src/features/projects/AddProjectScreen.logic.ts
T

27 lines
918 B
TypeScript

import { canCreateProjectInEnvironment } from "@t3tools/client-runtime/operations/projects";
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
import type { EnvironmentId } from "@t3tools/contracts";
export function resolveAddProjectEnvironment<
T extends {
readonly environmentId: EnvironmentId;
readonly connectionState: EnvironmentConnectionPhase;
},
>(environmentOptions: ReadonlyArray<T>, requestedEnvironmentId: EnvironmentId | null): T | null {
if (requestedEnvironmentId !== null) {
return (
environmentOptions.find(
(environment) =>
environment.environmentId === requestedEnvironmentId &&
canCreateProjectInEnvironment(environment.connectionState),
) ?? null
);
}
return (
environmentOptions.find((environment) =>
canCreateProjectInEnvironment(environment.connectionState),
) ?? null
);
}