Compare commits
24 Commits
53be0b2f50
...
authentica
| Author | SHA1 | Date | |
|---|---|---|---|
| d4133f28bd | |||
| b6f2225148 | |||
| 8dc51fafdf | |||
| 1862b6b79e | |||
| 9962dc1e55 | |||
| 00fbe8b655 | |||
| 532183b305 | |||
| a7cf31900b | |||
|
|
0295386dac | ||
|
|
6598faf5e8 | ||
| 47e5d80792 | |||
| 54db5eadf3 | |||
| 845a2e9593 | |||
| 1a8fe7bb1d | |||
| 50450ccd76 | |||
| 04778c4d78 | |||
| e197319d9b | |||
| 0a7be2e27b | |||
| 05916b959c | |||
| 37c273a746 | |||
| b8ca34f736 | |||
| 490bcc7585 | |||
| 657f307c30 | |||
| 580715947d |
0
ArtisanConnect/api/auth.jsx
Normal file
0
ArtisanConnect/api/auth.jsx
Normal file
12
ArtisanConnect/api/categories.jsx
Normal file
12
ArtisanConnect/api/categories.jsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import axios from "axios";
|
||||
|
||||
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||
|
||||
export async function listCategories() {
|
||||
try {
|
||||
const response = await axios.get(`${API_URL}/vars/categories`);
|
||||
return response.data;
|
||||
} catch (err) {
|
||||
console.error("Nie udało się pobrać listy kategorii.", err.response.status);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,122 @@
|
||||
const API_URL = "https://testowe.zikor.pl/api/v1/notices/";
|
||||
import axios from "axios";
|
||||
import FormData from 'form-data'
|
||||
import {useAuthStore} from "@/store/authStore";
|
||||
|
||||
// const API_URL = "https://testowe.zikor.pl/api/v1";
|
||||
|
||||
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||
|
||||
export async function listNotices() {
|
||||
const response = await fetch(`${API_URL}get/all`);
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error("Error");
|
||||
}
|
||||
return data;
|
||||
const { token } = useAuthStore.getState();
|
||||
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||
|
||||
const response = await fetch(`${API_URL}/notices/get/all`, {
|
||||
headers: headers
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(response.toString());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getNoticeById(noticeId) {
|
||||
const response = await fetch(`${API_URL}get/${noticeId}`);
|
||||
const response = await fetch(`${API_URL}/notices/get/${noticeId}`);
|
||||
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error("Error");
|
||||
}
|
||||
return data;
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error("Error");
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function createNotice(notice) {
|
||||
// console.log("Notice created", notice);
|
||||
const response = await fetch(`${API_URL}add`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(notice),
|
||||
});
|
||||
console.log("Response", response);
|
||||
if (!response.ok) {
|
||||
throw new Error("Error");
|
||||
}
|
||||
try {
|
||||
const response = await axios.post(`${API_URL}/notices/add`, notice, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (response.data.noticeId !== null) {
|
||||
for (const imageUri of notice.image) {
|
||||
await uploadImage(response.data.noticeId, imageUri);
|
||||
}
|
||||
}
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.log("Error", error.response.data, error.response.status);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getImageByNoticeId(noticeId) {
|
||||
let imageUrl;
|
||||
try {
|
||||
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`);
|
||||
|
||||
const imageName = listResponse.data[0];
|
||||
imageUrl = `${API_URL}/images/get/${imageName}`;
|
||||
|
||||
return imageUrl;
|
||||
} catch (err) {
|
||||
console.log(`Zdjęcie nie istnieje dla notice o id: ${noticeId}`);
|
||||
imageUrl = "https://http.cat/404.jpg";
|
||||
return imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllImagesByNoticeId(noticeId) {
|
||||
try {
|
||||
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`);
|
||||
|
||||
if (listResponse.data && listResponse.data.length > 0) {
|
||||
return listResponse.data.map(imageName =>
|
||||
`${API_URL}/images/get/${imageName}`
|
||||
);
|
||||
}
|
||||
|
||||
return ["https://http.cat/404.jpg"];
|
||||
} catch (err) {
|
||||
if(err.response.status === 404) {
|
||||
console.info(`Ogłoszenie o id: ${noticeId} nie posiada zdjęć.`);
|
||||
return ["https://http.cat/404.jpg"];
|
||||
}
|
||||
console.warn(`Nie udało się pobrać listy zdjęć dla ogłoszenia o id: ${noticeId}`, err);
|
||||
return ["https://http.cat/404.jpg"];
|
||||
}
|
||||
}
|
||||
|
||||
export const uploadImage = async (noticeId, imageUri) => {
|
||||
const formData = new FormData();
|
||||
|
||||
const filename = imageUri.split('/').pop();
|
||||
|
||||
const match = /\.(\w+)$/.exec(filename);
|
||||
const type = match ? `image/${match[1]}` : 'image/jpeg';
|
||||
|
||||
formData.append('file', {
|
||||
uri: imageUri,
|
||||
name: filename,
|
||||
type: type,
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`${API_URL}/images/upload/${noticeId}`,
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
}
|
||||
);
|
||||
console.info('Upload successful:', response.data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.log("imageURI:", imageUri);
|
||||
console.error('Error uploading image:', error.response.data, error.response.status);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"expo": {
|
||||
"name": "ArtisanConnect",
|
||||
"slug": "ArtisanConnect",
|
||||
"scheme": "Artisanconnect",
|
||||
"scheme": "com.hamx.artisanconnect",
|
||||
"version": "1.0.0",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/icon.png",
|
||||
@@ -14,19 +14,44 @@
|
||||
"backgroundColor": "#ffffff"
|
||||
},
|
||||
"ios": {
|
||||
"supportsTablet": true
|
||||
"supportsTablet": true,
|
||||
"bundleIdentifier": "com.hamx.artisanconnect"
|
||||
},
|
||||
"android": {
|
||||
"adaptiveIcon": {
|
||||
"foregroundImage": "./assets/adaptive-icon.png",
|
||||
"backgroundColor": "#ffffff"
|
||||
}
|
||||
},
|
||||
"permissions": [
|
||||
"android.permission.RECORD_AUDIO",
|
||||
"android.permission.CAMERA"
|
||||
],
|
||||
"package": "com.hamx.artisanconnect"
|
||||
},
|
||||
"web": {
|
||||
"favicon": "./assets/favicon.png"
|
||||
},
|
||||
"plugins": [
|
||||
"expo-router"
|
||||
]
|
||||
"expo-router",
|
||||
[
|
||||
"expo-image-picker",
|
||||
{
|
||||
"photosPermission": "The app accesses your photos to let you share them with your friends."
|
||||
}
|
||||
],
|
||||
[
|
||||
"expo-camera",
|
||||
{
|
||||
"cameraPermission": "Please allow $(PRODUCT_NAME) to access your camera"
|
||||
}
|
||||
],
|
||||
"expo-web-browser"
|
||||
],
|
||||
"extra": {
|
||||
"router": {},
|
||||
"eas": {
|
||||
"projectId": "7a0d8bc8-938f-4d2a-babb-945faee13429"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,75 @@
|
||||
import { Tabs } from "expo-router";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import {Tabs} from "expo-router";
|
||||
import {Ionicons} from "@expo/vector-icons";
|
||||
|
||||
export default function TabLayout() {
|
||||
return (
|
||||
<Tabs
|
||||
screenOptions={{
|
||||
tabBarActiveTintColor: "rgb(var(--color-primary-500))",
|
||||
}}
|
||||
>
|
||||
<Tabs.Screen
|
||||
name="index"
|
||||
options={{
|
||||
title: "Home",
|
||||
tabBarLabel: "Home",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="home-outline" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="notices"
|
||||
options={{
|
||||
title: "Ogłoszenia",
|
||||
tabBarLabel: "Ogłoszenia",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="list-outline" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="notice/create"
|
||||
options={{
|
||||
title: "Dodaj",
|
||||
tabBarLabel: "Dodaj",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="add-circle-outline" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="wishlist"
|
||||
options={{
|
||||
title: "Ulubione",
|
||||
tabBarLabel: "Ulubione",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="heart-outline" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="account"
|
||||
options={{
|
||||
title: "Konto",
|
||||
tabBarLabel: "Konto",
|
||||
tabBarIcon: ({ color, size }) => (
|
||||
<Ionicons name="person-outline" size={size} color={color} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</Tabs>
|
||||
);
|
||||
return (
|
||||
<Tabs
|
||||
screenOptions={{
|
||||
tabBarActiveTintColor: "rgb(var(--color-primary-500))",
|
||||
}}
|
||||
>
|
||||
<Tabs.Screen
|
||||
name="index"
|
||||
options={{
|
||||
title: "Home",
|
||||
tabBarLabel: "Home",
|
||||
tabBarIcon: ({color, size}) => (
|
||||
<Ionicons name="home-outline" size={size} color={color}/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="notices"
|
||||
options={{
|
||||
title: "Ogłoszenia",
|
||||
tabBarLabel: "Ogłoszenia",
|
||||
tabBarIcon: ({color, size}) => (
|
||||
<Ionicons name="list-outline" size={size} color={color}/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="notice/create"
|
||||
options={{
|
||||
title: "Dodaj",
|
||||
tabBarLabel: "Dodaj",
|
||||
tabBarIcon: ({color, size}) => (
|
||||
<Ionicons name="add-circle-outline" size={size} color={color}/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="wishlist"
|
||||
options={{
|
||||
title: "Ulubione",
|
||||
tabBarLabel: "Ulubione",
|
||||
tabBarIcon: ({color, size}) => (
|
||||
<Ionicons name="heart-outline" size={size} color={color}/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="login"
|
||||
options={{
|
||||
headerShown: false, // Ukryj nagłówek dla Drawer
|
||||
title: "Authentication",
|
||||
tabBarLabel: "Authentication",
|
||||
tabBarIcon: ({color, size}) => (
|
||||
<Ionicons name="key" size={size} color={color}/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
name="dashboard"
|
||||
options={{
|
||||
headerShown: false, // Ukryj nagłówek dla Drawer
|
||||
title: "Konto",
|
||||
tabBarLabel: "Konto",
|
||||
tabBarIcon: ({color, size}) => (
|
||||
<Ionicons name="person-outline" size={size} color={color}/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
|
||||
24
ArtisanConnect/app/(tabs)/dashboard/_layout.jsx
Normal file
24
ArtisanConnect/app/(tabs)/dashboard/_layout.jsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Drawer } from "expo-router/drawer";
|
||||
|
||||
export default function AccountDrawerLayout() {
|
||||
return (
|
||||
<Drawer
|
||||
screenOptions={{
|
||||
drawerActiveTintColor: "#1c1c1e",
|
||||
drawerInactiveTintColor: "#8e8e8f",
|
||||
drawerActiveBackgroundColor: "#f0f0f0",
|
||||
drawerItemStyle: {
|
||||
borderRadius: 8,
|
||||
// backgroundColor: "transparent",
|
||||
},
|
||||
headerTintColor: "#1c1c1e",
|
||||
}}
|
||||
>
|
||||
<Drawer.Screen name="account" options={{ title: "Konto" }} />
|
||||
<Drawer.Screen
|
||||
name="userNotices"
|
||||
options={{ title: "Moje ogłoszenia" }}
|
||||
/>
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
4
ArtisanConnect/app/(tabs)/dashboard/userNotices.jsx
Normal file
4
ArtisanConnect/app/(tabs)/dashboard/userNotices.jsx
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Text } from "@/components/ui/text";
|
||||
export default function UserNotices() {
|
||||
return <Text>Użytkownik</Text>;
|
||||
}
|
||||
180
ArtisanConnect/app/(tabs)/login.jsx
Normal file
180
ArtisanConnect/app/(tabs)/login.jsx
Normal file
@@ -0,0 +1,180 @@
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import {StyleSheet, ActivityIndicator, SafeAreaView, View, Platform} from 'react-native';
|
||||
import {useAuthStore} from '@/store/authStore';
|
||||
import {useRouter, Link} from 'expo-router';
|
||||
|
||||
import {Box} from "@/components/ui/box"
|
||||
import {Button, ButtonText, ButtonIcon} from "@/components/ui/button"
|
||||
import {Center} from "@/components/ui/center"
|
||||
import {Heading} from "@/components/ui/heading"
|
||||
import {Input, InputField} from "@/components/ui/input"
|
||||
import {Text} from "@/components/ui/text"
|
||||
import {VStack} from "@/components/ui/vstack"
|
||||
import {HStack} from "@/components/ui/hstack"
|
||||
import {ArrowRightIcon} from "@/components/ui/icon"
|
||||
import {Divider} from '@/components/ui/divider';
|
||||
import {Ionicons} from "@expo/vector-icons";
|
||||
|
||||
import * as WebBrowser from 'expo-web-browser';
|
||||
import * as Google from "expo-auth-session/providers/google";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import {makeRedirectUri} from "expo-auth-session";
|
||||
|
||||
import Constants from 'expo-constants';
|
||||
|
||||
WebBrowser.maybeCompleteAuthSession();
|
||||
|
||||
// client_id ios 936418008320-ohefdfcebd41f6oa2o8phh1mgj9s49sl.apps.googleusercontent.com
|
||||
// android 936418008320-d8dfjph5e4r28fcm1rbdfbh5phmbg03d.apps.googleusercontent.com
|
||||
|
||||
export default function Login() {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const {signIn, isLoading, signInWithGoogle} = useAuthStore();
|
||||
const router = useRouter();
|
||||
|
||||
const [request, response, promptAsync] = Google.useAuthRequest({
|
||||
androidClientId: "936418008320-d8dfjph5e4r28fcm1rbdfbh5phmbg03d.apps.googleusercontent.com",
|
||||
iosClientId: "936418008320-ohefdfcebd41f6oa2o8phh1mgj9s49sl.apps.googleusercontent.com",
|
||||
webClientId: "936418008320-btdngtlfnjac1p67guje72m9el5q59a7.apps.googleusercontent.com",
|
||||
redirectUri:
|
||||
Platform.OS === 'android'
|
||||
? makeRedirectUri({
|
||||
scheme: Constants.expoConfig.android.package,
|
||||
path: '/',
|
||||
})
|
||||
: undefined,
|
||||
})
|
||||
|
||||
const handleInternalLogin = async () => {
|
||||
if (!email || !password) {
|
||||
alert('Proszę wprowadzić email i hasło.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await signIn(email, password);
|
||||
alert(`Zalogowano jako ${email}`);
|
||||
router.replace('/');
|
||||
} catch (e) {
|
||||
alert("Błąd logowania: " + (e.response?.data?.message || e.message));
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
handleGoogleLogin();
|
||||
}, [response]);
|
||||
|
||||
const handleGoogleLogin = async () => {
|
||||
// const user = await AsyncStorage.getItem("@user");
|
||||
let user = null;
|
||||
if (!user) {
|
||||
if(response.type === "success") {
|
||||
user = await getUserInfo(response.authentication.accessToken)
|
||||
await signInWithGoogle(response.authentication.accessToken);
|
||||
alert(`Zalogowano jako ${user.email}`);
|
||||
}
|
||||
|
||||
} else {
|
||||
console.info("Pobrano użytkownika z AsyncStorage:", JSON.parse(user));
|
||||
alert(`Zalogowano jako ${user.email}`);
|
||||
}
|
||||
};
|
||||
|
||||
const getUserInfo = async (token) => {
|
||||
if(!token) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const response = await fetch("https://www.googleapis.com/userinfo/v2/me",
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
}
|
||||
);
|
||||
const user = await response.json();
|
||||
await AsyncStorage.setItem("@user", JSON.stringify(user));
|
||||
return user;
|
||||
} catch (error) {
|
||||
console.error("Błąd podczas pobierania informacji o użytkowniku:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<ActivityIndicator size="large"/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={styles.container}>
|
||||
<Center>
|
||||
<Box className="p-5 max-w-96 border border-background-300 rounded-lg">
|
||||
<VStack className="pb-4" space="xs">
|
||||
<Heading className="leading-[30px]">Logowanie</Heading>
|
||||
<Box className="flex flex-row">
|
||||
<Link href="/registration" asChild>
|
||||
<Button variant="link" size="sm" className="p-0">
|
||||
<ButtonText style={styles.signupbutton}>Nie masz jeszcze konta? Załóz je
|
||||
tutaj!</ButtonText>
|
||||
<ButtonIcon className="mr-1" size="md" as={ArrowRightIcon}/>
|
||||
</Button>
|
||||
</Link>
|
||||
</Box>
|
||||
</VStack>
|
||||
<VStack space="xl" className="py-2">
|
||||
<Input>
|
||||
<InputField className="py-2" placeholder="Login" onChangeText={setEmail}/>
|
||||
</Input>
|
||||
<Input>
|
||||
<InputField type="password" className="py-2" placeholder="Hasło"
|
||||
onChangeText={setPassword}/>
|
||||
</Input>
|
||||
</VStack>
|
||||
<VStack space="lg" className="pt-4">
|
||||
<Button size="sm" onPress={handleInternalLogin}>
|
||||
<ButtonText>Zaloguj się</ButtonText>
|
||||
</Button>
|
||||
</VStack>
|
||||
|
||||
<HStack alignItems="center" space="sm" className="pt-6 pb-6">
|
||||
<Divider flex={1}/>
|
||||
<Text fontSize="$sm" className="text-gray-300">
|
||||
lub
|
||||
</Text>
|
||||
<Divider flex={1}/>
|
||||
</HStack>
|
||||
<Button size="sm" onPress={() => promptAsync()}>
|
||||
<Ionicons name="logo-google" color="#fff"/>
|
||||
</Button>
|
||||
</Box>
|
||||
</Center>
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
padding: 20,
|
||||
},
|
||||
input: {
|
||||
borderWidth: 1,
|
||||
borderColor: '#ddd',
|
||||
borderRadius: 5,
|
||||
marginBottom: 15,
|
||||
padding: 10,
|
||||
},
|
||||
errorText: {
|
||||
color: 'red',
|
||||
marginBottom: 10,
|
||||
},
|
||||
signupbutton: {
|
||||
fontWeight: '300',
|
||||
},
|
||||
});
|
||||
@@ -1,142 +1,256 @@
|
||||
import { useState } from "react";
|
||||
import { Button, ButtonText } from "@/components/ui/button";
|
||||
import { FormControl } from "@/components/ui/form-control";
|
||||
import { Input, InputField } from "@/components/ui/input";
|
||||
import { Text } from "@/components/ui/text";
|
||||
import { VStack } from "@/components/ui/vstack";
|
||||
import { Textarea, TextareaInput } from "@/components/ui/textarea";
|
||||
import {useState, useEffect} from "react";
|
||||
import {Image, StyleSheet} from "react-native";
|
||||
import {Button, ButtonText} from "@/components/ui/button";
|
||||
import {FormControl} from "@/components/ui/form-control";
|
||||
import {Input, InputField} from "@/components/ui/input";
|
||||
import {Text} from "@/components/ui/text";
|
||||
import {VStack} from "@/components/ui/vstack";
|
||||
import {Textarea, TextareaInput} from "@/components/ui/textarea";
|
||||
import {ScrollView} from '@gluestack-ui/themed';
|
||||
import * as ImagePicker from 'expo-image-picker';
|
||||
import {
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectInput,
|
||||
SelectIcon,
|
||||
SelectPortal,
|
||||
SelectBackdrop,
|
||||
SelectContent,
|
||||
SelectDragIndicator,
|
||||
SelectDragIndicatorWrapper,
|
||||
SelectItem,
|
||||
Select,
|
||||
SelectTrigger,
|
||||
SelectInput,
|
||||
SelectIcon,
|
||||
SelectPortal,
|
||||
SelectBackdrop,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectScrollView,
|
||||
} from "@/components/ui/select";
|
||||
|
||||
import { ChevronDownIcon } from "@/components/ui/icon";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { createNotice } from "@/api/notices";
|
||||
import {ChevronDownIcon} from "@/components/ui/icon";
|
||||
import {useNoticesStore} from "@/store/noticesStore";
|
||||
import {listCategories} from "@/api/categories";
|
||||
import {useRouter} from "expo-router";
|
||||
|
||||
export default function CreateNotice() {
|
||||
const [title, setTitle] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [price, setPrice] = useState("");
|
||||
const [category, setCategory] = useState("");
|
||||
const [error, setError] = useState({
|
||||
title: false,
|
||||
description: false,
|
||||
price: false,
|
||||
category: false,
|
||||
});
|
||||
const router = useRouter();
|
||||
const {addNotice, fetchNotices} = useNoticesStore();
|
||||
const [title, setTitle] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [price, setPrice] = useState("");
|
||||
const [category, setCategory] = useState("");
|
||||
const [image, setImage] = useState([]);
|
||||
const [selectItems, setSelectItems] = useState([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const noticeMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
createNotice({
|
||||
title: title,
|
||||
clientId: 1,
|
||||
description: description,
|
||||
price: parseFloat(price),
|
||||
category: category,
|
||||
status: "ACTIVE",
|
||||
}),
|
||||
onSuccess: () => {
|
||||
console.log("Notice created successfully");
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Error creating notice");
|
||||
},
|
||||
});
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
|
||||
const addNotice = () => {
|
||||
setError({
|
||||
title: !title,
|
||||
description: !description,
|
||||
price: !price,
|
||||
category: !category,
|
||||
const fetchSelectItems = async () => {
|
||||
try {
|
||||
let data = await listCategories();
|
||||
if (isMounted && Array.isArray(data)) {
|
||||
setSelectItems(data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching select items:', error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchSelectItems();
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const [error, setError] = useState({
|
||||
title: false,
|
||||
description: false,
|
||||
price: false,
|
||||
category: false,
|
||||
});
|
||||
|
||||
if (!title || !description || !price || !category) {
|
||||
console.log("Error in form");
|
||||
return;
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
image: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
});
|
||||
|
||||
const handleAddNotice = async () => {
|
||||
setError({
|
||||
title: !title,
|
||||
description: !description,
|
||||
price: !price,
|
||||
category: !category,
|
||||
});
|
||||
|
||||
if (!title || !description || !price || !category) {
|
||||
console.log("Error in form");
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const result = await addNotice({
|
||||
title: title,
|
||||
clientId: 1,
|
||||
description: description,
|
||||
price: price,
|
||||
category: category,
|
||||
status: "ACTIVE",
|
||||
image: image
|
||||
});
|
||||
|
||||
if (result) {
|
||||
console.log("Notice created successfully with ID: ", result.noticeId);
|
||||
await fetchNotices();
|
||||
clearForm();
|
||||
router.push("/(tabs)/notices");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error creating notice. Error message: ", error.message);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const takePicture = async () => {
|
||||
const {status} = await ImagePicker.requestCameraPermissionsAsync();
|
||||
if (status !== 'granted') {
|
||||
return;
|
||||
}
|
||||
const result = await ImagePicker.launchCameraAsync({
|
||||
allowsEditing: false,
|
||||
});
|
||||
|
||||
if (!result.canceled && result.assets) {
|
||||
setImage(result.assets.map(asset => asset.uri));
|
||||
}
|
||||
}
|
||||
noticeMutation.mutate();
|
||||
};
|
||||
|
||||
return (
|
||||
<FormControl className="p-4 border rounded-lg border-outline-300">
|
||||
<VStack space="xl">
|
||||
<VStack space="xs">
|
||||
<Text className="text-typography-500">Tytuł</Text>
|
||||
<Input className="min-w-[250px]" isInvalid={error.title}>
|
||||
<InputField
|
||||
type="text"
|
||||
value={title}
|
||||
onChangeText={(value) => setTitle(value)}
|
||||
/>
|
||||
</Input>
|
||||
</VStack>
|
||||
const pickImage = async () => {
|
||||
let result = await ImagePicker.launchImageLibraryAsync({
|
||||
mediaTypes: 'images',
|
||||
selectionLimit: 8,
|
||||
allowsEditing: false,
|
||||
allowsMultipleSelection: true,
|
||||
aspect: [4, 3],
|
||||
quality: 0.5,
|
||||
});
|
||||
|
||||
<VStack space="xs">
|
||||
<Text className="text-typography-500">Opis</Text>
|
||||
<Textarea
|
||||
size="md"
|
||||
className="min-w-[250px] "
|
||||
isInvalid={error.description}
|
||||
>
|
||||
<TextareaInput
|
||||
placeholder="Opisz produkt"
|
||||
value={description}
|
||||
onChangeText={(value) => setDescription(value)}
|
||||
/>
|
||||
</Textarea>
|
||||
</VStack>
|
||||
if (!result.canceled) {
|
||||
setImage(result.assets.map(asset => asset.uri));
|
||||
}
|
||||
};
|
||||
|
||||
<VStack space="xs">
|
||||
<Text className="text-typography-500">Cena</Text>
|
||||
<Input className="min-w-[250px]" isInvalid={error.price}>
|
||||
<InputField
|
||||
type="text"
|
||||
value={price}
|
||||
onChangeText={(value) => setPrice(value)}
|
||||
/>
|
||||
</Input>
|
||||
</VStack>
|
||||
<VStack space="xs">
|
||||
<Text className="text-typography-500">Kategoria</Text>
|
||||
<Select
|
||||
onValueChange={(value) => setCategory(value)}
|
||||
isInvalid={error.category}
|
||||
>
|
||||
<SelectTrigger variant="outline" size="md">
|
||||
<SelectInput placeholder="Wybierz kategorię" />
|
||||
<SelectIcon className="mr-3" as={ChevronDownIcon} />
|
||||
</SelectTrigger>
|
||||
<SelectPortal>
|
||||
<SelectBackdrop />
|
||||
<SelectContent>
|
||||
<SelectDragIndicatorWrapper>
|
||||
<SelectDragIndicator />
|
||||
</SelectDragIndicatorWrapper>
|
||||
<SelectItem label="Meble" value="Furniture" />
|
||||
<SelectItem label="Biżuteria" value="Jewelry" />
|
||||
<SelectItem label="Ceramika" value="Ceramics" />
|
||||
</SelectContent>
|
||||
</SelectPortal>
|
||||
</Select>
|
||||
</VStack>
|
||||
<Button
|
||||
className="ml-auto"
|
||||
onPress={() => addNotice()}
|
||||
disabled={noticeMutation.isLoading}
|
||||
>
|
||||
<ButtonText className="text-typography-0">Save</ButtonText>
|
||||
</Button>
|
||||
</VStack>
|
||||
</FormControl>
|
||||
);
|
||||
}
|
||||
const clearForm = () => {
|
||||
setTitle("");
|
||||
setDescription("");
|
||||
setPrice("");
|
||||
setCategory("");
|
||||
setImage([]);
|
||||
setError({
|
||||
title: false,
|
||||
description: false,
|
||||
price: false,
|
||||
category: false,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollView h="$80" w="$80">
|
||||
<FormControl className="p-4 border rounded-lg border-outline-300">
|
||||
<VStack space="xl">
|
||||
<VStack space="md">
|
||||
<Text className="text-typography-500">Zdjęcia</Text>
|
||||
<Button onPress={pickImage}>
|
||||
<ButtonText>
|
||||
Wybierz zdjęcia
|
||||
</ButtonText>
|
||||
</Button>
|
||||
<Button onPress={takePicture}>
|
||||
<ButtonText>Zrób zdjęcie</ButtonText>
|
||||
</Button>
|
||||
<Text size="sm"
|
||||
bold="true"
|
||||
>
|
||||
Pierwsze zdjęcie będzie zdjęciem głównym</Text>
|
||||
{image && image.length > 0 && (
|
||||
<VStack space="xs" className="flex-row flex-wrap">
|
||||
{image.map((img, index) => (
|
||||
<Image key={index} source={{uri: img}} style={styles.image} className="m-1"/>
|
||||
))}
|
||||
</VStack>
|
||||
)}
|
||||
</VStack>
|
||||
|
||||
<VStack space="xs">
|
||||
<Text className="text-typography-500">Tytuł</Text>
|
||||
<Input className="min-w-[250px]" isInvalid={error.title}>
|
||||
<InputField
|
||||
type="text"
|
||||
value={title}
|
||||
onChangeText={(value) => setTitle(value)}
|
||||
/>
|
||||
</Input>
|
||||
</VStack>
|
||||
|
||||
<VStack space="xs">
|
||||
<Text className="text-typography-500">Opis</Text>
|
||||
<Textarea
|
||||
size="md"
|
||||
className="min-w-[250px] "
|
||||
isInvalid={error.description}
|
||||
>
|
||||
<TextareaInput
|
||||
placeholder="Opisz produkt"
|
||||
value={description}
|
||||
onChangeText={(value) => setDescription(value)}
|
||||
/>
|
||||
</Textarea>
|
||||
</VStack>
|
||||
|
||||
<VStack space="xs">
|
||||
<Text className="text-typography-500">Cena</Text>
|
||||
<Input className="min-w-[250px]" isInvalid={error.price}>
|
||||
<InputField
|
||||
type="text"
|
||||
value={price}
|
||||
onChangeText={(value) => setPrice(value)}
|
||||
/>
|
||||
</Input>
|
||||
</VStack>
|
||||
<VStack space="xs">
|
||||
<Text className="text-typography-500">Kategoria</Text>
|
||||
<Select
|
||||
onValueChange={(value) => setCategory(value)}
|
||||
isInvalid={error.category}
|
||||
>
|
||||
<SelectTrigger variant="outline" size="md">
|
||||
<SelectInput placeholder="Wybierz kategorię"/>
|
||||
<SelectIcon className="mr-3" as={ChevronDownIcon}/>
|
||||
</SelectTrigger>
|
||||
<SelectPortal>
|
||||
<SelectBackdrop/>
|
||||
<SelectContent style={{maxHeight: 400}}>
|
||||
<SelectScrollView>
|
||||
{selectItems.map((item) => (
|
||||
<SelectItem key={item.value} label={item.label} value={item.value}/>
|
||||
))}
|
||||
</SelectScrollView>
|
||||
</SelectContent>
|
||||
</SelectPortal>
|
||||
</Select>
|
||||
</VStack>
|
||||
<Button
|
||||
className="mt-5 w-full"
|
||||
onPress={handleAddNotice}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<ButtonText className="text-typography-0">Dodaj</ButtonText>
|
||||
</Button>
|
||||
</VStack>
|
||||
</FormControl>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -1,30 +1,65 @@
|
||||
import { FlatList, Text, ActivityIndicator } from "react-native";
|
||||
import { listNotices } from "@/api/notices";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { NoticeCard } from "@/components/NoticeCard";
|
||||
import {FlatList, Text, ActivityIndicator, RefreshControl} from "react-native";
|
||||
import {useState, useEffect} from "react";
|
||||
import {useNoticesStore} from "@/store/noticesStore";
|
||||
import {NoticeCard} from "@/components/NoticeCard";
|
||||
|
||||
export default function Notices() {
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: ["notices"],
|
||||
queryFn: listNotices,
|
||||
});
|
||||
const {notices, fetchNotices} = useNoticesStore();
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
if (isLoading) {
|
||||
return <ActivityIndicator />;
|
||||
}
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
if (error) {
|
||||
return <Text>Błąd, spróbuj ponownie póżniej</Text>;
|
||||
}
|
||||
const loadData = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await fetchNotices();
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
setError(err);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
key={2}
|
||||
data={data}
|
||||
numColumns={2}
|
||||
columnContainerClassName="m-2"
|
||||
columnWrapperClassName="gap-2 m-2"
|
||||
renderItem={({ item }) => <NoticeCard notice={item} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
const onRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
await fetchNotices();
|
||||
} catch (err) {
|
||||
setError(err);
|
||||
} finally {
|
||||
setRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading && !refreshing) {
|
||||
return <ActivityIndicator/>;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <Text>Nie udało sie pobrać listy. {error.message}</Text>;
|
||||
}
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
key={2}
|
||||
data={notices}
|
||||
numColumns={2}
|
||||
columnContainerClassName="m-2"
|
||||
columnWrapperClassName="gap-2 m-2"
|
||||
renderItem={({item}) => <NoticeCard notice={item}/>}
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
refreshing={refreshing}
|
||||
onRefresh={onRefresh}
|
||||
colors={["#3b82f6"]}
|
||||
tintColor="#3b82f6"
|
||||
/>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Tabs, Stack } from "expo-router";
|
||||
import { Stack } from "expo-router";
|
||||
import "@/global.css";
|
||||
import { GluestackUIProvider } from "@/components/ui/gluestack-ui-provider";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
|
||||
@@ -1,67 +1,133 @@
|
||||
import { Stack, useLocalSearchParams } from "expo-router";
|
||||
import { Box } from "@/components/ui/box";
|
||||
import { Button, ButtonText } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Heading } from "@/components/ui/heading";
|
||||
import { Image } from "@/components/ui/image";
|
||||
import { Text } from "@/components/ui/text";
|
||||
import { VStack } from "@/components/ui/vstack";
|
||||
import { Icon, FavouriteIcon } from "@/components/ui/icon";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { getNoticeById } from "@/api/notices";
|
||||
import { ActivityIndicator } from "react-native";
|
||||
import {Stack, useLocalSearchParams} from "expo-router";
|
||||
import {Box} from "@/components/ui/box";
|
||||
import {Card} from "@/components/ui/card";
|
||||
import {Heading} from "@/components/ui/heading";
|
||||
import {Image} from "@/components/ui/image";
|
||||
import {Text} from "@/components/ui/text";
|
||||
import {VStack} from "@/components/ui/vstack";
|
||||
import {Ionicons} from "@expo/vector-icons";
|
||||
import {ActivityIndicator} from "react-native";
|
||||
import {useEffect, useState} from "react";
|
||||
import {useNoticesStore} from "@/store/noticesStore";
|
||||
import {useWishlist} from "@/store/wishlistStore";
|
||||
import {Pressable} from "react-native";
|
||||
|
||||
export default function NoticeDetails() {
|
||||
const { id } = useLocalSearchParams();
|
||||
const {id} = useLocalSearchParams();
|
||||
const [image, setImage] = useState(null);
|
||||
const [isImageLoading, setIsImageLoading] = useState(true);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
const [notice, setNotice] = useState(null);
|
||||
|
||||
const {
|
||||
data: notice,
|
||||
isLoading,
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ["notices", id],
|
||||
queryFn: () => getNoticeById(Number(id)),
|
||||
});
|
||||
const {getNoticeById, getAllImagesByNoticeId} = useNoticesStore();
|
||||
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
|
||||
const removeNoticeFromWishlist = useWishlist((state) => state.removeNoticeFromWishlist);
|
||||
const isInWishlist = useWishlist((state) =>
|
||||
notice ? state.wishlistNotices.some((item) => item.noticeId === notice.noticeId) : false
|
||||
);
|
||||
|
||||
if (isLoading) {
|
||||
return <ActivityIndicator />;
|
||||
}
|
||||
useEffect(() => {
|
||||
const fetchNotice = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const noticeData = getNoticeById(Number(id));
|
||||
if (noticeData) {
|
||||
setNotice(noticeData);
|
||||
setError(null);
|
||||
} else {
|
||||
setError(new Error(`Notice with ID ${id} not found.`));
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (error) {
|
||||
return <Text>Błąd, spróbuj ponownie póżniej</Text>;
|
||||
}
|
||||
fetchNotice();
|
||||
}, [id]);
|
||||
|
||||
return (
|
||||
<Card className="p-0 rounded-lg m-3 flex-1">
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: notice.title,
|
||||
}}
|
||||
/>
|
||||
<Image
|
||||
source={{
|
||||
uri: "https://gluestack.github.io/public-blog-video-assets/saree.png",
|
||||
}}
|
||||
className=" h-auto w-full rounded-md aspect-[1/1]"
|
||||
alt="image"
|
||||
resizeMode="cover"
|
||||
/>
|
||||
useEffect(() => {
|
||||
const fetchImage = async () => {
|
||||
setIsImageLoading(true);
|
||||
if (notice) {
|
||||
try {
|
||||
const images = await getAllImagesByNoticeId(notice.noticeId);
|
||||
setImage(images && images.length > 0 ? images[0] : "https://http.cat/404.jpg");
|
||||
} catch (err) {
|
||||
console.error("Error while loading images:", err);
|
||||
setImage("https://http.cat/404.jpg");
|
||||
} finally {
|
||||
setIsImageLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
<VStack className="p-2">
|
||||
<Text className="text-sm font-normal mb-2 text-typography-700">
|
||||
{notice.title}
|
||||
</Text>
|
||||
<Box className="flex-row items-center">
|
||||
<Heading size="md" className="flex-1">
|
||||
{notice.price}zł
|
||||
</Heading>
|
||||
<Icon
|
||||
as={FavouriteIcon}
|
||||
size="sm"
|
||||
className="text-primary-500 w-6 h-6"
|
||||
/>
|
||||
</Box>
|
||||
</VStack>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
if (notice) {
|
||||
fetchImage();
|
||||
}
|
||||
}, [notice]);
|
||||
|
||||
if (isLoading) {
|
||||
return <ActivityIndicator/>;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <Text>Błąd, spróbuj ponownie póżniej: {error.message}</Text>;
|
||||
}
|
||||
|
||||
if (!notice) {
|
||||
return <Text>Nie znaleziono ogłoszenia</Text>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="p-0 rounded-lg m-3 flex-1">
|
||||
<Stack.Screen
|
||||
options={{
|
||||
title: notice.title,
|
||||
}}
|
||||
/>
|
||||
{isImageLoading ? (
|
||||
<Box className="h-auto w-full rounded-md aspect-[1/1] bg-gray-100 items-center justify-center">
|
||||
<ActivityIndicator size="large" color="#3b82f6" />
|
||||
</Box>
|
||||
) : (
|
||||
<Image
|
||||
source={{
|
||||
uri: image,
|
||||
}}
|
||||
className="h-auto w-full rounded-md aspect-[1/1]"
|
||||
alt="image"
|
||||
resizeMode="cover"
|
||||
/>
|
||||
)}
|
||||
|
||||
<VStack className="p-2">
|
||||
<Text className="text-sm font-normal mb-2 text-typography-700">
|
||||
{notice.title}
|
||||
</Text>
|
||||
<Box className="flex-row items-center">
|
||||
<Heading size="md" className="flex-1">
|
||||
{notice.price}zł
|
||||
</Heading>
|
||||
<Pressable
|
||||
onPress={() => {
|
||||
if (isInWishlist) {
|
||||
removeNoticeFromWishlist(notice.noticeId);
|
||||
} else {
|
||||
addNoticeToWishlist(notice);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Ionicons
|
||||
name={isInWishlist ? "heart" : "heart-outline"}
|
||||
size={24}
|
||||
color={"primary-heading-500"}
|
||||
/>
|
||||
</Pressable>
|
||||
</Box>
|
||||
</VStack>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
96
ArtisanConnect/app/registration.jsx
Normal file
96
ArtisanConnect/app/registration.jsx
Normal file
@@ -0,0 +1,96 @@
|
||||
import React, {useState} from 'react';
|
||||
import {StyleSheet, ActivityIndicator, SafeAreaView, View} from 'react-native';
|
||||
import {useAuthStore} from '@/store/authStore';
|
||||
import {useRouter} from 'expo-router';
|
||||
|
||||
import {Box} from "@/components/ui/box"
|
||||
import {Button, ButtonText} from "@/components/ui/button"
|
||||
import {Center} from "@/components/ui/center"
|
||||
import {Heading} from "@/components/ui/heading"
|
||||
import {Input, InputField} from "@/components/ui/input"
|
||||
import {VStack} from "@/components/ui/vstack"
|
||||
|
||||
export default function Registration() {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [firstName, setFirstName] = useState('');
|
||||
const [lastName, setLastName] = useState('');
|
||||
const {signUp, isLoading} = useAuthStore();
|
||||
const router = useRouter();
|
||||
|
||||
const handleInternalRegistration = async () => {
|
||||
if (!email || !password || !firstName || !lastName) {
|
||||
alert('Proszę uzupełnić wszystkie pola');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await signUp({email, password, firstName, lastName});
|
||||
alert(`Zalogowano jako ${email}`);
|
||||
router.replace('/');
|
||||
} catch (e) {
|
||||
alert("Błąd logowania: " + (e.response?.data?.message || e.message));
|
||||
}
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<ActivityIndicator size="large"/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={styles.container}>
|
||||
<Center>
|
||||
<Box className="p-5 w-[80%] border border-background-300 rounded-lg">
|
||||
<VStack className="pb-4" space="xs">
|
||||
<Heading className="leading-[30px]">Rejestracja</Heading>
|
||||
</VStack>
|
||||
<VStack space="xl" className="py-2">
|
||||
<Input>
|
||||
<InputField type="email" className="py-2" placeholder="E-mail" onChangeText={setEmail}/>
|
||||
</Input>
|
||||
<Input>
|
||||
<InputField className="py-2" placeholder="Imię" onChangeText={setFirstName}/>
|
||||
</Input>
|
||||
<Input>
|
||||
<InputField className="py-2" placeholder="Nazwisko" onChangeText={setLastName}/>
|
||||
</Input>
|
||||
<Input>
|
||||
<InputField type="password" className="py-2" placeholder="Hasło"
|
||||
onChangeText={setPassword}/>
|
||||
</Input>
|
||||
</VStack>
|
||||
<VStack space="lg" className="pt-4">
|
||||
<Button size="sm" onPress={handleInternalRegistration}>
|
||||
<ButtonText>Zarejestruj się</ButtonText>
|
||||
</Button>
|
||||
</VStack>
|
||||
</Box>
|
||||
</Center>
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
},
|
||||
formContainer: {
|
||||
width: '80%',
|
||||
},
|
||||
input: {
|
||||
borderWidth: 1,
|
||||
borderColor: '#ddd',
|
||||
borderRadius: 5,
|
||||
marginBottom: 15,
|
||||
padding: 10,
|
||||
},
|
||||
errorText: {
|
||||
color: 'red',
|
||||
marginBottom: 10,
|
||||
},
|
||||
});
|
||||
@@ -1,62 +1,116 @@
|
||||
import { Box } from "@/components/ui/box";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Heading } from "@/components/ui/heading";
|
||||
import { Image } from "@/components/ui/image";
|
||||
import { Text } from "@/components/ui/text";
|
||||
import { VStack } from "@/components/ui/vstack";
|
||||
import { Link } from "expo-router";
|
||||
import { Pressable } from "react-native";
|
||||
import { useWishlist } from "@/store/wishlistStore";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import {Box} from "@/components/ui/box";
|
||||
import {Card} from "@/components/ui/card";
|
||||
import {Heading} from "@/components/ui/heading";
|
||||
import {Image} from "@/components/ui/image";
|
||||
import {Text} from "@/components/ui/text";
|
||||
import {VStack} from "@/components/ui/vstack";
|
||||
import {Link} from "expo-router";
|
||||
import {Pressable, ActivityIndicator, View} from "react-native";
|
||||
import {useWishlist} from "@/store/wishlistStore";
|
||||
import {useNoticesStore} from "@/store/noticesStore";
|
||||
import {Ionicons} from "@expo/vector-icons";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
export function NoticeCard({ notice }) {
|
||||
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
|
||||
const removeNoticeFromWishlist = useWishlist(
|
||||
(state) => state.removeNoticeFromWishlist
|
||||
);
|
||||
const isInWishlist = useWishlist((state) =>
|
||||
state.wishlistNotices.some((item) => item.noticeId == notice.noticeId)
|
||||
);
|
||||
export function NoticeCard({notice}) {
|
||||
const noticeId = notice?.noticeId;
|
||||
|
||||
return (
|
||||
<Link href={`/notice/${notice.noticeId}`} asChild>
|
||||
<Pressable className="flex-1">
|
||||
<Card className="p-0 rounded-lg max-w-[460px] flex-1">
|
||||
<Image
|
||||
source={{
|
||||
uri: "https://gluestack.github.io/public-blog-video-assets/saree.png",
|
||||
}}
|
||||
className=" h-auto w-full rounded-md aspect-[1/1]"
|
||||
alt="image"
|
||||
resizeMode="cover"
|
||||
/>
|
||||
<VStack className="p-2">
|
||||
<Text className="text-sm font-normal mb-2 text-typography-700">
|
||||
{notice.title}
|
||||
</Text>
|
||||
<Box className="flex-row items-center">
|
||||
<Heading size="md" className="flex-1">
|
||||
{notice.price}zł
|
||||
</Heading>
|
||||
<Pressable
|
||||
onPress={() => {
|
||||
if (isInWishlist) {
|
||||
removeNoticeFromWishlist(notice.noticeId); // Usuń z ulubionych
|
||||
} else {
|
||||
addNoticeToWishlist(notice); // Dodaj do ulubionych
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Ionicons
|
||||
name={isInWishlist ? "heart" : "heart-outline"} // Dynamiczna ikona
|
||||
size={24} // Rozmiar ikony
|
||||
color={"primary-heading-500"} // Kolor ikony
|
||||
/>
|
||||
</Pressable>
|
||||
</Box>
|
||||
</VStack>
|
||||
</Card>
|
||||
</Pressable>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
|
||||
const removeNoticeFromWishlist = useWishlist((state) => state.removeNoticeFromWishlist);
|
||||
const isInWishlist = useWishlist((state) =>
|
||||
noticeId ? state.wishlistNotices.some((item) => item.noticeId === noticeId) : false
|
||||
);
|
||||
|
||||
const [image, setImage] = useState(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const {getAllImagesByNoticeId} = useNoticesStore();
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
|
||||
const fetchImage = async () => {
|
||||
if (!noticeId) {
|
||||
if (isMounted) {
|
||||
setImage("https://http.cat/404.jpg");
|
||||
setIsLoading(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const images = await getAllImagesByNoticeId(noticeId);
|
||||
if (isMounted) {
|
||||
setImage(images && images.length > 0 ? images[0] : "https://http.cat/404.jpg");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error while loading image: ${error}`);
|
||||
if (isMounted) {
|
||||
setImage("https://http.cat/404.jpg");
|
||||
}
|
||||
} finally {
|
||||
if (isMounted) {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fetchImage();
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, [noticeId]);
|
||||
|
||||
if (!notice) {
|
||||
return <View style={{flex: 1}} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Link href={`/notice/${noticeId}`} asChild>
|
||||
<Pressable className="flex-1">
|
||||
<Card className="p-0 rounded-lg max-w-[460px] flex-1">
|
||||
{isLoading ? (
|
||||
<Box className="h-auto w-full rounded-md aspect-[1/1] bg-gray-100 items-center justify-center">
|
||||
<ActivityIndicator size="large" color="#3b82f6" />
|
||||
</Box>
|
||||
) : (
|
||||
<Image
|
||||
source={{
|
||||
uri: image,
|
||||
}}
|
||||
className="h-auto w-full rounded-md aspect-[1/1]"
|
||||
alt="image"
|
||||
resizeMode="cover"
|
||||
/>
|
||||
)}
|
||||
<VStack className="p-2">
|
||||
<Text className="text-sm font-normal mb-2 text-typography-700">
|
||||
{notice.title}
|
||||
</Text>
|
||||
<Box className="flex-row items-center">
|
||||
<Heading size="md" className="flex-1">
|
||||
{notice.price}zł
|
||||
</Heading>
|
||||
<Pressable
|
||||
onPress={() => {
|
||||
if (isInWishlist) {
|
||||
removeNoticeFromWishlist(noticeId);
|
||||
} else {
|
||||
addNoticeToWishlist(notice);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Ionicons
|
||||
name={isInWishlist ? "heart" : "heart-outline"}
|
||||
size={24}
|
||||
color={"primary-heading-500"}
|
||||
/>
|
||||
</Pressable>
|
||||
</Box>
|
||||
</VStack>
|
||||
</Card>
|
||||
</Pressable>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
21
ArtisanConnect/eas.json
Normal file
21
ArtisanConnect/eas.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"cli": {
|
||||
"version": ">= 16.8.0",
|
||||
"appVersionSource": "remote"
|
||||
},
|
||||
"build": {
|
||||
"development": {
|
||||
"developmentClient": true,
|
||||
"distribution": "internal"
|
||||
},
|
||||
"preview": {
|
||||
"distribution": "internal"
|
||||
},
|
||||
"production": {
|
||||
"autoIncrement": true
|
||||
}
|
||||
},
|
||||
"submit": {
|
||||
"production": {}
|
||||
}
|
||||
}
|
||||
12971
ArtisanConnect/package-lock.json
generated
12971
ArtisanConnect/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,9 +11,12 @@
|
||||
"dependencies": {
|
||||
"@expo/html-elements": "^0.4.2",
|
||||
"@expo/vector-icons": "^14.1.0",
|
||||
"@gluestack-style/react": "^1.0.57",
|
||||
"@gluestack-ui/actionsheet": "^0.2.53",
|
||||
"@gluestack-ui/button": "^1.0.14",
|
||||
"@gluestack-ui/divider": "^0.1.10",
|
||||
"@gluestack-ui/form-control": "^0.1.19",
|
||||
"@gluestack-ui/hstack": "^0.1.17",
|
||||
"@gluestack-ui/icon": "^0.1.27",
|
||||
"@gluestack-ui/image": "^0.1.17",
|
||||
"@gluestack-ui/input": "^0.1.38",
|
||||
@@ -21,32 +24,45 @@
|
||||
"@gluestack-ui/overlay": "^0.1.22",
|
||||
"@gluestack-ui/select": "^0.1.31",
|
||||
"@gluestack-ui/textarea": "^0.1.25",
|
||||
"@gluestack-ui/themed": "^1.1.73",
|
||||
"@gluestack-ui/toast": "^1.0.9",
|
||||
"@legendapp/motion": "^2.4.0",
|
||||
"@react-native-async-storage/async-storage": "2.1.2",
|
||||
"@react-native-community/cli-link-assets": "^18.0.0",
|
||||
"@react-navigation/drawer": "^7.3.11",
|
||||
"@tanstack/react-query": "^5.74.4",
|
||||
"axios": "^1.8.4",
|
||||
"axios": "^1.9.0",
|
||||
"babel-plugin-module-resolver": "^5.0.2",
|
||||
"expo": "~52.0.46",
|
||||
"expo-constants": "~17.0.8",
|
||||
"expo-linking": "~7.0.5",
|
||||
"expo-router": "~4.0.20",
|
||||
"expo-status-bar": "~2.0.1",
|
||||
"expo": "^53.0.0",
|
||||
"expo-auth-session": "~6.1.5",
|
||||
"expo-camera": "~16.1.6",
|
||||
"expo-constants": "~17.1.6",
|
||||
"expo-image-picker": "~16.1.4",
|
||||
"expo-linking": "~7.1.4",
|
||||
"expo-router": "~5.0.5",
|
||||
"expo-status-bar": "~2.2.3",
|
||||
"expo-web-browser": "~14.1.6",
|
||||
"form-data": "^4.0.2",
|
||||
"fs": "^0.0.1-security",
|
||||
"lucide-react-native": "^0.511.0",
|
||||
"nativewind": "^4.1.23",
|
||||
"react": "18.3.1",
|
||||
"react-dom": "18.3.1",
|
||||
"react-native": "0.76.9",
|
||||
"react": "19.0.0",
|
||||
"react-dom": "19.0.0",
|
||||
"react-native": "0.79.2",
|
||||
"react-native-css-interop": "^0.1.22",
|
||||
"react-native-reanimated": "^3.17.4",
|
||||
"react-native-safe-area-context": "^5.4.0",
|
||||
"react-native-screens": "~4.4.0",
|
||||
"react-native-svg": "^15.2.0",
|
||||
"react-native-web": "~0.19.13",
|
||||
"react-native-gesture-handler": "~2.24.0",
|
||||
"react-native-reanimated": "~3.17.4",
|
||||
"react-native-safe-area-context": "5.4.0",
|
||||
"react-native-screens": "~4.11.1",
|
||||
"react-native-svg": "15.11.2",
|
||||
"react-native-web": "~0.20.0",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"zustand": "^5.0.3"
|
||||
"zustand": "^5.0.3",
|
||||
"expo-crypto": "~14.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.0",
|
||||
"@types/react": "~18.3.12",
|
||||
"@types/react": "~19.0.10",
|
||||
"jscodeshift": "^0.15.2"
|
||||
},
|
||||
"private": true
|
||||
|
||||
105
ArtisanConnect/store/authStore.jsx
Normal file
105
ArtisanConnect/store/authStore.jsx
Normal file
@@ -0,0 +1,105 @@
|
||||
import {create} from "zustand";
|
||||
import {createJSONStorage, persist} from "zustand/middleware";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import axios from "axios";
|
||||
|
||||
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||
|
||||
export const useAuthStore = create(
|
||||
persist(
|
||||
(set) => ({
|
||||
user_id: null,
|
||||
token: null,
|
||||
isLoading: false,
|
||||
error: null,
|
||||
|
||||
signIn: async (email, password) => {
|
||||
set({isLoading: true, error: null});
|
||||
try {
|
||||
const response = await axios.post(`${API_URL}/auth/login`, {
|
||||
email,
|
||||
password
|
||||
});
|
||||
|
||||
const user_id = response.data.user_id;
|
||||
const token = response.data.token;
|
||||
set({user_id: user_id, token: token, isLoading: false});
|
||||
|
||||
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||
} catch (error) {
|
||||
set({error: error.response?.data?.message || error.message, isLoading: false});
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
signUp: async (userData) => {
|
||||
set({isLoading: true, error: null});
|
||||
try {
|
||||
const response = await axios.post(`${API_URL}/auth/register`, userData, {
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
});
|
||||
|
||||
const user_id = response.data.user_id;
|
||||
const token = response.data.token;
|
||||
set({user_id: user_id, token: token, isLoading: false});
|
||||
|
||||
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||
} catch (error) {
|
||||
set({error: error.response?.data?.message || error.message, isLoading: false});
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
signInWithGoogle: async (googleToken) => {
|
||||
set({isLoading: true, error: null});
|
||||
try {
|
||||
const response = await axios.post(`${API_URL}/auth/google`, {googleToken: googleToken}, {
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
});
|
||||
const user_id = response.data.user_id;
|
||||
const token = response.data.token;
|
||||
set({user_id: user_id, token: token, isLoading: false});
|
||||
|
||||
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||
} catch (error) {
|
||||
set({error: error.response?.data?.message || error.message, isLoading: false});
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
signOut: async () => {
|
||||
try {
|
||||
await axios.post(`${API_URL}/auth/logout`);
|
||||
} catch (error) {
|
||||
console.error("Logout error:", error);
|
||||
} finally {
|
||||
delete axios.defaults.headers.common["Authorization"];
|
||||
set({user_id: null, token: null});
|
||||
}
|
||||
},
|
||||
|
||||
checkAuth: async () => {
|
||||
const {token} = useAuthStore.getState();
|
||||
if (!token) return null;
|
||||
|
||||
set({isLoading: true});
|
||||
try {
|
||||
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||
|
||||
const response = await axios.get(`${API_URL}/auth/me`);
|
||||
|
||||
set({user_id: response.data, isLoading: false});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
delete axios.defaults.headers.common["Authorization"];
|
||||
set({user_id: null, token: null, isLoading: false});
|
||||
return null;
|
||||
}
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: "auth-storage",
|
||||
storage: createJSONStorage(() => AsyncStorage),
|
||||
}
|
||||
)
|
||||
);
|
||||
41
ArtisanConnect/store/noticesStore.jsx
Normal file
41
ArtisanConnect/store/noticesStore.jsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import {create} from "zustand";
|
||||
import * as api from "@/api/notices";
|
||||
|
||||
export const useNoticesStore = create((set, get) => ({
|
||||
notices: [],
|
||||
fetchNotices: async () => {
|
||||
set({error: null});
|
||||
try {
|
||||
const data = await api.listNotices();
|
||||
set({notices: data});
|
||||
} catch (error) {
|
||||
set(error);
|
||||
}
|
||||
},
|
||||
|
||||
addNotice: async (notice) => {
|
||||
try {
|
||||
const newNotice = await api.createNotice(notice);
|
||||
set((state) => ({
|
||||
notices: [...state.notices, newNotice],
|
||||
}));
|
||||
return newNotice;
|
||||
} catch (error) {
|
||||
set({ error });
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
getNoticeById: (noticeId) => {
|
||||
return get().notices.find((notice) => String(notice.noticeId) === String(noticeId));
|
||||
},
|
||||
|
||||
getAllImagesByNoticeId: async (noticeId) => {
|
||||
try {
|
||||
return await api.getAllImagesByNoticeId(noticeId);
|
||||
} catch (error) {
|
||||
console.error("Error while getting images:", error);
|
||||
return ["https://http.cat/404.jpg"];
|
||||
}
|
||||
}
|
||||
}));
|
||||
@@ -9,7 +9,7 @@ export const useWishlist = create((set) => ({
|
||||
removeNoticeFromWishlist: (noticeId) =>
|
||||
set((state) => ({
|
||||
wishlistNotices: state.wishlistNotices.filter(
|
||||
(item) => item.noticeId != noticeId
|
||||
(item) => item.noticeId !== noticeId
|
||||
),
|
||||
})),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user