From 486da3d77c6c33c90ecdbbaac199378c0e6045b1 Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Fri, 5 May 2023 18:52:38 +0500
Subject: [PATCH 1/3] fix: save tos checkbox in draft

---
 src/components/CheckboxWithLabel.js | 10 +++++++++-
 src/components/Form.js              |  8 +++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/components/CheckboxWithLabel.js b/src/components/CheckboxWithLabel.js
index 4c7123bd24d9..aab98ad01913 100644
--- a/src/components/CheckboxWithLabel.js
+++ b/src/components/CheckboxWithLabel.js
@@ -1,6 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 import {View, TouchableOpacity} from 'react-native';
+import _ from 'lodash';
 import styles from '../styles/styles';
 import Checkbox from './Checkbox';
 import Text from './Text';
@@ -75,7 +76,14 @@ class CheckboxWithLabel extends React.Component {
     constructor(props) {
         super(props);
 
-        this.isChecked = props.value || props.defaultValue || props.isChecked;
+        if (!_.isUndefined(props.value)) {
+            this.isChecked = props.value;
+        } else if (!_.isUndefined(props.defaultValue)) {
+            this.isChecked = props.defaultValue;
+        } else {
+            this.isChecked = props.isChecked;
+        }
+
         this.LabelComponent = props.LabelComponent;
 
         this.toggleCheckbox = this.toggleCheckbox.bind(this);
diff --git a/src/components/Form.js b/src/components/Form.js
index 8708eab04c6c..4b1b97f84230 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -255,7 +255,13 @@ class Form extends React.Component {
 
             // We clone the child passing down all form props
             const inputID = child.props.inputID;
-            const defaultValue = this.props.draftValues[inputID] || child.props.defaultValue;
+            let defaultValue;
+
+            if (!_.isUndefined(this.props.draftValues[inputID])) {
+                defaultValue = this.props.draftValues[inputID];
+            } else if (!_.isUndefined(child.props.defaultValue)) {
+                defaultValue = child.props.defaultValue;
+            }
 
             // We want to initialize the input value if it's undefined
             if (_.isUndefined(this.state.inputValues[inputID])) {

From eafde7e7dd9bcab44bd98fd19fe7a56f5cd4e75f Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Mon, 8 May 2023 16:49:22 +0500
Subject: [PATCH 2/3] fix: replace if statements with _find function

---
 src/components/CheckboxWithLabel.js | 13 +++++--------
 src/components/Form.js              |  9 ++++++---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/components/CheckboxWithLabel.js b/src/components/CheckboxWithLabel.js
index aab98ad01913..551294e80426 100644
--- a/src/components/CheckboxWithLabel.js
+++ b/src/components/CheckboxWithLabel.js
@@ -1,7 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 import {View, TouchableOpacity} from 'react-native';
-import _ from 'lodash';
+import _ from 'underscore';
 import styles from '../styles/styles';
 import Checkbox from './Checkbox';
 import Text from './Text';
@@ -76,13 +76,10 @@ class CheckboxWithLabel extends React.Component {
     constructor(props) {
         super(props);
 
-        if (!_.isUndefined(props.value)) {
-            this.isChecked = props.value;
-        } else if (!_.isUndefined(props.defaultValue)) {
-            this.isChecked = props.defaultValue;
-        } else {
-            this.isChecked = props.isChecked;
-        }
+        // We need to pick the first value that is strictly a boolean
+        // https://github.com/Expensify/App/issues/16885#issuecomment-1520846065
+
+        this.isChecked = _.find([props.value, props.defaultValue, props.isChecked], value => _.isBoolean(value));
 
         this.LabelComponent = props.LabelComponent;
 
diff --git a/src/components/Form.js b/src/components/Form.js
index 4b1b97f84230..dfed6138d9f2 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -257,10 +257,13 @@ class Form extends React.Component {
             const inputID = child.props.inputID;
             let defaultValue;
 
-            if (!_.isUndefined(this.props.draftValues[inputID])) {
+            // We need to make sure that checkboxes have correct
+            // value assigned from the list of draft values
+            // https://github.com/Expensify/App/issues/16885#issuecomment-1520846065
+            if (_.isBoolean(this.props.draftValues[inputID])) {
                 defaultValue = this.props.draftValues[inputID];
-            } else if (!_.isUndefined(child.props.defaultValue)) {
-                defaultValue = child.props.defaultValue;
+            } else {
+                defaultValue = this.props.draftValues[inputID] || child.props.defaultValue;
             }
 
             // We want to initialize the input value if it's undefined

From 29fe0e2e7e87c181766ca504479b1599e3473dba Mon Sep 17 00:00:00 2001
From: Sibtain Ali <allroundexperts@gmail.com>
Date: Tue, 9 May 2023 15:49:20 +0500
Subject: [PATCH 3/3] Update src/components/CheckboxWithLabel.js

Co-authored-by: Rocio Perez-Cano <pecanoro@users.noreply.github.com>
---
 src/components/CheckboxWithLabel.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/components/CheckboxWithLabel.js b/src/components/CheckboxWithLabel.js
index 551294e80426..27b72bc62207 100644
--- a/src/components/CheckboxWithLabel.js
+++ b/src/components/CheckboxWithLabel.js
@@ -78,7 +78,6 @@ class CheckboxWithLabel extends React.Component {
 
         // We need to pick the first value that is strictly a boolean
         // https://github.com/Expensify/App/issues/16885#issuecomment-1520846065
-
         this.isChecked = _.find([props.value, props.defaultValue, props.isChecked], value => _.isBoolean(value));
 
         this.LabelComponent = props.LabelComponent;
