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

Status clear after #24620

Merged
merged 160 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
75fbcbd
add routes
perunt Aug 16, 2023
cd8dd15
add disableIsFocusStyle feature to BaseSelectionListRadio
perunt Aug 16, 2023
3ecbaaf
add translations
perunt Aug 16, 2023
244147e
extend dateUtils
perunt Aug 16, 2023
b612558
add new field for draftCustomStatus in Onyx
perunt Aug 16, 2023
f774e8e
use proper data for title on StatusPage
perunt Aug 16, 2023
5f5233a
WIP StatusClearAfterPage
perunt Aug 16, 2023
76f5a67
add style property into BaseSelectionListRadio
perunt Aug 16, 2023
9053f53
WIP SettingsStatusCustomClearAfter
perunt Aug 16, 2023
2650d40
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Aug 21, 2023
dbfde80
lint
perunt Aug 21, 2023
243c7e3
add SetTimePage
perunt Aug 22, 2023
1f51af1
use correct clearAfter for saving
perunt Aug 22, 2023
55ecba3
add styles to AmountTextInput
perunt Aug 23, 2023
7cc9a4b
add isDisabledLongPress to button
perunt Aug 23, 2023
c150adf
update BigNumberPad
perunt Aug 23, 2023
b6c34cb
create TimePicker
perunt Aug 23, 2023
f81217f
lint
perunt Aug 23, 2023
be5ed56
add ItemSeparatorComponent to BaseSelectionListRadio
perunt Aug 23, 2023
72d6c0e
add containerStyle for MenuItem
perunt Aug 23, 2023
33b23b9
add separator component
perunt Aug 23, 2023
992b4fc
add translations
perunt Aug 23, 2023
f532d24
add buttonStyle in Form
perunt Aug 23, 2023
9e8e850
create areDatesIdentical and getTimePeriod
perunt Aug 23, 2023
f500a65
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Aug 23, 2023
b8da3bb
fix BaseSelectionList after merge
perunt Aug 23, 2023
8a2af6f
remove stale time
perunt Aug 24, 2023
ff8334c
disable scroll
perunt Aug 24, 2023
0562caf
clean
perunt Aug 24, 2023
e3fa10a
clean
perunt Aug 24, 2023
76dc73f
exhaustive-deps
perunt Aug 24, 2023
3402e36
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Aug 25, 2023
dbf4f4e
do more comments
perunt Aug 27, 2023
bd32866
Merge branch 'main' of https://github.com/margelo/expensify-app-fork …
perunt Aug 28, 2023
a140ac2
remove getDateForTitleBasedFromType
perunt Aug 29, 2023
cad1d25
Merge branch 'main' of https://github.com/margelo/expensify-app-fork …
perunt Aug 29, 2023
6eaf9f5
add FormHelpMessage for MenuItem
perunt Aug 30, 2023
45b070b
add brickRoadIndicator for status page
perunt Aug 30, 2023
67a83ee
add error handling for time picker
perunt Aug 30, 2023
793d02a
add time validation for StatusClearAfterPage
perunt Aug 30, 2023
3395f1b
add submitButtonContainerStyle
perunt Aug 31, 2023
8c62869
add containerMessageStyle for FormHelpMessage
perunt Aug 31, 2023
4ec08ef
lint
perunt Aug 31, 2023
ddf7b70
flex reset
perunt Aug 31, 2023
0862b81
Merge branch 'main' of https://github.com/margelo/expensify-app-fork …
perunt Aug 31, 2023
0afb8f1
remove duplicates after merge
perunt Aug 31, 2023
4742fa9
remove error dot and underline
perunt Aug 31, 2023
33bb524
adjust error styles
perunt Aug 31, 2023
a0b89d1
update validation
perunt Aug 31, 2023
fab3f10
update translation
perunt Sep 1, 2023
36f20c9
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Sep 1, 2023
1cb9425
tide up the comments for time utils
perunt Sep 1, 2023
e4283bc
add more comments for TimePicker
perunt Sep 3, 2023
ce90d1b
fix form button
perunt Sep 4, 2023
2f7de91
update time picker styles
perunt Sep 4, 2023
a3b3b75
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Sep 4, 2023
3038c64
remove unused styleUtils
perunt Sep 4, 2023
4f438f4
BRICK_ROAD_INDICATOR_STATUS
perunt Sep 5, 2023
b8d1d13
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Sep 25, 2023
9f63519
fix after merge
perunt Sep 25, 2023
658a0ef
fix routes
perunt Sep 26, 2023
6e27461
add errorMessageStyle for the Form
perunt Sep 26, 2023
68df0de
update validateDateTimeIsAtLeastOneMinuteInFuture
perunt Sep 26, 2023
b31c3fb
fix ScreenWrapper
perunt Sep 26, 2023
679ee5b
fix rerenders in TimePicker
perunt Sep 26, 2023
b92dee6
migrate from moment to date-fns
perunt Sep 26, 2023
3653b91
lint
perunt Sep 26, 2023
b057191
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Sep 26, 2023
9b44d86
fix after merge
perunt Sep 26, 2023
f4cd77b
clean styles
perunt Sep 26, 2023
a095fd0
add resetForm functionality for Form, add isDisabled
perunt Sep 27, 2023
394dba6
change combineDateAndTime
perunt Sep 27, 2023
041b7cb
new design
perunt Sep 27, 2023
4e909cd
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Sep 27, 2023
78bc2e5
delete StatusSetPage
perunt Sep 27, 2023
bd517b4
lint
perunt Sep 27, 2023
b4166e6
add translation
perunt Sep 27, 2023
c702bce
fix validation
perunt Sep 27, 2023
f019b7d
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Sep 27, 2023
741a979
remove SelectionList
perunt Sep 27, 2023
7013977
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Sep 28, 2023
9d19aa5
fix style errors
perunt Sep 28, 2023
f12461f
remove disabling
perunt Sep 29, 2023
315a8aa
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 4, 2023
3187265
fix after merge
perunt Oct 4, 2023
dcb1145
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 11, 2023
798da59
storybook: add error text for MenuItem
perunt Oct 11, 2023
816af08
ts
perunt Oct 11, 2023
a11b343
Simplified code
perunt Oct 16, 2023
37dd64d
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 16, 2023
eeae253
fix after merge
perunt Oct 16, 2023
2077752
lint
perunt Oct 16, 2023
c2e9a36
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 23, 2023
a7fb901
remove lodash import after merge
perunt Oct 23, 2023
4dfd6c2
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 23, 2023
61ee723
fix styles after merge
perunt Oct 23, 2023
db63d34
fix colon positioning
perunt Oct 24, 2023
9ccbe3e
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 24, 2023
da91d8b
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 27, 2023
139e9cb
change time validation
perunt Oct 27, 2023
342363c
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 30, 2023
7141613
fix imports after merge
perunt Oct 30, 2023
3c24990
update translations
perunt Oct 30, 2023
4652656
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 31, 2023
07a200e
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 31, 2023
b85dbc9
run prettier
perunt Oct 31, 2023
6cb433e
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Oct 31, 2023
8d3d44a
fix after merge: replace FormProvider with Form
perunt Oct 31, 2023
39198d4
showSoftInputOnFocus
perunt Nov 2, 2023
a441841
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 2, 2023
752de6a
update translations
perunt Nov 3, 2023
431b6e3
update spanish translation
perunt Nov 4, 2023
07e54ed
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 8, 2023
1588913
change validation + add focus
perunt Nov 8, 2023
274cea1
fix focusing on hour input
perunt Nov 9, 2023
3179d07
remove cleanDraftValues
perunt Nov 9, 2023
aba85d5
migrate to FormProvider
perunt Nov 9, 2023
b040910
add resetForm to FormProvide
perunt Nov 9, 2023
24eb81f
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 10, 2023
435c4d4
clean artifacts
perunt Nov 10, 2023
d48ff12
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 13, 2023
91b8be1
fix ios focus
perunt Nov 13, 2023
6f821fc
update naming
perunt Nov 13, 2023
70dffd3
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 13, 2023
8ab585d
prettier
perunt Nov 13, 2023
8e3a325
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 13, 2023
899005d
clean ONYXKEYS after merge
perunt Nov 13, 2023
0371e12
fix types
perunt Nov 13, 2023
b8131f6
rename field
perunt Nov 13, 2023
e471d09
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 15, 2023
de7ed58
update after merge
perunt Nov 15, 2023
dc9d3d3
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 17, 2023
9b29c56
import styles from useThemeStyles after merge
perunt Nov 17, 2023
6bfa885
update themes
perunt Nov 21, 2023
a3bc42b
ditch the illustration
perunt Nov 21, 2023
b0b1ff3
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 24, 2023
c76510e
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 27, 2023
9f4ba40
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 29, 2023
633af7a
fix after merge
perunt Nov 29, 2023
4068e30
fix after merge
perunt Nov 29, 2023
b3387fb
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Nov 29, 2023
12488b4
add Tooltip
perunt Nov 29, 2023
ab5a614
clean translation
perunt Nov 29, 2023
70a6c05
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 1, 2023
c0a4532
fix background after merge
perunt Dec 1, 2023
a878f8e
fix theme style after merge
perunt Dec 1, 2023
d525b51
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 4, 2023
fe0490b
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 4, 2023
3a06323
fix import after merge
perunt Dec 4, 2023
8aae901
lint
perunt Dec 4, 2023
acd0ff7
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 5, 2023
caea704
fix tooltip hovering
perunt Dec 5, 2023
a61c7d7
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 6, 2023
30b908d
add screens after merge
perunt Dec 6, 2023
39dc1e0
fix typing
perunt Dec 6, 2023
ad5ddaf
Merge branch 'main' of https://github.com/Expensify/App into feat/##2…
perunt Dec 13, 2023
cda1145
migrate to useStyleUtils
perunt Dec 13, 2023
b3f0937
fix getStatusAMandPMButtonStyle
perunt Dec 13, 2023
2afce0a
add shouldShowRedDotIndicator to FormHelpMessage
perunt Dec 13, 2023
47fa79c
fix after merge
perunt Dec 13, 2023
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
6 changes: 5 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2902,6 +2902,10 @@ const CONST = {
NAVIGATE: 'NAVIGATE',
},
},
TIME_PERIOD: {
AM: 'AM',
PM: 'PM',
},
INDENTS: ' ',
PARENT_CHILD_SEPARATOR: ': ',
CATEGORY_LIST_THRESHOLD: 8,
Expand All @@ -2911,7 +2915,7 @@ const CONST = {
SBE: 'SbeDemoSetup',
MONEY2020: 'Money2020DemoSetup',
},

COLON: ':',
MAPBOX: {
PADDING: 50,
DEFAULT_ZOOM: 10,
Expand Down
8 changes: 4 additions & 4 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ const ONYXKEYS = {
WAYPOINT_FORM_DRAFT: 'waypointFormDraft',
SETTINGS_STATUS_SET_FORM: 'settingsStatusSetForm',
SETTINGS_STATUS_SET_FORM_DRAFT: 'settingsStatusSetFormDraft',
SETTINGS_STATUS_CLEAR_AFTER_FORM: 'settingsStatusClearAfterForm',
SETTINGS_STATUS_CLEAR_AFTER_FORM_DRAFT: 'settingsStatusClearAfterFormDraft',
SETTINGS_STATUS_SET_CLEAR_AFTER_FORM: 'settingsStatusSetClearAfterForm',
SETTINGS_STATUS_SET_CLEAR_AFTER_FORM_DRAFT: 'settingsStatusSetClearAfterFormDraft',
SETTINGS_STATUS_CLEAR_DATE_FORM: 'settingsStatusClearDateForm',
SETTINGS_STATUS_CLEAR_DATE_FORM_DRAFT: 'settingsStatusClearDateFormDraft',
PRIVATE_NOTES_FORM: 'privateNotesForm',
PRIVATE_NOTES_FORM_DRAFT: 'privateNotesFormDraft',
I_KNOW_A_TEACHER_FORM: 'iKnowTeacherForm',
Expand Down Expand Up @@ -508,8 +508,8 @@ type OnyxValues = {
[ONYXKEYS.FORMS.WAYPOINT_FORM_DRAFT]: OnyxTypes.Form;
[ONYXKEYS.FORMS.SETTINGS_STATUS_SET_FORM]: OnyxTypes.Form;
[ONYXKEYS.FORMS.SETTINGS_STATUS_SET_FORM_DRAFT]: OnyxTypes.Form;
[ONYXKEYS.FORMS.SETTINGS_STATUS_CLEAR_AFTER_FORM]: OnyxTypes.Form;
[ONYXKEYS.FORMS.SETTINGS_STATUS_CLEAR_AFTER_FORM_DRAFT]: OnyxTypes.Form;
[ONYXKEYS.FORMS.SETTINGS_STATUS_CLEAR_DATE_FORM]: OnyxTypes.Form;
[ONYXKEYS.FORMS.SETTINGS_STATUS_CLEAR_DATE_FORM_DRAFT]: OnyxTypes.Form;
[ONYXKEYS.FORMS.SETTINGS_STATUS_SET_CLEAR_AFTER_FORM]: OnyxTypes.Form;
[ONYXKEYS.FORMS.SETTINGS_STATUS_SET_CLEAR_AFTER_FORM_DRAFT]: OnyxTypes.Form;
[ONYXKEYS.FORMS.PRIVATE_NOTES_FORM]: OnyxTypes.Form;
Expand Down
4 changes: 3 additions & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ const ROUTES = {
getRoute: (backTo?: string) => getUrlWithBackToParam('settings/security/two-factor-auth', backTo),
},
SETTINGS_STATUS: 'settings/profile/status',
SETTINGS_STATUS_SET: 'settings/profile/status/set',
SETTINGS_STATUS_CLEAR_AFTER: 'settings/profile/status/clear-after',
SETTINGS_STATUS_CLEAR_AFTER_DATE: 'settings/profile/status/clear-after/date',
SETTINGS_STATUS_CLEAR_AFTER_TIME: 'settings/profile/status/clear-after/time',

KEYBOARD_SHORTCUTS: 'keyboard-shortcuts',

Expand Down
4 changes: 3 additions & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ const SCREENS = {
CONTACT_METHODS: 'Settings_ContactMethods',
CONTACT_METHOD_DETAILS: 'Settings_ContactMethodDetails',
NEW_CONTACT_METHOD: 'Settings_NewContactMethod',
STATUS_CLEAR_AFTER: 'Settings_Status_Clear_After',
STATUS_CLEAR_AFTER_DATE: 'Settings_Status_Clear_After_Date',
STATUS_CLEAR_AFTER_TIME: 'Settings_Status_Clear_After_Time',
STATUS: 'Settings_Status',
STATUS_SET: 'Settings_Status_Set',
PRONOUNS: 'Settings_Pronouns',
TIMEZONE: 'Settings_Timezone',
TIMEZONE_SELECT: 'Settings_Timezone_Select',
Expand Down
13 changes: 12 additions & 1 deletion src/components/AmountTextInput.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import useStyleUtils from '@styles/useStyleUtils';
import useThemeStyles from '@styles/useThemeStyles';
import CONST from '@src/CONST';
import refPropTypes from './refPropTypes';
Expand Down Expand Up @@ -27,6 +28,12 @@ const propTypes = {
/** Function to call when selection in text input is changed */
onSelectionChange: PropTypes.func,

/** Style for the input */
style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),

/** Style for the container */
containerStyles: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),

/** Function to call to handle key presses in the text input */
onKeyPress: PropTypes.func,
};
Expand All @@ -36,16 +43,19 @@ const defaultProps = {
selection: undefined,
onSelectionChange: () => {},
onKeyPress: () => {},
style: {},
containerStyles: {},
};

function AmountTextInput(props) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
return (
<TextInput
disableKeyboard
autoGrow
hideFocusedState
inputStyle={[styles.iouAmountTextInput, styles.p0, styles.noLeftBorderRadius, styles.noRightBorderRadius]}
inputStyle={[styles.iouAmountTextInput, styles.p0, styles.noLeftBorderRadius, styles.noRightBorderRadius, ...StyleUtils.parseStyleAsArray(props.style)]}
textInputContainerStyles={[styles.borderNone, styles.noLeftBorderRadius, styles.noRightBorderRadius]}
onChangeText={props.onChangeAmount}
ref={props.forwardedRef}
Expand All @@ -57,6 +67,7 @@ function AmountTextInput(props) {
onSelectionChange={props.onSelectionChange}
role={CONST.ROLE.PRESENTATION}
onKeyPress={props.onKeyPress}
containerStyles={[...StyleUtils.parseStyleAsArray(props.containerStyles)]}
/>
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/BigNumberPad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type BigNumberPadProps = {

/** Used to locate this view from native classes. */
id?: string;

/** Whether long press is disabled */
isLongPressDisabled: boolean;
};

const padNumbers = [
Expand All @@ -24,7 +27,7 @@ const padNumbers = [
['.', '0', '<'],
] as const;

function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, id = 'numPadView'}: BigNumberPadProps) {
function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, id = 'numPadView', isLongPressDisabled = false}: BigNumberPadProps) {
const {toLocaleDigit} = useLocalize();

const styles = useThemeStyles();
Expand Down Expand Up @@ -85,6 +88,7 @@ function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, i
onMouseDown={(e) => {
e.preventDefault();
}}
isLongPressDisabled={isLongPressDisabled}
/>
);
})}
Expand Down
7 changes: 7 additions & 0 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ type ButtonProps = (ButtonWithText | ChildrenProps) & {
/** Should enable the haptic feedback? */
shouldEnableHapticFeedback?: boolean;

/** Should disable the long press? */
isLongPressDisabled?: boolean;

/** Id to use for this button */
id?: string;

Expand Down Expand Up @@ -149,6 +152,7 @@ function Button(
shouldRemoveRightBorderRadius = false,
shouldRemoveLeftBorderRadius = false,
shouldEnableHapticFeedback = false,
isLongPressDisabled = false,

id = '',
accessibilityLabel = '',
Expand Down Expand Up @@ -255,6 +259,9 @@ function Button(
return onPress(event);
}}
onLongPress={(event) => {
if (isLongPressDisabled) {
return;
}
if (shouldEnableHapticFeedback) {
HapticFeedback.longPress();
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/EmojiPicker/EmojiPickerButtonDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import Text from '@components/Text';
import Tooltip from '@components/Tooltip';
import Tooltip from '@components/Tooltip/PopoverAnchorTooltip';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import getButtonState from '@libs/getButtonState';
import useStyleUtils from '@styles/useStyleUtils';
Expand Down Expand Up @@ -47,7 +47,7 @@ function EmojiPickerButtonDropdown(props) {
<Tooltip text={props.translate('reportActionCompose.emoji')}>
<PressableWithoutFeedback
ref={emojiPopoverAnchor}
style={styles.emojiPickerButtonDropdown}
style={[styles.emojiPickerButtonDropdown, props.style]}
disabled={props.isDisabled}
onPress={onPress}
id="emojiDropdownButton"
Expand Down
41 changes: 37 additions & 4 deletions src/components/Form.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
import {Keyboard, ScrollView, StyleSheet} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
Expand All @@ -26,7 +26,7 @@ const propTypes = {
formID: PropTypes.string.isRequired,

/** Text to be displayed in the submit button */
submitButtonText: PropTypes.string.isRequired,
submitButtonText: PropTypes.string,

/** Controls the submit button's visibility */
isSubmitButtonVisible: PropTypes.bool,
Expand Down Expand Up @@ -88,6 +88,9 @@ const propTypes = {
/** Information about the network */
network: networkPropTypes.isRequired,

/** Style for the error message for submit button */
errorMessageStyle: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),

...withLocalizePropTypes,
};

Expand All @@ -104,11 +107,13 @@ const defaultProps = {
shouldValidateOnBlur: true,
footerContent: null,
style: [],
errorMessageStyle: [],
submitButtonStyles: [],
validate: () => ({}),
submitButtonText: '',
};

function Form(props) {
const Form = forwardRef((props, forwardedRef) => {
const styles = useThemeStyles();
const [errors, setErrors] = useState({});
const [inputValues, setInputValues] = useState(() => ({...props.draftValues}));
Expand Down Expand Up @@ -245,6 +250,30 @@ function Form(props) {
onSubmit(trimmedStringValues);
}, [props.formState.isLoading, props.network.isOffline, props.enabledWhenOffline, inputValues, onValidate, onSubmit]);

/**
* Resets the form
*/
const resetForm = useCallback(
(optionalValue) => {
_.each(inputValues, (inputRef, inputID) => {
setInputValues((prevState) => {
const copyPrevState = _.clone(prevState);

touchedInputs.current[inputID] = false;
copyPrevState[inputID] = optionalValue[inputID] || '';

return copyPrevState;
});
});
setErrors({});
},
[inputValues],
);

useImperativeHandle(forwardedRef, () => ({
resetForm,
}));

/**
* Loops over Form's children and automatically supplies Form props to them
*
Expand Down Expand Up @@ -464,7 +493,9 @@ function Form(props) {
containerStyles={[styles.mh0, styles.mt5, styles.flex1, ...props.submitButtonStyles]}
enabledWhenOffline={props.enabledWhenOffline}
isSubmitActionDangerous={props.isSubmitActionDangerous}
useSmallerSubmitButtonSize={props.useSmallerSubmitButtonSize}
disablePressOnEnter
errorMessageStyle={props.errorMessageStyle}
/>
)}
</FormSubmit>
Expand All @@ -474,6 +505,8 @@ function Form(props) {
props.style,
props.isSubmitButtonVisible,
props.submitButtonText,
props.useSmallerSubmitButtonSize,
props.errorMessageStyle,
props.formState.errorFields,
props.formState.isLoading,
props.footerContent,
Expand Down Expand Up @@ -539,7 +572,7 @@ function Form(props) {
}
</SafeAreaConsumer>
);
}
});

Form.displayName = 'Form';
Form.propTypes = propTypes;
Expand Down
Loading
Loading