Skip to content

Commit

Permalink
Merge pull request #1444 from culturecreates/bugfix/issue-100
Browse files Browse the repository at this point in the history
fix: added support for region mandatory field in quick create place
  • Loading branch information
AbhishekPAnil authored Nov 14, 2024
2 parents 66127f1 + 9110c65 commit 17e87d1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/components/Modal/QuickCreatePlace/QuickCreatePlace.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
createInitialNamesObjectFromKeyword,
placeHolderCollectionCreator,
} from '../../../utils/MultiLingualFormItemSupportFunctions';
import { placeFormRequiredFieldNames } from '../../../constants/placeFormRequiredFieldNames';

const { TextArea } = Input;

Expand All @@ -52,15 +53,30 @@ function QuickCreatePlace(props) {
setLoaderModalOpen,
loaderModalOpen,
setShowDialog,
currentCalendarData,
} = props;

const fieldNames = {
name: 'name',
region: 'region',
address: 'address',
placeType: 'placeType',
};

const [form] = Form.useForm();
const { t } = useTranslation();
const timestampRef = useRef(Date.now()).current;
const navigate = useNavigate();
const { user } = useSelector(getUserDetails);
const { eventId } = useParams();

let requiredFields = currentCalendarData?.forms?.filter((form) => form?.formName === entitiesClass.place);
let requiredFieldNames = requiredFields
? requiredFields[0]?.formFieldProperties?.mandatoryFields?.standardFields
?.map((field) => field?.fieldName)
?.concat(requiredFields[0]?.formFieldProperties?.mandatoryFields?.dynamicFields?.map((field) => field))
: [];

const [event, setEvent] = useState([]);
useEffect(() => {
if (event.length > 0) {
Expand Down Expand Up @@ -162,13 +178,16 @@ function QuickCreatePlace(props) {
.catch((error) => console.log(error));
};
const createPlaceHandler = (toggle = true) => {
const validationFieldNames = [];
let validationFieldNames = [];
calendarContentLanguage.forEach((language) => {
validationFieldNames.push(['name', contentLanguageKeyMap[language]]);
validationFieldNames.push([fieldNames.name, contentLanguageKeyMap[language]]);
});
if (requiredFieldNames?.includes(placeFormRequiredFieldNames.REGION)) {
validationFieldNames.push(fieldNames.region);
}
return new Promise((resolve, reject) => {
form
.validateFields([...validationFieldNames, 'address'])
.validateFields([...validationFieldNames, fieldNames.address])
.then(() => {
var values = form.getFieldsValue();
var persistValues = form.getFieldsValue(true); // if toggle is false form is unmounted, hence the need to use both default and true values
Expand Down Expand Up @@ -334,7 +353,7 @@ function QuickCreatePlace(props) {
<CreateMultiLingualFormItems
calendarContentLanguage={calendarContentLanguage}
form={form}
name={['name']}
name={[fieldNames.name]}
data={createInitialNamesObjectFromKeyword(keyword, calendarContentLanguage)}
validations={t('dashboard.events.addEditEvent.validations.title')}
dataCy={`text-area-quick-create-place-name-`}
Expand All @@ -358,7 +377,7 @@ function QuickCreatePlace(props) {
</CreateMultiLingualFormItems>

<Form.Item
name="address"
name={fieldNames.address}
label={t('dashboard.events.addEditEvent.location.quickCreatePlace.address')}
validateTrigger={['onBlur']}
rules={[
Expand Down Expand Up @@ -425,7 +444,7 @@ function QuickCreatePlace(props) {
</Form.Item>

<Form.Item
name="placeType"
name={fieldNames.placeType}
label={taxonomyDetails(allTaxonomyData?.data, user, 'Type', 'name', false)}
data-cy="form-item-quick-create-place-type-label">
<TreeSelectOption
Expand Down Expand Up @@ -454,14 +473,20 @@ function QuickCreatePlace(props) {
/>
</Form.Item>
<Form.Item
name={'region'}
name={fieldNames.region}
label={taxonomyDetails(
allTaxonomyData?.data,
user,
placeTaxonomyMappedFieldTypes.REGION,
'name',
false,
)}
rules={[
{
required: requiredFieldNames?.includes(placeFormRequiredFieldNames?.REGION),
message: t('common.validations.informationRequired'),
},
]}
data-cy="form-item-quick-create-place-region-label">
<TreeSelectOption
style={{
Expand Down
1 change: 1 addition & 0 deletions src/pages/Dashboard/AddEvent/AddEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3091,6 +3091,7 @@ function AddEvent() {
setLoaderModalOpen={setLoaderModalOpen}
loaderModalOpen={loaderModalOpen}
setShowDialog={setShowDialog}
currentCalendarData={currentCalendarData}
/>
</Form.Item>
<Form.Item
Expand Down

0 comments on commit 17e87d1

Please sign in to comment.