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

Move violation message below billable field #36533

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 11 additions & 9 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,22 +395,24 @@ function MoneyRequestView({
)}

{shouldShowBillable && (
<>
<View style={[styles.flexRow, styles.optionRow, styles.justifyContentBetween, styles.alignItemsCenter, styles.ml5, styles.mr8]}>
<View style={[styles.flexRow, styles.optionRow, styles.justifyContentBetween, styles.alignItemsCenter, styles.ml5, styles.mr8]}>
<View>
<Text color={!transactionBillable ? theme.textSupporting : undefined}>{translate('common.billable')}</Text>
<Switch
accessibilityLabel={translate('common.billable')}
isOn={!!transactionBillable}
onToggle={saveBillable}
/>
{getErrorForField('billable') && (
{!!getErrorForField('billable') && (
<ViolationMessages
violations={getViolationsForField('billable')}
containerStyle={[styles.mt1]}
textStyle={[styles.ph0]}
isLast
/>
)}
</View>
</>
<Switch
accessibilityLabel={translate('common.billable')}
isOn={!!transactionBillable}
onToggle={saveBillable}
/>
</View>
)}
</View>
<SpacerView
Expand Down
9 changes: 6 additions & 3 deletions src/components/ViolationMessages.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import React, {useMemo} from 'react';
import {View} from 'react-native';
import type {StyleProp, TextStyle, ViewStyle} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import ViolationsUtils from '@libs/Violations/ViolationsUtils';
import type {TransactionViolation} from '@src/types/onyx';
import Text from './Text';

export default function ViolationMessages({violations, isLast}: {violations: TransactionViolation[]; isLast?: boolean}) {
type ViolationMessagesProps = {violations: TransactionViolation[]; isLast?: boolean; containerStyle?: StyleProp<ViewStyle>; textStyle?: StyleProp<TextStyle>};

export default function ViolationMessages({violations, isLast, containerStyle, textStyle}: ViolationMessagesProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const violationMessages = useMemo(() => violations.map((violation) => [violation.name, ViolationsUtils.getViolationTranslation(violation, translate)]), [translate, violations]);

return (
<View style={[styles.mtn2, isLast ? styles.mb2 : styles.mb1]}>
<View style={[styles.mtn2, isLast ? styles.mb2 : styles.mb1, containerStyle]}>
{violationMessages.map(([name, message]) => (
<Text
key={`violationMessages.${name}`}
style={[styles.ph5, styles.textLabelError]}
style={[styles.ph5, styles.textLabelError, textStyle]}
>
{message}
</Text>
Expand Down
Loading