= ({
>
-
- Organization{" "}
- {
+ const adminOrgs = getAdminOrganizations(userRole, userID, organizations);
+ const isOrgAdmin = userRole !== "Admin";
+ const isSingleOrg = adminOrgs.length === 1;
+ const hasNoOrgs = adminOrgs.length === 0;
+
+ return (
+ <>
+
- Organizations can have multiple teams. Learn more about{" "}
- e.stopPropagation()}
+ Organization{" "}
+
+ Organizations can have multiple teams. Learn more about{" "}
+ e.stopPropagation()}
+ >
+ user management hierarchy
+
+
+ }
>
- user management hierarchy
-
+
+
}
+ name="organization_id"
+ initialValue={currentOrg ? currentOrg.organization_id : null}
+ className="mt-8"
+ rules={
+ isOrgAdmin
+ ? [
+ {
+ required: true,
+ message: "Please select an organization",
+ },
+ ]
+ : []
+ }
+ help={
+ isSingleOrg
+ ? "You can only create teams within this organization"
+ : isOrgAdmin
+ ? "required"
+ : ""
+ }
>
-
-
-
- }
- name="organization_id"
- initialValue={currentOrg ? currentOrg.organization_id : null}
- className="mt-8"
- >
- {
- form.setFieldValue("organization_id", value);
- setCurrentOrgForCreateTeam(organizations?.find((org) => org.organization_id === value) || null);
- }}
- filterOption={(input, option) => {
- if (!option) return false;
- const optionValue = option.children?.toString() || "";
- return optionValue.toLowerCase().includes(input.toLowerCase());
- }}
- optionFilterProp="children"
- >
- {organizations?.map((org) => (
-
- {org.organization_alias}{" "}
- ({org.organization_id})
-
- ))}
-
-
+ {
+ form.setFieldValue("organization_id", value);
+ setCurrentOrgForCreateTeam(
+ adminOrgs?.find((org) => org.organization_id === value) || null
+ );
+ }}
+ filterOption={(input, option) => {
+ if (!option) return false;
+ const optionValue = option.children?.toString() || "";
+ return optionValue.toLowerCase().includes(input.toLowerCase());
+ }}
+ optionFilterProp="children"
+ >
+ {adminOrgs?.map((org) => (
+
+ {org.organization_alias}{" "}
+ ({org.organization_id})
+
+ ))}
+
+
+
+ {/* Show message when org admin needs to select organization */}
+ {isOrgAdmin && !isSingleOrg && adminOrgs.length > 1 && (
+
+
+ Please select an organization to create a team for. You can only create teams within
+ organizations where you are an admin.
+
+
+ )}
+ >
+ );
+ })()}