organizations: mapToOptionType()

in src/Frontend/src/forms/user/FormEditUser.tsx [69:173]


                organizations: mapToOptionType(organizationsOptions),
                groups: mapToOptionType(groupsOptions),
                organizations_utils: organizationUtilsOptions
            });
        }
        
        getDataOptions();
    }, [rolesOptions, organizationsOptions, groupsOptions, organizationUtilsOptions]);
    
    const form = useForm<z.infer<typeof formData.schema>>({
        resolver: zodResolver(formData.schema),
        defaultValues: data || SchemaEditUserDefaultValues
    });
    
    useEffect(() => {
        if (data && !isEmpty(data)) {
            const newData = Object.assign({}, data);
            newData.organizations = newData.organizations.map((o : IOrganization) => ({ ...o, value: o.id, label: o.name }));
            newData.groups = newData.groups.map((g : IGroup) => ({ ...g, value: g.id, label: g.name }));
            form.reset(newData);
        }
    }, [data, form]);
    
    const [role_id, organizations, groups] = (form as any).watch(['role_id', 'organizations', 'groups']);
        
    const isAdminRole = useCallback(() => {
        if (isEmpty(defaultOptions.role_id)) return false;
        const roleItem = defaultOptions.role_id.find(role => role.id === role_id);
        if (!roleItem) return false;
            
        if (ROLE_ADMIN_ARRAY.includes(roleItem.label)) return true;
            
        return false;
    }, [defaultOptions, role_id]);
        
    const isStateManagerRole = useCallback(() => {
        if (isEmpty(defaultOptions.role_id)) return false;
        const roleItem = defaultOptions.role_id.find(role => role.id === role_id);
        if (!roleItem) return false;
            
        if (ROLE_STATE_MANAGER_ARRAY.includes(roleItem.label)) return true;
            
        return false;
    }, [defaultOptions, role_id]);

    const isRegionManagerRole = useCallback(() => {
        if (isEmpty(defaultOptions.role_id)) return false;
        const roleItem = defaultOptions.role_id.find(role => role.id === role_id);
        if (!roleItem) return false;

        if (ROLE_REGIONAL_MANAGER_ARRAY.includes(roleItem.label)) return true;

        return false;
    }, [defaultOptions, role_id]);

    const isCountyManagerRole = useCallback(() => {
        if (isEmpty(defaultOptions.role_id)) return false;
        const roleItem = defaultOptions.role_id.find(role => role.id === role_id);
        if (!roleItem) return false;

        if (ROLE_COUNTY_MANAGER_ARRAY.includes(roleItem.label)) return true;
        return false;
    }, [defaultOptions, role_id]);

    const isSchoolManagerRole = useCallback(() => {
        if (isEmpty(defaultOptions.role_id)) return false;
        const roleItem = defaultOptions.role_id.find(role => role.id === role_id);
        if (!roleItem) return false;

        if (ROLE_SCHOOL_MANAGER_ARRAY.includes(roleItem.label)) return true;

        return false;
    }, [defaultOptions, role_id]);

    const isStudentRole = useCallback((): boolean => {
        if (isEmpty(defaultOptions.role_id)) return false;
        const roleItem = defaultOptions.role_id.find(role => role.id === role_id);
        if (!roleItem) return false;

        if (ROLE_STUDENT_ARRAY.includes(roleItem.label)) return true;

        return false;
    }, [defaultOptions, role_id]);

    const onSubmit = async (values: z.infer<typeof formData.schema>) => {
        setLoading(true)
        try {
            await updateUserById(data.id, values);
            toast.success(t('toast.success.form.user_updated'))
            setOpen(false)
        } catch (error: any) {
            toast.error(t('toast.errors.form.edit_user'))
        } finally {
            setLoading(false)
        }
        queryClient.invalidateQueries({ queryKey: [CATEGORY_USERS] });
    }

    const getOrganizationsOptions = useCallback(() => {
        if (isEmpty(role_id) || isAdminRole() || !organizations) return [];

        let newOrganizationOptions : TOption[] = Object.assign([], defaultOptions['organizations']);

        if (isStudentRole()) {
            newOrganizationOptions = newOrganizationOptions.map((organization: TOption)=> ({