2024-07-31 19:01:45 +02:00
|
|
|
import { product_type_t } from "@/lib/dimensions";
|
|
|
|
import { PRODUCT_TYPES, Product } from "@/lib/product";
|
2024-06-27 23:31:59 +02:00
|
|
|
import Ionicons from "@expo/vector-icons/Ionicons";
|
2024-07-31 19:01:45 +02:00
|
|
|
import { StyleSheet, TextInput, TouchableHighlight, View } from "react-native";
|
|
|
|
import SelectDropdown from "react-native-select-dropdown";
|
2024-06-27 23:31:59 +02:00
|
|
|
|
2024-06-30 18:37:27 +02:00
|
|
|
export type ProductAttributeChangeFunc = (key: string, newValue: string) => any;
|
|
|
|
export type ProductAttributeDeleteFunc = (key: string) => any;
|
2024-07-31 19:01:45 +02:00
|
|
|
export type ChangeAttributeFunction = (oldKey: string, newKey: string) => any;
|
|
|
|
export type ProductTypeChangeFunc = (
|
|
|
|
key: string,
|
|
|
|
newProductType: product_type_t
|
|
|
|
) => any;
|
2024-06-27 23:31:59 +02:00
|
|
|
|
2024-06-30 18:37:27 +02:00
|
|
|
export type ProductAttributeProps = {
|
2024-07-31 19:01:45 +02:00
|
|
|
attributeKey: string;
|
|
|
|
attributeValue: string;
|
|
|
|
onProductTypeChange?: ProductTypeChangeFunc;
|
|
|
|
onChangeAttributeKey?: ChangeAttributeFunction;
|
|
|
|
onChangeAttribute?: ProductAttributeChangeFunc;
|
|
|
|
onDelete?: ProductAttributeChangeFunc;
|
2024-06-30 18:37:27 +02:00
|
|
|
};
|
2024-06-27 23:31:59 +02:00
|
|
|
|
2024-07-31 19:01:45 +02:00
|
|
|
const select_product_type_choices = PRODUCT_TYPES.map((p) => [p, p]);
|
2024-06-27 23:31:59 +02:00
|
|
|
|
2024-07-31 19:01:45 +02:00
|
|
|
export const ProductAttributeEditor = ({
|
|
|
|
attributeKey,
|
|
|
|
attributeValue,
|
|
|
|
onDelete,
|
|
|
|
onChangeAttributeKey,
|
|
|
|
onChangeAttribute,
|
|
|
|
}: ProductAttributeProps) => {
|
|
|
|
const doChangeKey = (e: any) => {
|
|
|
|
onChangeAttributeKey && onChangeAttributeKey(attributeKey, e);
|
|
|
|
};
|
2024-06-30 18:37:27 +02:00
|
|
|
|
2024-07-31 19:01:45 +02:00
|
|
|
const doChangeValue = (e: any) => {
|
|
|
|
onChangeAttribute && onChangeAttribute(attributeKey, e);
|
|
|
|
};
|
2024-06-27 23:31:59 +02:00
|
|
|
|
2024-07-31 19:01:45 +02:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<View style={styles.productAttributeRow}>
|
|
|
|
<TextInput
|
|
|
|
defaultValue={attributeKey}
|
|
|
|
onChangeText={doChangeKey}
|
|
|
|
style={styles.value}
|
|
|
|
aria-label="Edit Key"
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
defaultValue={attributeValue}
|
|
|
|
onChangeText={doChangeValue}
|
|
|
|
style={styles.value}
|
|
|
|
aria-label="Edit Value"
|
|
|
|
/>
|
|
|
|
<TouchableHighlight
|
|
|
|
onPress={() => onDelete && onDelete(attributeKey, attributeValue)}
|
|
|
|
aria-label="Delete Attribute"
|
|
|
|
style={{
|
|
|
|
backgroundColor: "darkred",
|
|
|
|
borderRadius: 5,
|
|
|
|
margin: 5,
|
|
|
|
padding: 5,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Ionicons name="trash-bin-outline" size={30} color={"white"} />
|
|
|
|
</TouchableHighlight>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
2024-06-27 23:31:59 +02:00
|
|
|
|
2024-06-29 15:09:22 +02:00
|
|
|
const styles = StyleSheet.create({
|
2024-07-31 19:01:45 +02:00
|
|
|
productAttributeRow: {
|
|
|
|
flexDirection: "row",
|
|
|
|
},
|
|
|
|
key: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
flex: 1,
|
|
|
|
borderWidth: 1,
|
|
|
|
borderColor: "grey",
|
|
|
|
borderStyle: "solid",
|
|
|
|
padding: 10,
|
|
|
|
},
|
|
|
|
});
|