import React from 'react';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { Text, TextVariants, Form, Alert } from '@patternfly/react-core';
import { translate as __ } from 'foremanReact/common/I18n';
import { SelectField } from '../form/SelectField';
import { GroupedSelectField } from '../form/GroupedSelectField';
import { WizardTitle } from '../form/WizardTitle';
import { WIZARD_TITLES, JOB_TEMPLATES } from '../../JobWizardConstants';
import { selectIsLoading } from '../../JobWizardSelectors';
export const CategoryAndTemplate = ({
jobCategories,
jobTemplates,
setJobTemplate,
selectedTemplateID,
selectedCategory,
setCategory,
errors,
}) => {
const templatesGroups = {};
const isTemplatesLoading = useSelector(state =>
selectIsLoading(state, JOB_TEMPLATES)
);
if (!isTemplatesLoading) {
jobTemplates.forEach(template => {
if (templatesGroups[template.provider_type]?.options)
templatesGroups[template.provider_type].options.push({
label: template.name,
value: template.id,
});
else
templatesGroups[template.provider_type] = {
options: [{ label: template.name, value: template.id }],
groupLabel: template.provider_type,
};
});
}
const selectedTemplate = jobTemplates.find(
template => template.id === selectedTemplateID
)?.name;
const onSelectCategory = newCategory => {
setCategory(newCategory);
setJobTemplate(null);
};
const { categoryError, allTemplatesError, templateError } = errors;
const isError = !!(categoryError || allTemplatesError || templateError);
return (
<>