Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added handlesubmit and button to form #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/screens/MainScreen/components/form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const monthsArr = Array.from({ length: 12 }, (x, i) => {
const yearsArr = Array.from({ length: 9 }, (_x, i) => currentYear + i);

export default function CForm({
handleSubmit,
cardMonth,
cardYear,
onUpdateState,
Expand All @@ -17,7 +18,7 @@ export default function CForm({
onCardInputFocus,
onCardInputBlur,
cardCvv,
children
children,
}) {
const [cardNumber, setCardNumber] = useState('');

Expand Down Expand Up @@ -190,6 +191,14 @@ export default function CForm({
</div>
</div>
</div>
<div className="card-form__row">
<button
onClick={handleSubmit}
className="card-input__input"
>
Save
</button>
</div>
</div>
</div>
);
Expand Down
13 changes: 9 additions & 4 deletions src/screens/MainScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const initialState = {
cardMonth: '',
cardYear: '',
cardCvv: '',
isCardFlipped: false
isCardFlipped: false,
};

const MainScreen = () => {
Expand All @@ -19,7 +19,7 @@ const MainScreen = () => {
(keyName, value) => {
setState({
...state,
[keyName]: value || initialState[keyName]
[keyName]: value || initialState[keyName],
});
},
[state]
Expand All @@ -30,7 +30,7 @@ const MainScreen = () => {
cardNumber: useRef(),
cardHolder: useRef(),
cardDate: useRef(),
cardCvv: useRef()
cardCvv: useRef(),
};

let focusFormFieldByKey = useCallback((key) => {
Expand All @@ -41,7 +41,7 @@ const MainScreen = () => {
let cardElementsRef = {
cardNumber: useRef(),
cardHolder: useRef(),
cardDate: useRef()
cardDate: useRef(),
};

let onCardFormInputFocus = (_event, inputName) => {
Expand All @@ -53,9 +53,14 @@ const MainScreen = () => {
setCurrentFocusedElm(null);
}, []);

let doSubmit = () => {
return console.log(state);
};

return (
<div className="wrapper">
<CForm
handleSubmit={doSubmit}
cardMonth={state.cardMonth}
cardYear={state.cardYear}
onUpdateState={updateStateValues}
Expand Down