2023-07-19 19:47:01 +00:00
|
|
|
import React from 'react';
|
2022-09-22 21:31:23 +00:00
|
|
|
import { StyleSheet, Text } from 'react-native';
|
|
|
|
|
|
|
|
import * as List from '../../containers/List';
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { useTheme } from '../../theme';
|
|
|
|
import sharedStyles from '../Styles';
|
|
|
|
import { OPTIONS } from './options';
|
|
|
|
import { CustomIcon } from '../../containers/CustomIcon';
|
|
|
|
import { useActionSheet } from '../../containers/ActionSheet';
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
pickerText: {
|
|
|
|
...sharedStyles.textRegular,
|
|
|
|
fontSize: 16
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
type TKey = 'desktopNotifications' | 'pushNotifications' | 'emailNotificationMode';
|
|
|
|
|
|
|
|
interface IBaseParams {
|
|
|
|
preference: TKey;
|
|
|
|
value: string;
|
2023-07-19 19:47:01 +00:00
|
|
|
onChangeValue: (param: { [key: string]: string }) => void;
|
2022-09-22 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ListPicker = ({
|
|
|
|
preference,
|
|
|
|
value,
|
|
|
|
title,
|
|
|
|
testID,
|
|
|
|
onChangeValue
|
|
|
|
}: {
|
|
|
|
title: string;
|
|
|
|
testID: string;
|
|
|
|
} & IBaseParams) => {
|
|
|
|
const { showActionSheet, hideActionSheet } = useActionSheet();
|
|
|
|
const { colors } = useTheme();
|
2023-07-19 19:47:01 +00:00
|
|
|
const option = value ? OPTIONS[preference].find(option => option.value === value) : OPTIONS[preference][0];
|
2022-09-22 21:31:23 +00:00
|
|
|
|
|
|
|
const getOptions = () =>
|
|
|
|
OPTIONS[preference].map(i => ({
|
|
|
|
title: I18n.t(i.label, { defaultValue: i.label }),
|
|
|
|
onPress: () => {
|
|
|
|
hideActionSheet();
|
2023-07-19 19:47:01 +00:00
|
|
|
onChangeValue({ [preference]: i.value.toString() });
|
2022-09-22 21:31:23 +00:00
|
|
|
},
|
|
|
|
right: option?.value === i.value ? () => <CustomIcon name={'check'} size={20} color={colors.tintActive} /> : undefined
|
|
|
|
}));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<List.Item
|
|
|
|
title={title}
|
|
|
|
testID={testID}
|
|
|
|
onPress={() => showActionSheet({ options: getOptions() })}
|
|
|
|
right={() => (
|
|
|
|
<Text style={[styles.pickerText, { color: colors.actionTintColor }]}>
|
|
|
|
{option?.label ? I18n.t(option?.label, { defaultValue: option?.label }) : option?.label}
|
|
|
|
</Text>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ListPicker;
|