-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29541 from Expensify/vit-27836followup
Allow Welcome Message on Room Creation
- Loading branch information
Showing
7 changed files
with
235 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, {useState, useEffect} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import _ from 'lodash'; | ||
import CONST from '../../CONST'; | ||
import HeaderWithBackButton from '../HeaderWithBackButton'; | ||
import SelectionList from '../SelectionList'; | ||
import Modal from '../Modal'; | ||
import ScreenWrapper from '../ScreenWrapper'; | ||
import styles from '../../styles/styles'; | ||
|
||
const propTypes = { | ||
/** Whether the modal is visible */ | ||
isVisible: PropTypes.bool.isRequired, | ||
|
||
/** Current value selected */ | ||
currentValue: PropTypes.string, | ||
|
||
/** Items to pick from */ | ||
items: PropTypes.arrayOf(PropTypes.shape({value: PropTypes.string, label: PropTypes.string})), | ||
|
||
/** The selected item */ | ||
selectedItem: PropTypes.shape({value: PropTypes.string, label: PropTypes.string}), | ||
|
||
/** Label for values */ | ||
label: PropTypes.string, | ||
|
||
/** Function to call when the user selects a item */ | ||
onItemSelected: PropTypes.func, | ||
|
||
/** Function to call when the user closes the modal */ | ||
onClose: PropTypes.func, | ||
}; | ||
|
||
const defaultProps = { | ||
currentValue: '', | ||
items: [], | ||
selectedItem: {}, | ||
label: '', | ||
onClose: () => {}, | ||
onItemSelected: () => {}, | ||
}; | ||
|
||
function ValueSelectorModal({currentValue, items, selectedItem, label, isVisible, onClose, onItemSelected}) { | ||
const [sectionsData, setSectionsData] = useState([]); | ||
|
||
useEffect(() => { | ||
const itemsData = _.map(items, (item) => ({value: item.value, keyForList: item.value, text: item.label, isSelected: item === selectedItem})); | ||
setSectionsData(itemsData); | ||
}, [items, selectedItem]); | ||
|
||
return ( | ||
<Modal | ||
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED} | ||
isVisible={isVisible} | ||
onClose={onClose} | ||
onModalHide={onClose} | ||
hideModalContentWhileAnimating | ||
useNativeDriver | ||
> | ||
<ScreenWrapper | ||
style={[styles.pb0]} | ||
includePaddingTop={false} | ||
includeSafeAreaPaddingBottom={false} | ||
testID="ValueSelectorModal" | ||
> | ||
<HeaderWithBackButton | ||
title={label} | ||
onBackButtonPress={onClose} | ||
/> | ||
<SelectionList | ||
sections={[{data: sectionsData}]} | ||
onSelectRow={onItemSelected} | ||
initiallyFocusedOptionKey={currentValue} | ||
/> | ||
</ScreenWrapper> | ||
</Modal> | ||
); | ||
} | ||
|
||
ValueSelectorModal.propTypes = propTypes; | ||
ValueSelectorModal.defaultProps = defaultProps; | ||
ValueSelectorModal.displayName = 'ValueSelectorModal'; | ||
|
||
export default ValueSelectorModal; |
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,102 @@ | ||
import React, {useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import _ from 'lodash'; | ||
import styles from '../../styles/styles'; | ||
import MenuItemWithTopDescription from '../MenuItemWithTopDescription'; | ||
import ValueSelectorModal from './ValueSelectorModal'; | ||
import FormHelpMessage from '../FormHelpMessage'; | ||
import refPropTypes from '../refPropTypes'; | ||
|
||
const propTypes = { | ||
/** Form Error description */ | ||
errorText: PropTypes.string, | ||
|
||
/** Item to display */ | ||
value: PropTypes.string, | ||
|
||
/** A placeholder value to display */ | ||
placeholder: PropTypes.string, | ||
|
||
/** Items to pick from */ | ||
items: PropTypes.arrayOf(PropTypes.shape({value: PropTypes.string, label: PropTypes.string})), | ||
|
||
/** Label of picker */ | ||
label: PropTypes.string, | ||
|
||
/** Callback to call when the input changes */ | ||
onInputChange: PropTypes.func, | ||
|
||
/** A ref to forward to MenuItemWithTopDescription */ | ||
forwardedRef: refPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
value: undefined, | ||
label: undefined, | ||
placeholder: '', | ||
items: {}, | ||
forwardedRef: undefined, | ||
errorText: '', | ||
onInputChange: () => {}, | ||
}; | ||
|
||
function ValuePicker({value, label, items, placeholder, errorText, onInputChange, forwardedRef}) { | ||
const [isPickerVisible, setIsPickerVisible] = useState(false); | ||
|
||
const showPickerModal = () => { | ||
setIsPickerVisible(true); | ||
}; | ||
|
||
const hidePickerModal = () => { | ||
setIsPickerVisible(false); | ||
}; | ||
|
||
const updateInput = (item) => { | ||
if (item.value !== value) { | ||
onInputChange(item.value); | ||
} | ||
hidePickerModal(); | ||
}; | ||
|
||
const descStyle = value.length === 0 ? styles.textNormal : null; | ||
const selectedItem = _.find(items, {value}); | ||
const selectedLabel = selectedItem ? selectedItem.label : ''; | ||
|
||
return ( | ||
<View> | ||
<MenuItemWithTopDescription | ||
ref={forwardedRef} | ||
shouldShowRightIcon | ||
title={selectedLabel || placeholder || ''} | ||
descriptionTextStyle={descStyle} | ||
description={label} | ||
onPress={showPickerModal} | ||
/> | ||
<View style={styles.ml5}> | ||
<FormHelpMessage message={errorText} /> | ||
</View> | ||
<ValueSelectorModal | ||
isVisible={isPickerVisible} | ||
currentValue={selectedLabel || placeholder || ''} | ||
label={label} | ||
selectedItem={selectedItem} | ||
items={items} | ||
onClose={hidePickerModal} | ||
onItemSelected={updateInput} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
ValuePicker.propTypes = propTypes; | ||
ValuePicker.defaultProps = defaultProps; | ||
ValuePicker.displayName = 'ValuePicker'; | ||
|
||
export default React.forwardRef((props, ref) => ( | ||
<ValuePicker | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
forwardedRef={ref} | ||
/> | ||
)); |
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
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