-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Refactor/23149 money request page #23979
Merged
marcaaron
merged 39 commits into
Expensify:main
from
koko57:refactor/23149-money-request-page
Aug 4, 2023
Merged
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
c9c2851
refactor: wip - create separate new and edit pages
koko57 bac5cc2
refactor: wip - remove refs
koko57 3b25e19
refactor: move util functions to a separate file, remove old MoneyReq…
koko57 bb7af06
refactor: wip - remove unnecessary code in page and form components
koko57 432880a
Merge branch 'main' into refactor/23149-money-request-page
koko57 868f979
refactor: wip - proptypes for the form, cleanup
koko57 098e31d
fix: fix input forwardedRef proptype
koko57 b530026
refactor: wip - proptypes, cleanup
koko57 9d71022
refactor: remove old money request page
koko57 9a0e29b
fix: fix linting error
koko57 4d6228f
fix: apply requested changes
koko57 27c7323
fix: apply requested changes
koko57 829af04
fix: fix forwardedRef
koko57 9c1e0c9
fix: minor fix
koko57 dfb4aa0
fix: minor fix
koko57 fd54d6f
Merge branch 'main' into refactor/23149-money-request-page
koko57 fe12a74
fix: fix currency changing problem
koko57 fbf5e4c
fix: restore handling several tabs logic
koko57 26331e2
fix: fix linting error
koko57 742de9f
fix: run prettier
koko57 10333ff
fix: rename money utils functions param, move getNewSelection to Mone…
koko57 6c2393d
fix: restore modal closing logic, remove current property
koko57 6212539
fix: add missing dep
koko57 a0f0e72
refactor: move screen wrapper and header to parent component
koko57 8f749e4
fix: restore inner refs
koko57 e1b552c
fix: apply requested changes
koko57 ec7d54c
fix: apply requested changes
koko57 013193d
fix: apply requested changes
koko57 586105c
fix: minor fix
koko57 33a9812
fix: bug fix
koko57 4d58a9d
refactor: wrap fullpagenotfoundview into screenwrapper
koko57 863d37b
fix: resolve conflicts
koko57 45754a8
fix: change the old money amount page for the new one
koko57 5b3fa95
fix: remove old money amount page
koko57 d0fd9dc
fix: resolve conflicts
koko57 f1b908f
fix: render screen wrapper only when editing amount
koko57 53a6f6e
fix: change title for step for iou.amount
koko57 81d595f
fix: apply requested changes
koko57 014b326
fix: apply requested changes
koko57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import lodashGet from 'lodash/get'; | ||
import CONST from '../CONST'; | ||
import _ from 'underscore'; | ||
|
||
/** | ||
* Returns the new selection object based on the updated amount's length | ||
* | ||
* @param {Object} oldSelection | ||
* @param {Number} prevLength | ||
* @param {Number} newLength | ||
* @returns {Object} | ||
*/ | ||
const getNewSelection = (oldSelection, prevLength, newLength) => { | ||
const cursorPosition = oldSelection.end + (newLength - prevLength); | ||
return {start: cursorPosition, end: cursorPosition}; | ||
}; | ||
|
||
/** | ||
* Strip comma from the amount | ||
* | ||
* @param {String} newAmount | ||
* @returns {String} | ||
*/ | ||
const stripCommaFromAmount = (newAmount) => newAmount.replace(/,/g, ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB, can we rename the parameter to |
||
|
||
/** | ||
* Strip spaces from the amount | ||
* | ||
* @param {String} newAmount | ||
* @returns {String} | ||
*/ | ||
const stripSpacesFromAmount = (newAmount) => newAmount.replace(/\s+/g, ''); | ||
|
||
/** | ||
* Adds a leading zero to the amount if user entered just the decimal separator | ||
* | ||
* @param {String} newAmount - Changed amount from user input | ||
* @returns {String} | ||
*/ | ||
const addLeadingZero = (newAmount) => (newAmount === '.' ? '0.' : newAmount); | ||
|
||
/** | ||
* @param {String} newAmount | ||
koko57 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @returns {Number} | ||
*/ | ||
const calculateAmountLength = (newAmount) => { | ||
const leadingZeroes = newAmount.match(/^0+/); | ||
const leadingZeroesLength = lodashGet(leadingZeroes, '[0].length', 0); | ||
const absAmount = parseFloat((stripCommaFromAmount(newAmount) * 100).toFixed(2)).toString(); | ||
|
||
// The following logic will prevent users from pasting an amount that is excessively long in length, | ||
// which would result in the 'absAmount' value being expressed in scientific notation or becoming infinity. | ||
if (/\D/.test(absAmount)) { | ||
return CONST.IOU.AMOUNT_MAX_LENGTH + 1; | ||
} | ||
|
||
// Return the sum of leading zeroes length and absolute amount length(including fraction digits). | ||
// When the absolute amount is 0, add 2 to the leading zeroes length to represent fraction digits. | ||
return leadingZeroesLength + (absAmount === '0' ? 2 : absAmount.length); | ||
}; | ||
|
||
/** | ||
* Check if amount is a decimal up to 3 digits | ||
* | ||
* @param {String} newAmount | ||
* @returns {Boolean} | ||
*/ | ||
const validateAmount = (newAmount) => { | ||
const decimalNumberRegex = new RegExp(/^\d+(,\d+)*(\.\d{0,2})?$/, 'i'); | ||
return newAmount === '' || (decimalNumberRegex.test(newAmount) && calculateAmountLength(newAmount) <= CONST.IOU.AMOUNT_MAX_LENGTH); | ||
}; | ||
|
||
/** | ||
* Replaces each character by calling `convertFn`. If `convertFn` throws an error, then | ||
* the original character will be preserved. | ||
* | ||
* @param {String} text | ||
* @param {Function} convertFn - `fromLocaleDigit` or `toLocaleDigit` | ||
* @returns {String} | ||
*/ | ||
const replaceAllDigits = (text, convertFn) => | ||
_.chain([...text]) | ||
.map((char) => { | ||
try { | ||
return convertFn(char); | ||
} catch { | ||
return char; | ||
} | ||
}) | ||
.join('') | ||
.value(); | ||
|
||
export {getNewSelection, stripCommaFromAmount, stripSpacesFromAmount, addLeadingZero, validateAmount, replaceAllDigits}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems too specific to belong to Utils.