Refine receipt item expense selection
This commit is contained in:
@@ -33,7 +33,7 @@ export function ReceiptItemSelector({
|
|||||||
}: ReceiptItemSelectorProps) {
|
}: ReceiptItemSelectorProps) {
|
||||||
const { colors } = useAppTheme();
|
const { colors } = useAppTheme();
|
||||||
const [selectedIds, setSelectedIds] = useState<Set<string>>(
|
const [selectedIds, setSelectedIds] = useState<Set<string>>(
|
||||||
() => new Set(items.map((item) => item.id)),
|
() => new Set(items.length === 1 ? [items[0]!.id] : []),
|
||||||
);
|
);
|
||||||
|
|
||||||
const calculation = useMemo(() => {
|
const calculation = useMemo(() => {
|
||||||
@@ -84,10 +84,11 @@ export function ReceiptItemSelector({
|
|||||||
<View style={styles.header}>
|
<View style={styles.header}>
|
||||||
<View style={styles.headerCopy}>
|
<View style={styles.headerCopy}>
|
||||||
<Text style={[styles.title, { color: colors.foreground }]}>
|
<Text style={[styles.title, { color: colors.foreground }]}>
|
||||||
Split receipt items
|
Select expense items
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={[styles.subtitle, { color: colors.mutedForeground }]}>
|
<Text style={[styles.subtitle, { color: colors.mutedForeground }]}>
|
||||||
Select what this person owes. Tax is split proportionally.
|
Pick only the receipt lines that should become this expense. Tax is
|
||||||
|
split proportionally.
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text style={[styles.total, { color: colors.foreground }]}>
|
<Text style={[styles.total, { color: colors.foreground }]}>
|
||||||
@@ -95,6 +96,39 @@ export function ReceiptItemSelector({
|
|||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{items.length > 1 ? (
|
||||||
|
<View style={styles.bulkActions}>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
onPress={() =>
|
||||||
|
setSelectedIds(new Set(items.map((item) => item.id)))
|
||||||
|
}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
styles.bulkAction,
|
||||||
|
pressed && styles.pressed,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Text style={[styles.bulkActionText, { color: colors.primary }]}>
|
||||||
|
Select all
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
onPress={() => setSelectedIds(new Set())}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
styles.bulkAction,
|
||||||
|
pressed && styles.pressed,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={[styles.bulkActionText, { color: colors.mutedForeground }]}
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<View style={styles.itemList}>
|
<View style={styles.itemList}>
|
||||||
{items.map((item) => {
|
{items.map((item) => {
|
||||||
const selected = selectedIds.has(item.id);
|
const selected = selectedIds.has(item.id);
|
||||||
@@ -137,7 +171,11 @@ export function ReceiptItemSelector({
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
title="Apply owed amount"
|
title={
|
||||||
|
calculation.selected.length === 0
|
||||||
|
? "Select an item to apply"
|
||||||
|
: "Apply selected items"
|
||||||
|
}
|
||||||
disabled={calculation.selected.length === 0}
|
disabled={calculation.selected.length === 0}
|
||||||
onPress={() =>
|
onPress={() =>
|
||||||
onApply({
|
onApply({
|
||||||
@@ -218,6 +256,18 @@ const styles = StyleSheet.create({
|
|||||||
itemList: {
|
itemList: {
|
||||||
gap: spacing.sm,
|
gap: spacing.sm,
|
||||||
},
|
},
|
||||||
|
bulkActions: {
|
||||||
|
flexDirection: "row",
|
||||||
|
gap: spacing.sm,
|
||||||
|
},
|
||||||
|
bulkAction: {
|
||||||
|
minHeight: 34,
|
||||||
|
justifyContent: "center",
|
||||||
|
},
|
||||||
|
bulkActionText: {
|
||||||
|
fontFamily: fonts.bodyMedium,
|
||||||
|
fontSize: 13,
|
||||||
|
},
|
||||||
item: {
|
item: {
|
||||||
minHeight: 48,
|
minHeight: 48,
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user