Skip to content

Commit

Permalink
Changes to display value
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapawar1 committed Dec 7, 2024
1 parent a80be48 commit 37e2e86
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ type DropdownProps<T extends string[]> = {
options: T;
setValue: (value: T[number]) => any;
value: string;
displayValue?: (s: string) => string;
};

type Option = {
i: number;
label: string;
value: string;
i: number;
};

function Dropdown<T extends string[]>({
options,
setValue,
value,
displayValue = s => s,
}: DropdownProps<T>) {
return (
<View>
Expand All @@ -33,10 +36,10 @@ function Dropdown<T extends string[]>({
dropdownPosition="bottom"
iconStyle={styles.iconStyle}
data={options.map((option: T[number], i: number) => {
return { i, value: option };
return { i, label: displayValue(option), value: option };
})}
maxHeight={400}
labelField="value"
labelField="label"
valueField="value"
placeholder="Select..."
value={value}
Expand All @@ -57,7 +60,7 @@ function Dropdown<T extends string[]>({
},
]}
>
{item.value}
{item.label}
</Text>
);
}}
Expand Down
24 changes: 17 additions & 7 deletions src/components/TreeEdit/TreeEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import SvgRepeat from '@/icons/Repeat';
import SvgUser from '@/icons/User';
import colors from '@/styles/colors';
import { updateTree } from '@/supabase/queries/trees';
import { Tree, TreeHealth, TreeReservedFor } from '@/types/tree';
import {
Tree,
TreeHealth,
TreeProductionStatus,
TreeReservedFor,
} from '@/types/tree';
import Dropdown from '../Dropdown/Dropdown';
import styles from './styles';

Expand All @@ -25,6 +30,8 @@ export default function TreeEdit({ treeData, setTreeData }: TreeEditProps) {
text => text.charAt(0).toUpperCase() + text.substring(1).toLowerCase(),
);

const displayValue = (s: string) => titleCase(s.replace('_', ' '));

const saveTreeData = async () => {
setIsEditing(false);
if (typeof treeData.row !== 'number') return;
Expand Down Expand Up @@ -108,6 +115,7 @@ export default function TreeEdit({ treeData, setTreeData }: TreeEditProps) {
{isEditing ? (
<Dropdown
options={Object.values(TreeHealth)}
displayValue={displayValue}
setValue={value =>
setTreeData({ ...treeData, health_status: value })
}
Expand All @@ -117,7 +125,7 @@ export default function TreeEdit({ treeData, setTreeData }: TreeEditProps) {
<View style={styles.iconTextView}>
<SvgHeart />
<Text style={[styles.displayText, styles.greenText]}>
{titleCase(treeData.health_status ?? '')}
{displayValue(treeData.health_status ?? '')}
</Text>
</View>
)}
Expand All @@ -127,17 +135,18 @@ export default function TreeEdit({ treeData, setTreeData }: TreeEditProps) {
<Text style={styles.label}>Production Status</Text>
{isEditing ? (
<Dropdown
options={Object.values(TreeReservedFor)}
options={Object.values(TreeProductionStatus)}
displayValue={displayValue}
setValue={value =>
setTreeData({ ...treeData, reserved_for: value })
setTreeData({ ...treeData, production_status: value })
}
value={treeData.reserved_for ?? ''}
value={treeData.production_status ?? ''}
/>
) : (
<View style={styles.iconTextView}>
<SvgRepeat />
<Text style={[styles.displayText, styles.greenText]}>
{titleCase(treeData.reserved_for ?? '')}
{displayValue(treeData.reserved_for ?? '')}
</Text>
</View>
)}
Expand All @@ -148,6 +157,7 @@ export default function TreeEdit({ treeData, setTreeData }: TreeEditProps) {
{isEditing ? (
<Dropdown
options={Object.values(TreeReservedFor)}
displayValue={displayValue}
setValue={value =>
setTreeData({ ...treeData, reserved_for: value })
}
Expand All @@ -157,7 +167,7 @@ export default function TreeEdit({ treeData, setTreeData }: TreeEditProps) {
<View style={styles.iconTextView}>
<SvgUser />
<Text style={[styles.displayText, styles.greenText]}>
{titleCase(treeData.reserved_for ?? '')}
{displayValue(treeData.reserved_for ?? '')}
</Text>
</View>
)}
Expand Down
7 changes: 7 additions & 0 deletions src/types/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type Tree = {
sold?: boolean;
reserved?: boolean;
reserved_for?: TreeReservedFor;
production_status?: TreeProductionStatus;
street_ready?: boolean;
required_action?: string;
source?: string;
Expand All @@ -28,4 +29,10 @@ export enum TreeHealth {
export enum TreeReservedFor {
Resident = 'resident',
CommunityPlanting = 'community_planting',
Sold = 'sold',
}

export enum TreeProductionStatus {
InProduction = 'in_production',
StreetReady = 'street_ready',
}

0 comments on commit 37e2e86

Please sign in to comment.