From b6a2d3ea0abddbba8907f6c2970554dd838fca1e Mon Sep 17 00:00:00 2001
From: Muhammad Abdullah Waheed
<42172960+abdullahwaheed@users.noreply.github.com>
Date: Thu, 8 Dec 2022 17:31:19 +0500
Subject: [PATCH] refactor: replaced deprecated Paragon form components
Main issue: https://github.com/openedx/frontend-wg/issues/102
PR: https://github.com/openedx/frontend-app-publisher/pull/761
---
src/components/DateTimeField/index.jsx | 61 ++++++-----
.../RenderInputTextField.test.jsx.snap | 100 ++++++++++--------
src/components/RenderInputTextField/index.jsx | 39 ++++---
.../RenderSelectField.test.jsx.snap | 53 +++++-----
src/components/RenderSelectField/index.jsx | 37 ++++---
5 files changed, 161 insertions(+), 129 deletions(-)
diff --git a/src/components/DateTimeField/index.jsx b/src/components/DateTimeField/index.jsx
index 7f3c8f9f7..217adb995 100644
--- a/src/components/DateTimeField/index.jsx
+++ b/src/components/DateTimeField/index.jsx
@@ -1,7 +1,7 @@
import React from 'react';
import moment from 'moment';
import PropTypes from 'prop-types';
-import { InputText } from '@edx/paragon';
+import { Form } from '@edx/paragon';
import {
getDateWithDashes,
getDateWithSlashes,
@@ -84,45 +84,50 @@ class DateTimeField extends React.Component {
return (
-
+
- )}
- placeholder={placeholder}
- pattern={pattern}
- maxLength={maxLength}
- required={required}
- disabled={disabled}
- onChange={e => this.updateDate(e)}
- min={minDate}
- onInvalid={onInvalid}
- />
+
+ this.updateDate(event.target.value)}
+ min={minDate}
+ onInvalid={onInvalid}
+ />
+
-
+
- )}
- placeholder="HH:mm"
- required={required}
- disabled={disabled}
- onChange={e => this.updateTime(e)}
- />
+
+ this.updateDate(event.target.value)}
+ />
+
);
@@ -157,7 +162,7 @@ DateTimeField.defaultProps = {
utcTimeZone: false,
maxLength: '',
type: '',
- pattern: '',
+ pattern: 'dd/mm/yyyy',
placeholder: '',
};
diff --git a/src/components/RenderInputTextField/__snapshots__/RenderInputTextField.test.jsx.snap b/src/components/RenderInputTextField/__snapshots__/RenderInputTextField.test.jsx.snap
index e789ccedc..5a877c0de 100644
--- a/src/components/RenderInputTextField/__snapshots__/RenderInputTextField.test.jsx.snap
+++ b/src/components/RenderInputTextField/__snapshots__/RenderInputTextField.test.jsx.snap
@@ -1,53 +1,61 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`RenderInputTextField renders html for number type 1`] = `
-
+
+
+
+ TestLabel
+
+
+
+
`;
exports[`RenderInputTextField renders html for text 1`] = `
-
+
+
+
+ TestLabel
+
+
+
+
`;
diff --git a/src/components/RenderInputTextField/index.jsx b/src/components/RenderInputTextField/index.jsx
index cea91bf8f..4b4c03f63 100644
--- a/src/components/RenderInputTextField/index.jsx
+++ b/src/components/RenderInputTextField/index.jsx
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
-import { InputText } from '@edx/paragon';
+import { Form } from '@edx/paragon';
const RenderInputTextField = ({
input,
@@ -15,21 +15,28 @@ const RenderInputTextField = ({
pattern,
meta: { touched, error },
}) => (
-
+
+
+ {label}
+
+
+ {touched && error && (
+
+ {error}
+
+ )}
+
);
RenderInputTextField.defaultProps = {
diff --git a/src/components/RenderSelectField/__snapshots__/RenderSelectField.test.jsx.snap b/src/components/RenderSelectField/__snapshots__/RenderSelectField.test.jsx.snap
index acb4ff126..7a6ea5448 100644
--- a/src/components/RenderSelectField/__snapshots__/RenderSelectField.test.jsx.snap
+++ b/src/components/RenderSelectField/__snapshots__/RenderSelectField.test.jsx.snap
@@ -1,30 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`RenderSelectField renders html for select field 1`] = `
-
+
+
+
+ TestLabel
+
+
+
+
+
+
+
+
`;
diff --git a/src/components/RenderSelectField/index.jsx b/src/components/RenderSelectField/index.jsx
index cc8b8d49a..555f50f88 100644
--- a/src/components/RenderSelectField/index.jsx
+++ b/src/components/RenderSelectField/index.jsx
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
-import { InputSelect } from '@edx/paragon';
+import { Form } from '@edx/paragon';
const RenderSelectField = ({
input,
@@ -12,18 +12,29 @@ const RenderSelectField = ({
meta: { touched, error },
options,
}) => (
-
+
+
+ {label}
+
+
+ {options.map(option => (
+
+ ))}
+ {touched && error && (
+
+ {error}
+
+ )}
+
+
);
RenderSelectField.defaultProps = {