add attributes
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import {Image, StyleSheet, KeyboardAvoidingView, Platform, ActivityIndicator} from "react-native";
|
import {
|
||||||
|
Image,
|
||||||
|
StyleSheet,
|
||||||
|
KeyboardAvoidingView,
|
||||||
|
Platform,
|
||||||
|
ActivityIndicator,
|
||||||
|
} from "react-native";
|
||||||
import { Button, ButtonText } from "@/components/ui/button";
|
import { Button, ButtonText } from "@/components/ui/button";
|
||||||
import { FormControl } from "@/components/ui/form-control";
|
import { FormControl } from "@/components/ui/form-control";
|
||||||
import { Input, InputField } from "@/components/ui/input";
|
import { Input, InputField } from "@/components/ui/input";
|
||||||
@@ -36,6 +42,7 @@ export default function CreateNotice() {
|
|||||||
const [image, setImage] = useState([]);
|
const [image, setImage] = useState([]);
|
||||||
const [selectItems, setSelectItems] = useState([]);
|
const [selectItems, setSelectItems] = useState([]);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [selectedAttributes, setSelectedAttributes] = useState({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isMounted = true;
|
let isMounted = true;
|
||||||
@@ -77,6 +84,35 @@ export default function CreateNotice() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const attributes = {
|
||||||
|
Kolor: [
|
||||||
|
"Zielony",
|
||||||
|
"Czerwony",
|
||||||
|
"Niebieski",
|
||||||
|
"Żółty",
|
||||||
|
"Biały",
|
||||||
|
"Czarny",
|
||||||
|
"Różowy",
|
||||||
|
"Szary",
|
||||||
|
"Fioletowy",
|
||||||
|
"Pomarańczowy",
|
||||||
|
"Inny",
|
||||||
|
],
|
||||||
|
Materiał: [
|
||||||
|
"Bawełna",
|
||||||
|
"Wełna",
|
||||||
|
"Syntetyk",
|
||||||
|
"Skóra",
|
||||||
|
"Len",
|
||||||
|
"Jedwab",
|
||||||
|
"Poliester",
|
||||||
|
"Akryl",
|
||||||
|
"Wiskoza",
|
||||||
|
"Nylon",
|
||||||
|
"Inny",
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
const handleAddNotice = async () => {
|
const handleAddNotice = async () => {
|
||||||
setError({
|
setError({
|
||||||
title: !title,
|
title: !title,
|
||||||
@@ -89,7 +125,13 @@ export default function CreateNotice() {
|
|||||||
console.log("Error in form");
|
console.log("Error in form");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const formattedAttributes = Object.entries(selectedAttributes).map(
|
||||||
|
([name, value]) => ({
|
||||||
|
name: name,
|
||||||
|
value: value,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
// console.log("Selected attributes:", formattedAttributes);
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
const result = await addNotice({
|
const result = await addNotice({
|
||||||
@@ -99,6 +141,7 @@ export default function CreateNotice() {
|
|||||||
category: category,
|
category: category,
|
||||||
status: "INACTIVE",
|
status: "INACTIVE",
|
||||||
image: image,
|
image: image,
|
||||||
|
attributes: formattedAttributes,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -150,6 +193,7 @@ export default function CreateNotice() {
|
|||||||
setPrice("");
|
setPrice("");
|
||||||
setCategory("");
|
setCategory("");
|
||||||
setImage([]);
|
setImage([]);
|
||||||
|
setSelectedAttributes({});
|
||||||
setError({
|
setError({
|
||||||
title: false,
|
title: false,
|
||||||
description: false,
|
description: false,
|
||||||
@@ -162,7 +206,7 @@ export default function CreateNotice() {
|
|||||||
return (
|
return (
|
||||||
<Box className="items-center justify-center flex-1">
|
<Box className="items-center justify-center flex-1">
|
||||||
<ActivityIndicator size="large" color="#787878" />
|
<ActivityIndicator size="large" color="#787878" />
|
||||||
<Text size="md" bold="true" className='mt-5'>
|
<Text size="md" bold="true" className="mt-5">
|
||||||
Dodajemy ogłoszenie...
|
Dodajemy ogłoszenie...
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
@@ -171,9 +215,9 @@ export default function CreateNotice() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
behavior={Platform.OS === "ios" ? "padding" : "height"}
|
||||||
style={{ flex: 1 }}
|
style={{ flex: 1 }}
|
||||||
keyboardVerticalOffset={Platform.OS === 'ios' ? 64 : 0}
|
keyboardVerticalOffset={Platform.OS === "ios" ? 64 : 0}
|
||||||
>
|
>
|
||||||
<ScrollView h="$80" w="$80">
|
<ScrollView h="$80" w="$80">
|
||||||
<FormControl className="p-4 border rounded-lg border-outline-300">
|
<FormControl className="p-4 border rounded-lg border-outline-300">
|
||||||
@@ -265,6 +309,42 @@ export default function CreateNotice() {
|
|||||||
</SelectPortal>
|
</SelectPortal>
|
||||||
</Select>
|
</Select>
|
||||||
</VStack>
|
</VStack>
|
||||||
|
|
||||||
|
{Object.entries(attributes).map(([label, options]) => (
|
||||||
|
<VStack key={label} space="xs">
|
||||||
|
<Text className="text-typography-500">{label}</Text>
|
||||||
|
<Select
|
||||||
|
onValueChange={(value) =>
|
||||||
|
setSelectedAttributes((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[label]: value,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<SelectTrigger variant="outline" size="md">
|
||||||
|
<SelectInput
|
||||||
|
placeholder={`Wybierz ${label.toLowerCase()}`}
|
||||||
|
/>
|
||||||
|
<SelectIcon className="mr-3" as={ChevronDownIcon} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectPortal>
|
||||||
|
<SelectBackdrop />
|
||||||
|
<SelectContent style={{ maxHeight: 400 }}>
|
||||||
|
<SelectScrollView>
|
||||||
|
{options.map((option) => (
|
||||||
|
<SelectItem
|
||||||
|
key={option}
|
||||||
|
label={option}
|
||||||
|
value={option}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</SelectScrollView>
|
||||||
|
</SelectContent>
|
||||||
|
</SelectPortal>
|
||||||
|
</Select>
|
||||||
|
</VStack>
|
||||||
|
))}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
className="mt-5 w-full"
|
className="mt-5 w-full"
|
||||||
onPress={handleAddNotice}
|
onPress={handleAddNotice}
|
||||||
|
|||||||
Reference in New Issue
Block a user