Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c8ec54c22d |
@@ -4,7 +4,7 @@ android {
|
|||||||
namespace = "io.ionic.starter"
|
namespace = "io.ionic.starter"
|
||||||
compileSdk = rootProject.ext.compileSdkVersion
|
compileSdk = rootProject.ext.compileSdkVersion
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.inspot.app"
|
applicationId "io.shopkeep.app"
|
||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 1
|
versionCode 1
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
@@ -30,15 +25,9 @@
|
|||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
<data android:scheme="com.inspot.app" />
|
<data android:scheme="io.shopkeep.app" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
|
||||||
<data android:scheme="com.inspot.app" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 742 B After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 708 B After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 742 B After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 16 KiB |
@@ -1,7 +1,7 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">InSpot</string>
|
<string name="app_name">ShopKeep</string>
|
||||||
<string name="title_activity_main">InSpot</string>
|
<string name="title_activity_main">ShopKeep</string>
|
||||||
<string name="package_name">io.ionic.starter</string>
|
<string name="package_name">io.ionic.starter</string>
|
||||||
<string name="custom_url_scheme">io.ionic.starter</string>
|
<string name="custom_url_scheme">io.ionic.starter</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { CapacitorConfig } from '@capacitor/cli';
|
import type { CapacitorConfig } from '@capacitor/cli';
|
||||||
|
|
||||||
const config: CapacitorConfig = {
|
const config: CapacitorConfig = {
|
||||||
appId: 'com.inspot.app',
|
appId: 'io.shopkeep.app',
|
||||||
appName: 'InSpot',
|
appName: 'ShopKeep',
|
||||||
webDir: 'dist',
|
webDir: 'dist',
|
||||||
plugins: {
|
plugins: {
|
||||||
FirebaseAuthentication: {
|
FirebaseAuthentication: {
|
||||||
|
|||||||
@@ -308,7 +308,7 @@
|
|||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
|
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.inspot.app;
|
PRODUCT_BUNDLE_IDENTIFIER = io.shopkeep.app;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@@ -330,7 +330,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.inspot.app;
|
PRODUCT_BUNDLE_IDENTIFIER = io.shopkeep.app;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import Capacitor
|
import Capacitor
|
||||||
import FirebaseCore
|
|
||||||
import FirebaseMessaging
|
|
||||||
|
|
||||||
@UIApplicationMain
|
@UIApplicationMain
|
||||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
@@ -9,25 +7,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
var window: UIWindow?
|
var window: UIWindow?
|
||||||
|
|
||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||||
FirebaseApp.configure()
|
// Override point for customization after application launch.
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
||||||
Messaging.messaging().apnsToken = deviceToken
|
|
||||||
Messaging.messaging().token { token, error in
|
|
||||||
if let error = error {
|
|
||||||
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
|
|
||||||
} else if let token = token {
|
|
||||||
NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
|
||||||
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func applicationWillResignActive(_ application: UIApplication) {
|
func applicationWillResignActive(_ application: UIApplication) {
|
||||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||||
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
||||||
|
|||||||
@@ -1,122 +1,14 @@
|
|||||||
{
|
{
|
||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom": "iphone",
|
"filename" : "AppIcon-512@2x.png",
|
||||||
"scale": "1x",
|
"idiom" : "universal",
|
||||||
"size": "20x20",
|
"platform" : "ios",
|
||||||
"filename": "icon-20.png"
|
"size" : "1024x1024"
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "ipad",
|
|
||||||
"scale": "1x",
|
|
||||||
"size": "20x20",
|
|
||||||
"filename": "icon-20.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "iphone",
|
|
||||||
"scale": "1x",
|
|
||||||
"size": "29x29",
|
|
||||||
"filename": "icon-29.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "ipad",
|
|
||||||
"scale": "1x",
|
|
||||||
"size": "29x29",
|
|
||||||
"filename": "icon-29.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "ipad",
|
|
||||||
"scale": "1x",
|
|
||||||
"size": "40x40",
|
|
||||||
"filename": "icon-40.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "iphone",
|
|
||||||
"scale": "2x",
|
|
||||||
"size": "20x20",
|
|
||||||
"filename": "icon-40.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "iphone",
|
|
||||||
"scale": "2x",
|
|
||||||
"size": "29x29",
|
|
||||||
"filename": "icon-58.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "ipad",
|
|
||||||
"scale": "2x",
|
|
||||||
"size": "29x29",
|
|
||||||
"filename": "icon-58.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "iphone",
|
|
||||||
"scale": "3x",
|
|
||||||
"size": "20x20",
|
|
||||||
"filename": "icon-60.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "ipad",
|
|
||||||
"scale": "1x",
|
|
||||||
"size": "76x76",
|
|
||||||
"filename": "icon-76.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "iphone",
|
|
||||||
"scale": "2x",
|
|
||||||
"size": "40x40",
|
|
||||||
"filename": "icon-80.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "ipad",
|
|
||||||
"scale": "2x",
|
|
||||||
"size": "40x40",
|
|
||||||
"filename": "icon-80.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "iphone",
|
|
||||||
"scale": "3x",
|
|
||||||
"size": "29x29",
|
|
||||||
"filename": "icon-87.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "iphone",
|
|
||||||
"scale": "2x",
|
|
||||||
"size": "60x60",
|
|
||||||
"filename": "icon-120.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "iphone",
|
|
||||||
"scale": "3x",
|
|
||||||
"size": "40x40",
|
|
||||||
"filename": "icon-120.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "ipad",
|
|
||||||
"scale": "2x",
|
|
||||||
"size": "76x76",
|
|
||||||
"filename": "icon-152.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "ipad",
|
|
||||||
"scale": "2x",
|
|
||||||
"size": "83.5x83.5",
|
|
||||||
"filename": "icon-167.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "iphone",
|
|
||||||
"scale": "3x",
|
|
||||||
"size": "60x60",
|
|
||||||
"filename": "icon-180.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom": "ios-marketing",
|
|
||||||
"scale": "1x",
|
|
||||||
"size": "1024x1024",
|
|
||||||
"filename": "icon-1024.png"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info" : {
|
"info" : {
|
||||||
"author": "appsuite",
|
"author" : "xcode",
|
||||||
"version" : 1
|
"version" : 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 480 B |
|
Before Width: | Height: | Size: 663 B |
|
Before Width: | Height: | Size: 979 B |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
@@ -7,7 +7,7 @@
|
|||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>en</string>
|
<string>en</string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>InSpot</string>
|
<string>ShopKeep</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
@@ -51,31 +51,12 @@
|
|||||||
<array>
|
<array>
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleURLName</key>
|
<key>CFBundleURLName</key>
|
||||||
<string>com.inspot.app</string>
|
<string>io.shopkeep.app</string>
|
||||||
<key>CFBundleURLSchemes</key>
|
<key>CFBundleURLSchemes</key>
|
||||||
<array>
|
<array>
|
||||||
<string>com.inspot.app</string>
|
<string>io.shopkeep.app</string>
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleURLTypes</key>
|
|
||||||
<array>
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleURLName</key>
|
|
||||||
<string>com.inspot.app</string>
|
|
||||||
<key>CFBundleURLSchemes</key>
|
|
||||||
<array>
|
|
||||||
<string>com.inspot.app</string>
|
|
||||||
</array>
|
|
||||||
</dict>
|
|
||||||
</array>
|
|
||||||
<key>NSCameraUsageDescription</key>
|
|
||||||
<string>InSpot needs camera access to let you capture and share reels of local spots.</string>
|
|
||||||
<key>NSPhotoLibraryUsageDescription</key>
|
|
||||||
<string>InSpot needs photo library access to let you upload profile photos and share reels from your gallery.</string>
|
|
||||||
<key>NSMicrophoneUsageDescription</key>
|
|
||||||
<string>InSpot needs microphone access to record sound for your reels.</string>
|
|
||||||
<key>NSLocationWhenInUseUsageDescription</key>
|
|
||||||
<string>InSpot needs your location to discover nearby spots and social connections.</string>
|
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -24,11 +24,10 @@
|
|||||||
"@ionic/pwa-elements": "^3.0.0",
|
"@ionic/pwa-elements": "^3.0.0",
|
||||||
"@ionic/react": "8.8.7",
|
"@ionic/react": "8.8.7",
|
||||||
"@ionic/react-router": "8.8.7",
|
"@ionic/react-router": "8.8.7",
|
||||||
"@supabase/supabase-js": "^2.108.1",
|
"@supabase/supabase-js": "^2.0.0",
|
||||||
"firebase": "^11.0.0",
|
"firebase": "^11.0.0",
|
||||||
"ionicons": "^7.4.0",
|
"ionicons": "^7.4.0",
|
||||||
"katex": "^0.16.0",
|
"katex": "^0.16.0",
|
||||||
"lottie-react": "^2.4.1",
|
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"react-hook-form": "^7.54.0",
|
"react-hook-form": "^7.54.0",
|
||||||
|
|||||||
@@ -1,24 +1,45 @@
|
|||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { Redirect, Route } from 'react-router-dom';
|
import { Redirect, Route } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
IonApp,
|
IonApp,
|
||||||
IonIcon,
|
|
||||||
IonLabel,
|
|
||||||
IonRouterOutlet,
|
IonRouterOutlet,
|
||||||
|
IonTabs,
|
||||||
IonTabBar,
|
IonTabBar,
|
||||||
IonTabButton,
|
IonTabButton,
|
||||||
IonTabs,
|
IonIcon,
|
||||||
|
IonLabel,
|
||||||
|
setupIonicReact,
|
||||||
} from '@ionic/react';
|
} from '@ionic/react';
|
||||||
import { IonReactRouter } from '@ionic/react-router';
|
import { IonReactRouter } from '@ionic/react-router';
|
||||||
import {
|
import {
|
||||||
flameOutline,
|
homeOutline,
|
||||||
locationOutline,
|
peopleOutline,
|
||||||
chatbubblesOutline,
|
receiptOutline,
|
||||||
personOutline,
|
home,
|
||||||
|
people,
|
||||||
|
receipt,
|
||||||
} from 'ionicons/icons';
|
} from 'ionicons/icons';
|
||||||
|
|
||||||
|
import Home from './pages/Home';
|
||||||
|
import CustomersPage from './pages/CustomersPage';
|
||||||
|
import CustomerDetailPage from './pages/CustomerDetailPage';
|
||||||
|
import HistoryPage from './pages/HistoryPage';
|
||||||
|
import SaleFormPage from './pages/SaleFormPage';
|
||||||
|
import CreditFormPage from './pages/CreditFormPage';
|
||||||
|
import RepaymentFormPage from './pages/RepaymentFormPage';
|
||||||
|
import AuthPage from './pages/AuthPage';
|
||||||
|
import VerifyEmailPage from './pages/VerifyEmailPage';
|
||||||
|
import ForgotPasswordPage from './pages/ForgotPasswordPage';
|
||||||
|
import NewPasswordPage from './pages/NewPasswordPage';
|
||||||
|
|
||||||
|
import { AuthProvider } from './contexts/AuthContext';
|
||||||
|
import ProtectedRoute from './components/ProtectedRoute';
|
||||||
|
import { setStatusBarStyle, Style } from './utils/statusBar';
|
||||||
|
|
||||||
/* Core CSS required for Ionic components to work properly */
|
/* Core CSS required for Ionic components to work properly */
|
||||||
import '@ionic/react/css/core.css';
|
import '@ionic/react/css/core.css';
|
||||||
|
|
||||||
|
/* Basic CSS for apps built with Ionic */
|
||||||
import '@ionic/react/css/normalize.css';
|
import '@ionic/react/css/normalize.css';
|
||||||
import '@ionic/react/css/structure.css';
|
import '@ionic/react/css/structure.css';
|
||||||
import '@ionic/react/css/typography.css';
|
import '@ionic/react/css/typography.css';
|
||||||
@@ -31,123 +52,104 @@ import '@ionic/react/css/text-transformation.css';
|
|||||||
import '@ionic/react/css/flex-utils.css';
|
import '@ionic/react/css/flex-utils.css';
|
||||||
import '@ionic/react/css/display.css';
|
import '@ionic/react/css/display.css';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ionic Dark Mode
|
||||||
|
* -----------------------------------------------------
|
||||||
|
* For more info, please see:
|
||||||
|
* https://ionicframework.com/docs/theming/dark-mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* import '@ionic/react/css/palettes/dark.always.css'; */
|
||||||
|
/* import '@ionic/react/css/palettes/dark.class.css'; */
|
||||||
|
import '@ionic/react/css/palettes/dark.system.css';
|
||||||
|
|
||||||
/* Theme variables */
|
/* Theme variables */
|
||||||
import './theme/variables.css';
|
import './theme/variables.css';
|
||||||
|
|
||||||
/* Pages */
|
setupIonicReact();
|
||||||
import AuthPage from './pages/AuthPage';
|
|
||||||
import VerifyEmailPage from './pages/VerifyEmailPage';
|
|
||||||
import ForgotPasswordPage from './pages/ForgotPasswordPage';
|
|
||||||
import NewPasswordPage from './pages/NewPasswordPage';
|
|
||||||
import OnboardingProfilePage from './pages/OnboardingProfilePage';
|
|
||||||
import IcebreakerPage from './pages/IcebreakerPage';
|
|
||||||
import HangoutPage from './pages/HangoutPage';
|
|
||||||
import ReelsPage from './pages/ReelsPage';
|
|
||||||
import CameraPage from './pages/CameraPage';
|
|
||||||
import ChatsPage from './pages/ChatsPage';
|
|
||||||
import ChatThreadPage from './pages/ChatThreadPage';
|
|
||||||
import ProfilePage from './pages/ProfilePage';
|
|
||||||
import EditProfilePage from './pages/EditProfilePage';
|
|
||||||
import NotificationsPage from './pages/NotificationsPage';
|
|
||||||
import PremiumPage from './pages/PremiumPage';
|
|
||||||
|
|
||||||
/* Contexts & Components */
|
const App: React.FC = () => {
|
||||||
import { AuthProvider } from './contexts/AuthContext';
|
useEffect(() => {
|
||||||
import ProtectedRoute from './components/ProtectedRoute';
|
// Set status bar to light icons on our dark-ish backgrounds
|
||||||
import { isPreviewMode } from './utils/previewMode';
|
setStatusBarStyle(Style.Dark);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const App: React.FC = () => (
|
return (
|
||||||
<IonApp>
|
<IonApp>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<IonReactRouter>
|
<IonReactRouter>
|
||||||
<IonRouterOutlet>
|
<IonRouterOutlet>
|
||||||
{/* Auth Stack */}
|
{/* Auth Routes */}
|
||||||
<Route path="/auth" component={AuthPage} exact />
|
<Route path="/auth" component={AuthPage} exact />
|
||||||
<Route path="/verify-email" component={VerifyEmailPage} exact />
|
<Route path="/verify-email" component={VerifyEmailPage} exact />
|
||||||
<Route path="/forgot-password" component={ForgotPasswordPage} exact />
|
|
||||||
<Route path="/new-password" component={NewPasswordPage} exact />
|
|
||||||
<ProtectedRoute
|
|
||||||
path="/onboarding/profile"
|
|
||||||
component={OnboardingProfilePage}
|
|
||||||
exact
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Detailed Stack (No Tabs) */}
|
|
||||||
<ProtectedRoute path="/reels/:placeId" component={ReelsPage} exact />
|
|
||||||
<ProtectedRoute
|
|
||||||
path="/chat/:conversationId"
|
|
||||||
component={ChatThreadPage}
|
|
||||||
exact
|
|
||||||
/>
|
|
||||||
<ProtectedRoute
|
|
||||||
path="/profile/edit"
|
|
||||||
component={EditProfilePage}
|
|
||||||
exact
|
|
||||||
/>
|
|
||||||
<ProtectedRoute path="/premium" component={PremiumPage} exact />
|
|
||||||
<ProtectedRoute
|
|
||||||
path="/notifications"
|
|
||||||
component={NotificationsPage}
|
|
||||||
exact
|
|
||||||
/>
|
|
||||||
<ProtectedRoute path="/camera" component={CameraPage} exact />
|
|
||||||
|
|
||||||
{/* Main Tabs */}
|
|
||||||
<Route
|
<Route
|
||||||
path={['/icebreaker', '/hangout', '/chats', '/profile']}
|
path="/forgot-password"
|
||||||
|
component={ForgotPasswordPage}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
<Route path="/new-password" component={NewPasswordPage} exact />
|
||||||
|
|
||||||
|
{/* Protected Form & Detail Routes (Outer Outlet for push/pop animation) */}
|
||||||
|
<ProtectedRoute path="/sale/new" component={SaleFormPage} exact />
|
||||||
|
<ProtectedRoute
|
||||||
|
path="/credit/new"
|
||||||
|
component={CreditFormPage}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
<ProtectedRoute
|
||||||
|
path="/repayment/new"
|
||||||
|
component={RepaymentFormPage}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
<ProtectedRoute
|
||||||
|
path="/customers/:id([0-9a-fA-F-]{36})"
|
||||||
|
component={CustomerDetailPage}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Tab Shell */}
|
||||||
|
<Route
|
||||||
|
path={['/home', '/customers', '/history']}
|
||||||
render={() => (
|
render={() => (
|
||||||
<IonTabs>
|
<IonTabs>
|
||||||
<IonRouterOutlet>
|
<IonRouterOutlet>
|
||||||
|
<ProtectedRoute path="/home" component={Home} exact />
|
||||||
<ProtectedRoute
|
<ProtectedRoute
|
||||||
path="/icebreaker"
|
path="/customers"
|
||||||
component={IcebreakerPage}
|
component={CustomersPage}
|
||||||
exact
|
exact
|
||||||
/>
|
/>
|
||||||
<ProtectedRoute
|
<ProtectedRoute
|
||||||
path="/hangout"
|
path="/history"
|
||||||
component={HangoutPage}
|
component={HistoryPage}
|
||||||
exact
|
|
||||||
/>
|
|
||||||
<ProtectedRoute path="/chats" component={ChatsPage} exact />
|
|
||||||
<ProtectedRoute
|
|
||||||
path="/profile"
|
|
||||||
component={ProfilePage}
|
|
||||||
exact
|
exact
|
||||||
/>
|
/>
|
||||||
</IonRouterOutlet>
|
</IonRouterOutlet>
|
||||||
<IonTabBar slot="bottom">
|
<IonTabBar slot="bottom">
|
||||||
<IonTabButton tab="icebreaker" href="/icebreaker">
|
<IonTabButton tab="home" href="/home">
|
||||||
<IonIcon icon={flameOutline} />
|
<IonIcon icon={homeOutline} />
|
||||||
<IonLabel>Icebreaker</IonLabel>
|
<IonLabel>Home</IonLabel>
|
||||||
</IonTabButton>
|
</IonTabButton>
|
||||||
<IonTabButton tab="hangout" href="/hangout">
|
<IonTabButton tab="customers" href="/customers">
|
||||||
<IonIcon icon={locationOutline} />
|
<IonIcon icon={peopleOutline} />
|
||||||
<IonLabel>Hangout</IonLabel>
|
<IonLabel>Customers</IonLabel>
|
||||||
</IonTabButton>
|
</IonTabButton>
|
||||||
<IonTabButton tab="chats" href="/chats">
|
<IonTabButton tab="history" href="/history">
|
||||||
<IonIcon icon={chatbubblesOutline} />
|
<IonIcon icon={receiptOutline} />
|
||||||
<IonLabel>Chats</IonLabel>
|
<IonLabel>History</IonLabel>
|
||||||
</IonTabButton>
|
|
||||||
<IonTabButton tab="profile" href="/profile">
|
|
||||||
<IonIcon icon={personOutline} />
|
|
||||||
<IonLabel>Profile</IonLabel>
|
|
||||||
</IonTabButton>
|
</IonTabButton>
|
||||||
</IonTabBar>
|
</IonTabBar>
|
||||||
</IonTabs>
|
</IonTabs>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
{/* Root Redirect */}
|
||||||
exact
|
<Route exact path="/" render={() => <Redirect to="/home" />} />
|
||||||
path="/"
|
|
||||||
render={() => (
|
|
||||||
<Redirect to={isPreviewMode() ? '/icebreaker' : '/auth'} />
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</IonRouterOutlet>
|
</IonRouterOutlet>
|
||||||
</IonReactRouter>
|
</IonReactRouter>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
</IonApp>
|
</IonApp>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 1.5 MiB |
|
Before Width: | Height: | Size: 1.5 MiB |
|
Before Width: | Height: | Size: 138 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 13 KiB |
@@ -1 +0,0 @@
|
|||||||
{"nm":"Main Scene","ddd":0,"h":1920,"w":1920,"meta":{"g":"@lottiefiles/creator 1.37.1"},"layers":[{"ty":4,"nm":"Layer 1 Outlines 3","sr":1,"st":0,"op":420,"ip":0,"hd":false,"ddd":0,"bm":0,"hasMask":false,"ao":0,"ks":{"a":{"a":0,"k":[523.115,1227.748,0],"ix":1},"s":{"a":1,"k":[{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[43,36],"t":0},{"s":[157,192.00000000000003],"t":25}],"ix":6},"sk":{"a":0,"k":0},"p":{"a":0,"k":[960,1277.507],"ix":2},"r":{"a":0,"k":0,"ix":10},"sa":{"a":0,"k":0},"o":{"a":1,"k":[{"o":{"x":0.167,"y":0.167},"i":{"x":0.833,"y":0.833},"s":[0],"t":0},{"o":{"x":0.167,"y":0.167},"i":{"x":0.833,"y":0.833},"s":[30],"t":12},{"s":[0],"t":25}],"ix":11}},"shapes":[{"ty":"gr","bm":0,"hd":false,"mn":"ADBE Vector Group","nm":"Group 3","ix":1,"cix":2,"np":2,"it":[{"ty":"sh","bm":0,"hd":false,"mn":"ADBE Vector Shape - Group","nm":"Path 1","ix":1,"d":1,"ks":{"a":0,"k":{"c":true,"i":[[-265.484,0],[0,-135.236],[265.484,0],[0,135.235]],"o":[[265.484,0],[0,135.235],[-265.484,0],[0,-135.236]],"v":[[0,-244.865],[480.701,0.001],[0,244.866],[-480.701,0.001]]},"ix":2}},{"ty":"st","bm":0,"hd":false,"mn":"ADBE Vector Graphic - Stroke","nm":"Stroke 1","lc":1,"lj":1,"ml":10,"o":{"a":0,"k":100,"ix":4},"w":{"a":1,"k":[{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[20],"t":0},{"s":[50],"t":25}],"ix":5},"c":{"a":0,"k":[0.9961,0.2353,0.4471],"ix":3}},{"ty":"tr","a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"sk":{"a":0,"k":0,"ix":4},"p":{"a":0,"k":[523.115,1227.748],"ix":2},"r":{"a":0,"k":0,"ix":6},"sa":{"a":0,"k":0,"ix":5},"o":{"a":0,"k":100,"ix":7}}]}],"ind":1},{"ty":4,"nm":"Layer 1 Outlines 2","sr":1,"st":0,"op":420,"ip":0,"hd":false,"ddd":0,"bm":0,"hasMask":false,"ao":0,"ks":{"a":{"a":0,"k":[523.115,382.842,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":6},"sk":{"a":0,"k":0},"p":{"a":1,"k":[{"o":{"x":0.167,"y":0.167},"i":{"x":0.833,"y":0.833},"s":[960,413.401],"t":0},{"o":{"x":0.167,"y":0.167},"i":{"x":0.833,"y":0.833},"s":[960,433.401],"t":12},{"s":[960,413.401],"t":25}],"ix":2},"r":{"a":0,"k":0,"ix":10},"sa":{"a":0,"k":0},"o":{"a":0,"k":100,"ix":11}},"shapes":[{"ty":"gr","bm":0,"hd":false,"mn":"ADBE Vector Group","nm":"Group 1","ix":1,"cix":2,"np":6,"it":[{"ty":"sh","bm":0,"hd":false,"mn":"ADBE Vector Shape - Group","nm":"Path 1","ix":1,"d":1,"ks":{"a":0,"k":{"c":true,"i":[[106.139,0],[0,106.14],[-106.139,0],[0,-106.141]],"o":[[-106.141,0],[0,-106.141],[106.139,0],[0,106.141]],"v":[[0,44.966],[-192.49,-147.526],[0,-340.016],[192.488,-147.524]]},"ix":2}},{"ty":"sh","bm":0,"hd":false,"mn":"ADBE Vector Shape - Group","nm":"Path 2","ix":2,"d":1,"ks":{"a":0,"k":{"c":true,"i":[[210.961,0],[0,-210.961],[-14.577,-16.234],[-13.668,15.223],[0,261.809]],"o":[[-210.963,0],[0,261.809],[13.693,15.25],[14.577,-16.234],[-0.004,-210.961]],"v":[[0,-530.117],[-382.593,-147.526],[-25.633,514.867],[25.633,514.867],[382.593,-147.526]]},"ix":2}},{"ty":"mm","bm":0,"hd":false,"mn":"ADBE Vector Filter - Merge","nm":"Merge Paths 1","mm":1},{"ty":"fl","bm":0,"hd":false,"mn":"ADBE Vector Graphic - Fill","nm":"Fill 1","c":{"a":0,"k":[0.9961,0.2353,0.4471],"ix":4},"r":1,"o":{"a":0,"k":100,"ix":5}},{"ty":"tr","a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"sk":{"a":0,"k":0,"ix":4},"p":{"a":0,"k":[523.115,530.367],"ix":2},"r":{"a":0,"k":0,"ix":6},"sa":{"a":0,"k":0,"ix":5},"o":{"a":0,"k":100,"ix":7}}]}],"ind":2},{"ty":4,"nm":"Layer 1 Outlines","sr":1,"st":0,"op":420,"ip":0,"hd":false,"ddd":0,"bm":0,"hasMask":false,"ao":0,"ks":{"a":{"a":0,"k":[523.115,1307.748],"ix":1},"s":{"a":0,"k":[100,123],"ix":6},"sk":{"a":0,"k":0},"p":{"a":0,"k":[960,1278.307],"ix":2},"r":{"a":0,"k":0,"ix":10},"sa":{"a":0,"k":0},"o":{"a":0,"k":80,"ix":11}},"shapes":[{"ty":"gr","bm":0,"hd":false,"mn":"ADBE Vector Group","nm":"Group 2","ix":1,"cix":2,"np":4,"it":[{"ty":"sh","bm":0,"hd":false,"mn":"ADBE Vector Shape - Group","nm":"Path 1","ix":1,"d":1,"ks":{"a":0,"k":{"c":true,"i":[[0,-46.929],[123.812,0],[0,46.929],[-123.812,0]],"o":[[0,46.929],[-123.812,0],[0,-46.929],[123.812,0]],"v":[[224.182,0],[0,84.972],[-224.182,0],[0,-84.972]]},"ix":2}},{"ty":"fl","bm":0,"hd":false,"mn":"ADBE Vector Graphic - Fill","nm":"Fill 1","c":{"a":0,"k":[0.9961,0.2353,0.4471],"ix":4},"r":1,"o":{"a":0,"k":100,"ix":5}},{"ty":"tr","a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"sk":{"a":0,"k":0,"ix":4},"p":{"a":0,"k":[523.115,1307.748],"ix":2},"r":{"a":0,"k":0,"ix":6},"sa":{"a":0,"k":0,"ix":5},"o":{"a":0,"k":100,"ix":7}}]}],"ind":3}],"v":"5.7.0","fr":30,"op":30,"ip":0,"assets":[]}
|
|
||||||
|
Before Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 1.6 MiB |
@@ -0,0 +1,130 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { IonIcon, IonItem, IonLabel, IonNote } from '@ionic/react';
|
||||||
|
import {
|
||||||
|
receiptOutline,
|
||||||
|
personAddOutline,
|
||||||
|
cashOutline,
|
||||||
|
chevronForwardOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
import { formatMoney } from '../utils/money';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { formatDisplayDate } from '../utils/dates';
|
||||||
|
|
||||||
|
export type ActivityType = 'sale' | 'credit' | 'repayment';
|
||||||
|
|
||||||
|
export interface ActivityItem {
|
||||||
|
id: string;
|
||||||
|
type: ActivityType;
|
||||||
|
amount: number;
|
||||||
|
date: string;
|
||||||
|
customerName?: string;
|
||||||
|
note?: string;
|
||||||
|
customerId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ActivityRowProps {
|
||||||
|
item: ActivityItem;
|
||||||
|
onClick?: () => void;
|
||||||
|
showDate?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ActivityRow: React.FC<ActivityRowProps> = ({
|
||||||
|
item,
|
||||||
|
onClick,
|
||||||
|
showDate = false,
|
||||||
|
}) => {
|
||||||
|
const { profile } = useAuth();
|
||||||
|
const currency = profile?.currency || 'USD';
|
||||||
|
|
||||||
|
const getIcon = () => {
|
||||||
|
switch (item.type) {
|
||||||
|
case 'sale':
|
||||||
|
return receiptOutline;
|
||||||
|
case 'credit':
|
||||||
|
return personAddOutline;
|
||||||
|
case 'repayment':
|
||||||
|
return cashOutline;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTitle = () => {
|
||||||
|
switch (item.type) {
|
||||||
|
case 'sale':
|
||||||
|
return 'Cash Sale';
|
||||||
|
case 'credit':
|
||||||
|
return `Credit: ${item.customerName || 'Customer'}`;
|
||||||
|
case 'repayment':
|
||||||
|
return `Repayment: ${item.customerName || 'Customer'}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAmountColor = () => {
|
||||||
|
switch (item.type) {
|
||||||
|
case 'sale':
|
||||||
|
return 'var(--color-text-primary)';
|
||||||
|
case 'credit':
|
||||||
|
return 'var(--ion-color-primary)';
|
||||||
|
case 'repayment':
|
||||||
|
return 'var(--ion-color-success)';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonItem
|
||||||
|
lines="none"
|
||||||
|
onClick={onClick}
|
||||||
|
detail={false}
|
||||||
|
style={{
|
||||||
|
'--background': 'transparent',
|
||||||
|
'--padding-start': '0',
|
||||||
|
'--padding-end': '0',
|
||||||
|
'--inner-padding-end': '0',
|
||||||
|
cursor: onClick ? 'pointer' : 'default',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="icon-container"
|
||||||
|
slot="start"
|
||||||
|
style={{ marginRight: '12px' }}
|
||||||
|
>
|
||||||
|
<IonIcon icon={getIcon()} />
|
||||||
|
</div>
|
||||||
|
<IonLabel>
|
||||||
|
<h3 className="semibold" style={{ margin: '0', fontSize: '15px' }}>
|
||||||
|
{getTitle()}
|
||||||
|
</h3>
|
||||||
|
<p className="secondary-text" style={{ margin: '2px 0 0 0' }}>
|
||||||
|
{showDate ? formatDisplayDate(item.date) : item.note || 'No notes'}
|
||||||
|
</p>
|
||||||
|
</IonLabel>
|
||||||
|
<div
|
||||||
|
slot="end"
|
||||||
|
style={{ textAlign: 'right', display: 'flex', alignItems: 'center' }}
|
||||||
|
>
|
||||||
|
<IonNote
|
||||||
|
className="tabular"
|
||||||
|
style={{
|
||||||
|
fontSize: '15px',
|
||||||
|
color: getAmountColor(),
|
||||||
|
fontWeight: '400',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.type === 'credit' ? '-' : '+'}
|
||||||
|
{formatMoney(item.amount, currency)}
|
||||||
|
</IonNote>
|
||||||
|
{onClick && (
|
||||||
|
<IonIcon
|
||||||
|
icon={chevronForwardOutline}
|
||||||
|
style={{
|
||||||
|
fontSize: '14px',
|
||||||
|
marginLeft: '8px',
|
||||||
|
color: 'var(--color-text-tertiary)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</IonItem>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ActivityRow;
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { getStorageUrl, getInitials, getInitialsColor } from '../utils/storage';
|
|
||||||
|
|
||||||
interface AvatarProps {
|
|
||||||
src?: string | null;
|
|
||||||
name?: string | null;
|
|
||||||
size?: number;
|
|
||||||
bucket?: string;
|
|
||||||
className?: string;
|
|
||||||
style?: React.CSSProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Avatar: React.FC<AvatarProps> = ({
|
|
||||||
src,
|
|
||||||
name,
|
|
||||||
size = 48,
|
|
||||||
bucket = 'avatars',
|
|
||||||
className = '',
|
|
||||||
style = {},
|
|
||||||
}) => {
|
|
||||||
const url =
|
|
||||||
src?.startsWith('/src/assets/') || src?.startsWith('/assets/')
|
|
||||||
? src
|
|
||||||
: getStorageUrl(bucket, src);
|
|
||||||
|
|
||||||
const containerStyle: React.CSSProperties = {
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
borderRadius: '50%',
|
|
||||||
overflow: 'hidden',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
flexShrink: 0,
|
|
||||||
background: url ? 'transparent' : getInitialsColor(name || null),
|
|
||||||
...style,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (url) {
|
|
||||||
return (
|
|
||||||
<div className={className} style={containerStyle}>
|
|
||||||
<img
|
|
||||||
src={url}
|
|
||||||
alt={name || 'Avatar'}
|
|
||||||
style={{ width: '100%', height: '100%', objectFit: 'cover' }}
|
|
||||||
onError={(e) => {
|
|
||||||
(e.target as HTMLImageElement).style.display = 'none';
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={className} style={containerStyle}>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
color: '#ffffff',
|
|
||||||
fontSize: size * 0.4,
|
|
||||||
fontWeight: 700,
|
|
||||||
letterSpacing: '-0.02em',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{getInitials(name || null)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Avatar;
|
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { IonIcon, IonItem, IonLabel, IonNote } from '@ionic/react';
|
||||||
|
import { chevronForwardOutline } from 'ionicons/icons';
|
||||||
|
import { formatMoney } from '../utils/money';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
|
||||||
|
interface CustomerRowProps {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
balance: number;
|
||||||
|
phone?: string;
|
||||||
|
onClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CustomerRow: React.FC<CustomerRowProps> = ({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
balance,
|
||||||
|
phone,
|
||||||
|
onClick,
|
||||||
|
}) => {
|
||||||
|
const { profile } = useAuth();
|
||||||
|
const currency = profile?.currency || 'USD';
|
||||||
|
|
||||||
|
const getInitials = (name: string) => {
|
||||||
|
return name
|
||||||
|
.split(' ')
|
||||||
|
.map((n) => n[0])
|
||||||
|
.join('')
|
||||||
|
.toUpperCase()
|
||||||
|
.slice(0, 2);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonItem
|
||||||
|
lines="none"
|
||||||
|
onClick={onClick}
|
||||||
|
detail={false}
|
||||||
|
style={{
|
||||||
|
'--background': 'transparent',
|
||||||
|
'--padding-start': '0',
|
||||||
|
'--padding-end': '0',
|
||||||
|
'--inner-padding-end': '0',
|
||||||
|
cursor: 'pointer',
|
||||||
|
marginBottom: '8px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="icon-container bold"
|
||||||
|
slot="start"
|
||||||
|
style={{
|
||||||
|
marginRight: '16px',
|
||||||
|
width: '44px',
|
||||||
|
height: '44px',
|
||||||
|
fontSize: '14px',
|
||||||
|
color: 'var(--ion-color-primary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{getInitials(name)}
|
||||||
|
</div>
|
||||||
|
<IonLabel>
|
||||||
|
<h3 className="semibold" style={{ margin: '0', fontSize: '16px' }}>
|
||||||
|
{name}
|
||||||
|
</h3>
|
||||||
|
{phone && (
|
||||||
|
<p className="secondary-text" style={{ margin: '2px 0 0 0' }}>
|
||||||
|
{phone}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</IonLabel>
|
||||||
|
<div
|
||||||
|
slot="end"
|
||||||
|
style={{ textAlign: 'right', display: 'flex', alignItems: 'center' }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'flex-end',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonNote
|
||||||
|
className="tabular"
|
||||||
|
style={{
|
||||||
|
fontSize: '16px',
|
||||||
|
color:
|
||||||
|
balance > 0
|
||||||
|
? 'var(--ion-color-danger)'
|
||||||
|
: 'var(--ion-color-success)',
|
||||||
|
fontWeight: '400',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{formatMoney(balance, currency)}
|
||||||
|
</IonNote>
|
||||||
|
<span
|
||||||
|
className="tertiary-text"
|
||||||
|
style={{ fontSize: '10px', marginTop: '2px' }}
|
||||||
|
>
|
||||||
|
{balance > 0 ? 'OUTSTANDING' : 'CLEARED'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<IonIcon
|
||||||
|
icon={chevronForwardOutline}
|
||||||
|
style={{
|
||||||
|
fontSize: '16px',
|
||||||
|
marginLeft: '12px',
|
||||||
|
color: 'var(--color-text-tertiary)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</IonItem>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CustomerRow;
|
||||||
@@ -1,80 +1,75 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { IonButton, IonIcon } from '@ionic/react';
|
import { IonIcon, IonButton } from '@ionic/react';
|
||||||
|
|
||||||
interface EmptyStateProps {
|
interface EmptyStateProps {
|
||||||
icon: string;
|
icon: string;
|
||||||
title: string;
|
title: string;
|
||||||
message: string;
|
description?: string;
|
||||||
ctaText?: string;
|
actionText?: string;
|
||||||
onCtaClick?: () => void;
|
onAction?: () => void;
|
||||||
style?: React.CSSProperties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const EmptyState: React.FC<EmptyStateProps> = ({
|
const EmptyState: React.FC<EmptyStateProps> = ({
|
||||||
icon,
|
icon,
|
||||||
title,
|
title,
|
||||||
message,
|
description,
|
||||||
ctaText,
|
actionText,
|
||||||
onCtaClick,
|
onAction,
|
||||||
style = {},
|
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
className="widget-card"
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '40px 20px',
|
padding: '40px 20px',
|
||||||
|
alignItems: 'center',
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
minHeight: '300px',
|
justifyContent: 'center',
|
||||||
...style,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
className="icon-container"
|
||||||
style={{
|
style={{
|
||||||
width: '80px',
|
width: '64px',
|
||||||
height: '80px',
|
height: '64px',
|
||||||
borderRadius: '24px',
|
borderRadius: '20px',
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
marginBottom: '20px',
|
marginBottom: '20px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
color: 'var(--color-text-tertiary)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IonIcon
|
<IonIcon icon={icon} style={{ fontSize: '32px' }} />
|
||||||
icon={icon}
|
|
||||||
style={{ fontSize: '40px', color: 'var(--ion-color-primary)' }}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<h3
|
<h3
|
||||||
style={{
|
style={{
|
||||||
fontSize: '20px',
|
margin: '0 0 8px 0',
|
||||||
fontWeight: 700,
|
fontSize: '18px',
|
||||||
margin: '0 0 8px',
|
fontWeight: '700',
|
||||||
color: 'var(--color-text-primary)',
|
color: 'var(--color-text-primary)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{title}
|
{title}
|
||||||
</h3>
|
</h3>
|
||||||
|
{description && (
|
||||||
<p
|
<p
|
||||||
|
className="secondary-text"
|
||||||
|
style={{ margin: '0 0 24px 0', maxWidth: '240px' }}
|
||||||
|
>
|
||||||
|
{description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{actionText && onAction && (
|
||||||
|
<IonButton
|
||||||
|
onClick={onAction}
|
||||||
|
shape="round"
|
||||||
|
fill="solid"
|
||||||
style={{
|
style={{
|
||||||
fontSize: '15px',
|
height: '44px',
|
||||||
color: 'var(--color-text-secondary)',
|
'--border-radius': '999px',
|
||||||
margin: '0 0 24px',
|
fontSize: '14px',
|
||||||
lineHeight: 1.5,
|
fontWeight: '700',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{message}
|
{actionText}
|
||||||
</p>
|
|
||||||
{ctaText && onCtaClick && (
|
|
||||||
<IonButton
|
|
||||||
expand="block"
|
|
||||||
onClick={onCtaClick}
|
|
||||||
style={{ '--border-radius': 'var(--radius-pill)', minWidth: '200px' }}
|
|
||||||
>
|
|
||||||
{ctaText}
|
|
||||||
</IonButton>
|
</IonButton>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { IonIcon } from '@ionic/react';
|
||||||
|
import { formatMoney } from '../utils/money';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
|
||||||
|
interface MetricCardProps {
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
icon?: string;
|
||||||
|
subtitle?: string;
|
||||||
|
fullWidth?: boolean;
|
||||||
|
loading?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MetricCard: React.FC<MetricCardProps> = ({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
icon,
|
||||||
|
subtitle,
|
||||||
|
fullWidth = false,
|
||||||
|
loading = false,
|
||||||
|
}) => {
|
||||||
|
const { profile } = useAuth();
|
||||||
|
const currency = profile?.currency || 'USD';
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="widget-card"
|
||||||
|
style={{
|
||||||
|
width: fullWidth ? '100%' : 'auto',
|
||||||
|
minHeight: fullWidth ? '160px' : '100px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="skeleton-text"
|
||||||
|
style={{
|
||||||
|
width: '40%',
|
||||||
|
height: '12px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '4px',
|
||||||
|
marginBottom: '12px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className="skeleton-text"
|
||||||
|
style={{
|
||||||
|
width: '70%',
|
||||||
|
height: '32px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '8px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="widget-card"
|
||||||
|
style={{
|
||||||
|
width: fullWidth ? '100%' : 'auto',
|
||||||
|
minHeight: fullWidth ? '160px' : '100px',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'flex-start',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<span className="tertiary-text">{label}</span>
|
||||||
|
<div
|
||||||
|
className="tabular"
|
||||||
|
style={{
|
||||||
|
fontSize: fullWidth ? '34px' : '24px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
marginTop: '4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{formatMoney(value, currency)}
|
||||||
|
</div>
|
||||||
|
{subtitle && <div className="secondary-text">{subtitle}</div>}
|
||||||
|
</div>
|
||||||
|
{icon && (
|
||||||
|
<div className="icon-container">
|
||||||
|
<IonIcon icon={icon} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MetricCard;
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { IonInput, IonLabel } from '@ionic/react';
|
||||||
|
import { sanitizeMoneyInput, getCurrencySymbol } from '../utils/money';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
|
||||||
|
interface MoneyInputProps {
|
||||||
|
value: string;
|
||||||
|
onValueChange: (value: string) => void;
|
||||||
|
label?: string;
|
||||||
|
placeholder?: string;
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MoneyInput: React.FC<MoneyInputProps> = ({
|
||||||
|
value,
|
||||||
|
onValueChange,
|
||||||
|
label,
|
||||||
|
placeholder = '0.00',
|
||||||
|
error,
|
||||||
|
}) => {
|
||||||
|
const { profile } = useAuth();
|
||||||
|
const symbol = getCurrencySymbol(profile?.currency || 'USD');
|
||||||
|
|
||||||
|
const handleChange = (e: CustomEvent) => {
|
||||||
|
const rawValue = e.detail.value || '';
|
||||||
|
const sanitized = sanitizeMoneyInput(rawValue);
|
||||||
|
onValueChange(sanitized);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="money-input-container">
|
||||||
|
{label && (
|
||||||
|
<IonLabel
|
||||||
|
position="stacked"
|
||||||
|
className="semibold"
|
||||||
|
style={{ marginBottom: '8px', display: 'block', fontSize: '13px' }}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</IonLabel>
|
||||||
|
)}
|
||||||
|
<div
|
||||||
|
className="input-wrapper"
|
||||||
|
style={{
|
||||||
|
border: error ? '1px solid var(--ion-color-danger)' : 'none',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="bold"
|
||||||
|
style={{
|
||||||
|
marginRight: '8px',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
fontSize: '18px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{symbol}
|
||||||
|
</span>
|
||||||
|
<IonInput
|
||||||
|
type="text"
|
||||||
|
inputMode="decimal"
|
||||||
|
value={value}
|
||||||
|
placeholder={placeholder}
|
||||||
|
onIonChange={handleChange}
|
||||||
|
style={{
|
||||||
|
fontSize: '20px',
|
||||||
|
fontWeight: '700',
|
||||||
|
'--padding-top': '0',
|
||||||
|
'--padding-bottom': '0',
|
||||||
|
}}
|
||||||
|
className="tabular"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{error && (
|
||||||
|
<IonLabel
|
||||||
|
color="danger"
|
||||||
|
style={{
|
||||||
|
fontSize: '12px',
|
||||||
|
marginTop: '4px',
|
||||||
|
display: 'block',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</IonLabel>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MoneyInput;
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import React, { useRef, useEffect } from 'react';
|
|
||||||
|
|
||||||
interface OtpInputProps {
|
|
||||||
value: string;
|
|
||||||
onChange: (value: string) => void;
|
|
||||||
length?: number;
|
|
||||||
disabled?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const OtpInput: React.FC<OtpInputProps> = ({
|
|
||||||
value,
|
|
||||||
onChange,
|
|
||||||
length = 6,
|
|
||||||
disabled = false,
|
|
||||||
}) => {
|
|
||||||
const inputRefs = useRef<(HTMLInputElement | null)[]>([]);
|
|
||||||
|
|
||||||
const handleChange = (
|
|
||||||
e: React.ChangeEvent<HTMLInputElement>,
|
|
||||||
index: number
|
|
||||||
) => {
|
|
||||||
const val = e.target.value;
|
|
||||||
if (!val) return;
|
|
||||||
|
|
||||||
const newOtp = value.split('');
|
|
||||||
newOtp[index] = val.slice(-1);
|
|
||||||
const combined = newOtp.join('');
|
|
||||||
onChange(combined);
|
|
||||||
|
|
||||||
if (val && index < length - 1) {
|
|
||||||
inputRefs.current[index + 1]?.focus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleKeyDown = (
|
|
||||||
e: React.KeyboardEvent<HTMLInputElement>,
|
|
||||||
index: number
|
|
||||||
) => {
|
|
||||||
if (e.key === 'Backspace' && !value[index] && index > 0) {
|
|
||||||
inputRefs.current[index - 1]?.focus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePaste = (e: React.ClipboardEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
const pastedData = e.clipboardData.getData('text').slice(0, length);
|
|
||||||
if (/^\d+$/.test(pastedData)) {
|
|
||||||
onChange(pastedData);
|
|
||||||
inputRefs.current[Math.min(pastedData.length, length - 1)]?.focus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
gap: '8px',
|
|
||||||
justifyContent: 'center',
|
|
||||||
margin: '24px 0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{Array.from({ length }).map((_, i) => (
|
|
||||||
<input
|
|
||||||
key={i}
|
|
||||||
ref={(el) => {
|
|
||||||
inputRefs.current[i] = el;
|
|
||||||
}}
|
|
||||||
type="text"
|
|
||||||
inputMode="numeric"
|
|
||||||
pattern="\d*"
|
|
||||||
maxLength={1}
|
|
||||||
value={value[i] || ''}
|
|
||||||
onChange={(e) => handleChange(e, i)}
|
|
||||||
onKeyDown={(e) => handleKeyDown(e, i)}
|
|
||||||
onPaste={handlePaste}
|
|
||||||
disabled={disabled}
|
|
||||||
style={{
|
|
||||||
width: '44px',
|
|
||||||
height: '52px',
|
|
||||||
textAlign: 'center',
|
|
||||||
fontSize: '22px',
|
|
||||||
fontWeight: 700,
|
|
||||||
borderRadius: '12px',
|
|
||||||
border: '2px solid transparent',
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
outline: 'none',
|
|
||||||
transition: 'border-color 0.2s',
|
|
||||||
...(value[i] ? { borderColor: 'var(--ion-color-primary)' } : {}),
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default OtpInput;
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Route, Redirect, RouteProps } from 'react-router-dom';
|
import { Route, Redirect, RouteProps } from 'react-router-dom';
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
import { isPreviewMode } from '../utils/previewMode';
|
|
||||||
|
|
||||||
interface ProtectedRouteProps extends RouteProps {
|
interface ProtectedRouteProps extends RouteProps {
|
||||||
component: React.ComponentType<any>;
|
component: React.ComponentType<any>;
|
||||||
@@ -11,15 +10,16 @@ const ProtectedRoute: React.FC<ProtectedRouteProps> = ({
|
|||||||
component: Component,
|
component: Component,
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const { user } = useAuth();
|
const { user, loading } = useAuth();
|
||||||
const previewMode = isPreviewMode();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Route
|
<Route
|
||||||
{...rest}
|
{...rest}
|
||||||
render={(props) =>
|
render={(props) => {
|
||||||
user || previewMode ? <Component {...props} /> : <Redirect to="/auth" />
|
if (loading) return null; // AuthProvider already handles spinner, but double safety
|
||||||
}
|
|
||||||
|
return user ? <Component {...props} /> : <Redirect to="/auth" />;
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { IonSearchbar, IonButton, IonIcon } from '@ionic/react';
|
|
||||||
import { optionsOutline } from 'ionicons/icons';
|
|
||||||
|
|
||||||
interface SearchRowProps {
|
|
||||||
value: string;
|
|
||||||
onChange: (e: any) => void;
|
|
||||||
onFilterClick?: () => void;
|
|
||||||
placeholder?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SearchRow: React.FC<SearchRowProps> = ({
|
|
||||||
value,
|
|
||||||
onChange,
|
|
||||||
onFilterClick,
|
|
||||||
placeholder = 'Search...',
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '8px',
|
|
||||||
margin: '0 20px 14px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSearchbar
|
|
||||||
value={value}
|
|
||||||
onIonInput={onChange}
|
|
||||||
placeholder={placeholder}
|
|
||||||
style={{
|
|
||||||
padding: 0,
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
'--background': 'rgba(255,255,255,0.06)',
|
|
||||||
'--color': 'var(--color-text-primary)',
|
|
||||||
'--placeholder-color': 'rgba(255,255,255,0.45)',
|
|
||||||
'--icon-color': 'rgba(255,255,255,0.75)',
|
|
||||||
'--clear-button-color': 'rgba(255,255,255,0.55)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{onFilterClick && (
|
|
||||||
<IonButton
|
|
||||||
onClick={onFilterClick}
|
|
||||||
style={{
|
|
||||||
'--background': 'rgba(255,255,255,0.06)',
|
|
||||||
'--color': 'var(--color-text-primary)',
|
|
||||||
'--border-radius': '12px',
|
|
||||||
width: '44px',
|
|
||||||
height: '44px',
|
|
||||||
margin: 0,
|
|
||||||
flexShrink: 0,
|
|
||||||
'--padding-start': 0,
|
|
||||||
'--padding-end': 0,
|
|
||||||
'--box-shadow': 'none',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={optionsOutline}
|
|
||||||
slot="icon-only"
|
|
||||||
style={{ fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
</IonButton>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SearchRow;
|
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
import React, { createContext, useContext, useEffect, useState } from 'react';
|
import React, {
|
||||||
import { User, Session } from '@supabase/supabase-js';
|
createContext,
|
||||||
|
useCallback,
|
||||||
|
useContext,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
import { User } from '@supabase/supabase-js';
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
import { Database } from '../database.types';
|
import { Database } from '../database.types';
|
||||||
import { IonSpinner } from '@ionic/react';
|
import { IonSpinner } from '@ionic/react';
|
||||||
@@ -8,11 +14,9 @@ type Profile = Database['public']['Tables']['profiles']['Row'];
|
|||||||
|
|
||||||
interface AuthContextType {
|
interface AuthContextType {
|
||||||
user: User | null;
|
user: User | null;
|
||||||
session: Session | null;
|
|
||||||
profile: Profile | null;
|
profile: Profile | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
refreshProfile: () => Promise<void>;
|
refreshProfile: () => Promise<void>;
|
||||||
signOut: () => Promise<void>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||||
@@ -21,57 +25,117 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
const [user, setUser] = useState<User | null>(null);
|
const [user, setUser] = useState<User | null>(null);
|
||||||
const [session, setSession] = useState<Session | null>(null);
|
|
||||||
const [profile, setProfile] = useState<Profile | null>(null);
|
const [profile, setProfile] = useState<Profile | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const refreshProfile = async (userId?: string) => {
|
const fetchProfile = useCallback(async (currentUser: User) => {
|
||||||
const id = userId || user?.id;
|
try {
|
||||||
if (!id) return;
|
const fallbackProfile = {
|
||||||
|
id: currentUser.id,
|
||||||
|
full_name:
|
||||||
|
typeof currentUser.user_metadata?.full_name === 'string'
|
||||||
|
? currentUser.user_metadata.full_name
|
||||||
|
: '',
|
||||||
|
shop_name: 'My Shop',
|
||||||
|
currency: 'USD',
|
||||||
|
};
|
||||||
|
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from('profiles')
|
.from('profiles')
|
||||||
|
.upsert(fallbackProfile, { onConflict: 'id', ignoreDuplicates: true })
|
||||||
.select('*')
|
.select('*')
|
||||||
.eq('id', id)
|
|
||||||
.single();
|
.single();
|
||||||
|
|
||||||
if (data) {
|
if (error) {
|
||||||
setProfile(data);
|
|
||||||
} else if (error && error.code !== 'PGRST116') {
|
|
||||||
console.error('Error fetching profile:', error);
|
console.error('Error fetching profile:', error);
|
||||||
|
setProfile({
|
||||||
|
...fallbackProfile,
|
||||||
|
created_at: new Date().toISOString(),
|
||||||
|
updated_at: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setProfile(data);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching profile:', err);
|
||||||
|
setProfile(null);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const refreshProfile = async () => {
|
||||||
|
if (user) {
|
||||||
|
await fetchProfile(user);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
supabase.auth.getSession().then(({ data: { session } }) => {
|
let mounted = true;
|
||||||
setSession(session);
|
|
||||||
setUser(session?.user ?? null);
|
const initialiseSession = async () => {
|
||||||
if (session?.user) {
|
const timeout = window.setTimeout(() => {
|
||||||
refreshProfile(session.user.id).finally(() => setLoading(false));
|
if (mounted) {
|
||||||
} else {
|
console.warn('Auth initialisation timed out; showing app shell.');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
});
|
}, 8000);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
data: { session },
|
||||||
|
error,
|
||||||
|
} = await supabase.auth.getSession();
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('Error restoring auth session:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentUser = session?.user ?? null;
|
||||||
|
setUser(currentUser);
|
||||||
|
|
||||||
|
if (currentUser) {
|
||||||
|
await fetchProfile(currentUser);
|
||||||
|
} else {
|
||||||
|
setProfile(null);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error restoring auth session:', err);
|
||||||
|
if (mounted) {
|
||||||
|
setUser(null);
|
||||||
|
setProfile(null);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
window.clearTimeout(timeout);
|
||||||
|
if (mounted) {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void initialiseSession();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: { subscription },
|
data: { subscription },
|
||||||
} = supabase.auth.onAuthStateChange((_event, session) => {
|
} = supabase.auth.onAuthStateChange((_event, session) => {
|
||||||
setSession(session);
|
const currentUser = session?.user ?? null;
|
||||||
setUser(session?.user ?? null);
|
setUser(currentUser);
|
||||||
if (session?.user) {
|
|
||||||
refreshProfile(session.user.id);
|
if (currentUser) {
|
||||||
|
void fetchProfile(currentUser);
|
||||||
} else {
|
} else {
|
||||||
setProfile(null);
|
setProfile(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => subscription.unsubscribe();
|
return () => {
|
||||||
}, []);
|
mounted = false;
|
||||||
|
subscription.unsubscribe();
|
||||||
const signOut = async () => {
|
|
||||||
await supabase.auth.signOut();
|
|
||||||
};
|
};
|
||||||
|
}, [fetchProfile]);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
@@ -81,7 +145,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
height: '100vh',
|
height: '100vh',
|
||||||
background: 'var(--color-bg)',
|
background: 'var(--color-bg, #f0f4ff)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IonSpinner name="crescent" color="primary" />
|
<IonSpinner name="crescent" color="primary" />
|
||||||
@@ -90,9 +154,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthContext.Provider
|
<AuthContext.Provider value={{ user, profile, loading, refreshProfile }}>
|
||||||
value={{ user, session, profile, loading, refreshProfile, signOut }}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</AuthContext.Provider>
|
</AuthContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,610 +14,175 @@ export type Database = {
|
|||||||
}
|
}
|
||||||
public: {
|
public: {
|
||||||
Tables: {
|
Tables: {
|
||||||
check_ins: {
|
credit_customers: {
|
||||||
Row: {
|
Row: {
|
||||||
checked_in_at: string | null
|
created_at: string
|
||||||
expires_at: string
|
|
||||||
id: string
|
id: string
|
||||||
place_id: string
|
name: string
|
||||||
|
notes: string | null
|
||||||
|
phone: string | null
|
||||||
|
updated_at: string
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
checked_in_at?: string | null
|
created_at?: string
|
||||||
expires_at: string
|
|
||||||
id?: string
|
id?: string
|
||||||
place_id: string
|
name: string
|
||||||
|
notes?: string | null
|
||||||
|
phone?: string | null
|
||||||
|
updated_at?: string
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
checked_in_at?: string | null
|
created_at?: string
|
||||||
expires_at?: string
|
|
||||||
id?: string
|
id?: string
|
||||||
place_id?: string
|
name?: string
|
||||||
user_id?: string
|
notes?: string | null
|
||||||
}
|
phone?: string | null
|
||||||
Relationships: [
|
updated_at?: string
|
||||||
{
|
|
||||||
foreignKeyName: "check_ins_place_id_fkey"
|
|
||||||
columns: ["place_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "places"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
foreignKeyName: "check_ins_user_id_fkey"
|
|
||||||
columns: ["user_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
conversations: {
|
|
||||||
Row: {
|
|
||||||
created_at: string | null
|
|
||||||
id: string
|
|
||||||
match_id: string
|
|
||||||
updated_at: string | null
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
match_id: string
|
|
||||||
updated_at?: string | null
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
match_id?: string
|
|
||||||
updated_at?: string | null
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "conversations_match_id_fkey"
|
|
||||||
columns: ["match_id"]
|
|
||||||
isOneToOne: true
|
|
||||||
referencedRelation: "matches"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
discovery_preferences: {
|
|
||||||
Row: {
|
|
||||||
goals: string[]
|
|
||||||
max_age: number
|
|
||||||
max_distance_km: number
|
|
||||||
min_age: number
|
|
||||||
updated_at: string | null
|
|
||||||
user_id: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
goals?: string[]
|
|
||||||
max_age?: number
|
|
||||||
max_distance_km?: number
|
|
||||||
min_age?: number
|
|
||||||
updated_at?: string | null
|
|
||||||
user_id: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
goals?: string[]
|
|
||||||
max_age?: number
|
|
||||||
max_distance_km?: number
|
|
||||||
min_age?: number
|
|
||||||
updated_at?: string | null
|
|
||||||
user_id?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "discovery_preferences_user_id_fkey"
|
|
||||||
columns: ["user_id"]
|
|
||||||
isOneToOne: true
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
matches: {
|
|
||||||
Row: {
|
|
||||||
created_at: string | null
|
|
||||||
id: string
|
|
||||||
last_message_at: string | null
|
|
||||||
user_a: string
|
|
||||||
user_b: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
last_message_at?: string | null
|
|
||||||
user_a: string
|
|
||||||
user_b: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
last_message_at?: string | null
|
|
||||||
user_a?: string
|
|
||||||
user_b?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "matches_user_a_fkey"
|
|
||||||
columns: ["user_a"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
foreignKeyName: "matches_user_b_fkey"
|
|
||||||
columns: ["user_b"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
messages: {
|
|
||||||
Row: {
|
|
||||||
body: string
|
|
||||||
conversation_id: string
|
|
||||||
created_at: string | null
|
|
||||||
id: string
|
|
||||||
read_at: string | null
|
|
||||||
sender_id: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
body: string
|
|
||||||
conversation_id: string
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
read_at?: string | null
|
|
||||||
sender_id: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
body?: string
|
|
||||||
conversation_id?: string
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
read_at?: string | null
|
|
||||||
sender_id?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "messages_conversation_id_fkey"
|
|
||||||
columns: ["conversation_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "conversations"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
foreignKeyName: "messages_sender_id_fkey"
|
|
||||||
columns: ["sender_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
notifications: {
|
|
||||||
Row: {
|
|
||||||
body: string
|
|
||||||
created_at: string | null
|
|
||||||
deep_link: string | null
|
|
||||||
id: string
|
|
||||||
read_at: string | null
|
|
||||||
title: string
|
|
||||||
type: string
|
|
||||||
user_id: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
body: string
|
|
||||||
created_at?: string | null
|
|
||||||
deep_link?: string | null
|
|
||||||
id?: string
|
|
||||||
read_at?: string | null
|
|
||||||
title: string
|
|
||||||
type: string
|
|
||||||
user_id: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
body?: string
|
|
||||||
created_at?: string | null
|
|
||||||
deep_link?: string | null
|
|
||||||
id?: string
|
|
||||||
read_at?: string | null
|
|
||||||
title?: string
|
|
||||||
type?: string
|
|
||||||
user_id?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "notifications_user_id_fkey"
|
|
||||||
columns: ["user_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
payments: {
|
|
||||||
Row: {
|
|
||||||
amount: number
|
|
||||||
created_at: string | null
|
|
||||||
currency: string
|
|
||||||
gateway: string
|
|
||||||
id: string
|
|
||||||
metadata: Json
|
|
||||||
reference: string
|
|
||||||
status: string
|
|
||||||
updated_at: string | null
|
|
||||||
user_id: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
amount: number
|
|
||||||
created_at?: string | null
|
|
||||||
currency?: string
|
|
||||||
gateway?: string
|
|
||||||
id?: string
|
|
||||||
metadata?: Json
|
|
||||||
reference: string
|
|
||||||
status?: string
|
|
||||||
updated_at?: string | null
|
|
||||||
user_id: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
amount?: number
|
|
||||||
created_at?: string | null
|
|
||||||
currency?: string
|
|
||||||
gateway?: string
|
|
||||||
id?: string
|
|
||||||
metadata?: Json
|
|
||||||
reference?: string
|
|
||||||
status?: string
|
|
||||||
updated_at?: string | null
|
|
||||||
user_id?: string
|
user_id?: string
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
places: {
|
credits: {
|
||||||
Row: {
|
Row: {
|
||||||
address: string | null
|
amount: number
|
||||||
busyness: string
|
created_at: string
|
||||||
category: string
|
credit_date: string
|
||||||
created_at: string | null
|
customer_id: string
|
||||||
created_by: string | null
|
|
||||||
description: string | null
|
description: string | null
|
||||||
google_place_id: string | null
|
|
||||||
id: string
|
id: string
|
||||||
image_path: string | null
|
updated_at: string
|
||||||
latitude: number
|
|
||||||
longitude: number
|
|
||||||
name: string
|
|
||||||
rating: number
|
|
||||||
review_count: number
|
|
||||||
updated_at: string | null
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
address?: string | null
|
|
||||||
busyness?: string
|
|
||||||
category?: string
|
|
||||||
created_at?: string | null
|
|
||||||
created_by?: string | null
|
|
||||||
description?: string | null
|
|
||||||
google_place_id?: string | null
|
|
||||||
id?: string
|
|
||||||
image_path?: string | null
|
|
||||||
latitude: number
|
|
||||||
longitude: number
|
|
||||||
name: string
|
|
||||||
rating?: number
|
|
||||||
review_count?: number
|
|
||||||
updated_at?: string | null
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
address?: string | null
|
|
||||||
busyness?: string
|
|
||||||
category?: string
|
|
||||||
created_at?: string | null
|
|
||||||
created_by?: string | null
|
|
||||||
description?: string | null
|
|
||||||
google_place_id?: string | null
|
|
||||||
id?: string
|
|
||||||
image_path?: string | null
|
|
||||||
latitude?: number
|
|
||||||
longitude?: number
|
|
||||||
name?: string
|
|
||||||
rating?: number
|
|
||||||
review_count?: number
|
|
||||||
updated_at?: string | null
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "places_created_by_fkey"
|
|
||||||
columns: ["created_by"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
profile_photos: {
|
|
||||||
Row: {
|
|
||||||
created_at: string | null
|
|
||||||
id: string
|
|
||||||
is_primary: boolean
|
|
||||||
position: number
|
|
||||||
storage_path: string
|
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
created_at?: string | null
|
amount: number
|
||||||
|
created_at?: string
|
||||||
|
credit_date?: string
|
||||||
|
customer_id: string
|
||||||
|
description?: string | null
|
||||||
id?: string
|
id?: string
|
||||||
is_primary?: boolean
|
updated_at?: string
|
||||||
position?: number
|
|
||||||
storage_path: string
|
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
created_at?: string | null
|
amount?: number
|
||||||
|
created_at?: string
|
||||||
|
credit_date?: string
|
||||||
|
customer_id?: string
|
||||||
|
description?: string | null
|
||||||
id?: string
|
id?: string
|
||||||
is_primary?: boolean
|
updated_at?: string
|
||||||
position?: number
|
|
||||||
storage_path?: string
|
|
||||||
user_id?: string
|
user_id?: string
|
||||||
}
|
}
|
||||||
Relationships: [
|
Relationships: [
|
||||||
{
|
{
|
||||||
foreignKeyName: "profile_photos_user_id_fkey"
|
foreignKeyName: "credits_customer_id_fkey"
|
||||||
columns: ["user_id"]
|
columns: ["customer_id"]
|
||||||
isOneToOne: false
|
isOneToOne: false
|
||||||
referencedRelation: "profiles"
|
referencedRelation: "credit_customers"
|
||||||
referencedColumns: ["id"]
|
referencedColumns: ["id"]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
profiles: {
|
profiles: {
|
||||||
Row: {
|
Row: {
|
||||||
avatar_path: string | null
|
created_at: string
|
||||||
bio: string | null
|
currency: string
|
||||||
birth_date: string | null
|
full_name: string | null
|
||||||
city: string | null
|
|
||||||
created_at: string | null
|
|
||||||
fcm_token: string | null
|
|
||||||
full_name: string
|
|
||||||
gender: string | null
|
|
||||||
id: string
|
id: string
|
||||||
interests: string[]
|
shop_name: string | null
|
||||||
latitude: number | null
|
updated_at: string
|
||||||
longitude: number | null
|
|
||||||
onboarding_complete: boolean
|
|
||||||
relationship_goal: string | null
|
|
||||||
updated_at: string | null
|
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
avatar_path?: string | null
|
created_at?: string
|
||||||
bio?: string | null
|
currency?: string
|
||||||
birth_date?: string | null
|
full_name?: string | null
|
||||||
city?: string | null
|
|
||||||
created_at?: string | null
|
|
||||||
fcm_token?: string | null
|
|
||||||
full_name?: string
|
|
||||||
gender?: string | null
|
|
||||||
id: string
|
id: string
|
||||||
interests?: string[]
|
shop_name?: string | null
|
||||||
latitude?: number | null
|
updated_at?: string
|
||||||
longitude?: number | null
|
|
||||||
onboarding_complete?: boolean
|
|
||||||
relationship_goal?: string | null
|
|
||||||
updated_at?: string | null
|
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
avatar_path?: string | null
|
created_at?: string
|
||||||
bio?: string | null
|
currency?: string
|
||||||
birth_date?: string | null
|
full_name?: string | null
|
||||||
city?: string | null
|
|
||||||
created_at?: string | null
|
|
||||||
fcm_token?: string | null
|
|
||||||
full_name?: string
|
|
||||||
gender?: string | null
|
|
||||||
id?: string
|
id?: string
|
||||||
interests?: string[]
|
shop_name?: string | null
|
||||||
latitude?: number | null
|
updated_at?: string
|
||||||
longitude?: number | null
|
|
||||||
onboarding_complete?: boolean
|
|
||||||
relationship_goal?: string | null
|
|
||||||
updated_at?: string | null
|
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
reel_comments: {
|
repayments: {
|
||||||
Row: {
|
Row: {
|
||||||
body: string
|
amount: number
|
||||||
created_at: string | null
|
created_at: string
|
||||||
|
customer_id: string
|
||||||
id: string
|
id: string
|
||||||
reel_id: string
|
note: string | null
|
||||||
|
repayment_date: string
|
||||||
|
updated_at: string
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
body: string
|
amount: number
|
||||||
created_at?: string | null
|
created_at?: string
|
||||||
|
customer_id: string
|
||||||
id?: string
|
id?: string
|
||||||
reel_id: string
|
note?: string | null
|
||||||
|
repayment_date?: string
|
||||||
|
updated_at?: string
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
body?: string
|
amount?: number
|
||||||
created_at?: string | null
|
created_at?: string
|
||||||
|
customer_id?: string
|
||||||
id?: string
|
id?: string
|
||||||
reel_id?: string
|
note?: string | null
|
||||||
|
repayment_date?: string
|
||||||
|
updated_at?: string
|
||||||
user_id?: string
|
user_id?: string
|
||||||
}
|
}
|
||||||
Relationships: [
|
Relationships: [
|
||||||
{
|
{
|
||||||
foreignKeyName: "reel_comments_reel_id_fkey"
|
foreignKeyName: "repayments_customer_id_fkey"
|
||||||
columns: ["reel_id"]
|
columns: ["customer_id"]
|
||||||
isOneToOne: false
|
isOneToOne: false
|
||||||
referencedRelation: "reels"
|
referencedRelation: "credit_customers"
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
foreignKeyName: "reel_comments_user_id_fkey"
|
|
||||||
columns: ["user_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
referencedColumns: ["id"]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
reel_likes: {
|
sales: {
|
||||||
Row: {
|
Row: {
|
||||||
created_at: string | null
|
amount: number
|
||||||
reel_id: string
|
created_at: string
|
||||||
user_id: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
created_at?: string | null
|
|
||||||
reel_id: string
|
|
||||||
user_id: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
created_at?: string | null
|
|
||||||
reel_id?: string
|
|
||||||
user_id?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "reel_likes_reel_id_fkey"
|
|
||||||
columns: ["reel_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "reels"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
foreignKeyName: "reel_likes_user_id_fkey"
|
|
||||||
columns: ["user_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
reels: {
|
|
||||||
Row: {
|
|
||||||
author_id: string
|
|
||||||
caption: string
|
|
||||||
comments_count: number
|
|
||||||
created_at: string | null
|
|
||||||
id: string
|
id: string
|
||||||
likes_count: number
|
note: string | null
|
||||||
media_path: string
|
sale_date: string
|
||||||
media_type: string
|
updated_at: string
|
||||||
place_id: string
|
|
||||||
shares_count: number
|
|
||||||
thumbnail_path: string | null
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
author_id: string
|
|
||||||
caption?: string
|
|
||||||
comments_count?: number
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
likes_count?: number
|
|
||||||
media_path: string
|
|
||||||
media_type: string
|
|
||||||
place_id: string
|
|
||||||
shares_count?: number
|
|
||||||
thumbnail_path?: string | null
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
author_id?: string
|
|
||||||
caption?: string
|
|
||||||
comments_count?: number
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
likes_count?: number
|
|
||||||
media_path?: string
|
|
||||||
media_type?: string
|
|
||||||
place_id?: string
|
|
||||||
shares_count?: number
|
|
||||||
thumbnail_path?: string | null
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "reels_author_id_fkey"
|
|
||||||
columns: ["author_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
foreignKeyName: "reels_place_id_fkey"
|
|
||||||
columns: ["place_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "places"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
subscriptions: {
|
|
||||||
Row: {
|
|
||||||
active_until: string | null
|
|
||||||
tier: string
|
|
||||||
updated_at: string | null
|
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
active_until?: string | null
|
amount: number
|
||||||
tier?: string
|
created_at?: string
|
||||||
updated_at?: string | null
|
id?: string
|
||||||
|
note?: string | null
|
||||||
|
sale_date?: string
|
||||||
|
updated_at?: string
|
||||||
user_id: string
|
user_id: string
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
active_until?: string | null
|
amount?: number
|
||||||
tier?: string
|
created_at?: string
|
||||||
updated_at?: string | null
|
id?: string
|
||||||
|
note?: string | null
|
||||||
|
sale_date?: string
|
||||||
|
updated_at?: string
|
||||||
user_id?: string
|
user_id?: string
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
swipes: {
|
|
||||||
Row: {
|
|
||||||
action: string
|
|
||||||
created_at: string | null
|
|
||||||
id: string
|
|
||||||
swiped_id: string
|
|
||||||
swiper_id: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
action: string
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
swiped_id: string
|
|
||||||
swiper_id: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
action?: string
|
|
||||||
created_at?: string | null
|
|
||||||
id?: string
|
|
||||||
swiped_id?: string
|
|
||||||
swiper_id?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "swipes_swiped_id_fkey"
|
|
||||||
columns: ["swiped_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
foreignKeyName: "swipes_swiper_id_fkey"
|
|
||||||
columns: ["swiper_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Views: {
|
Views: {
|
||||||
[_ in never]: never
|
[_ in never]: never
|
||||||
|
|||||||
@@ -1,118 +1,86 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
IonPage,
|
|
||||||
IonContent,
|
IonContent,
|
||||||
|
IonPage,
|
||||||
IonInput,
|
IonInput,
|
||||||
IonItem,
|
|
||||||
IonButton,
|
IonButton,
|
||||||
IonSpinner,
|
IonSpinner,
|
||||||
useIonViewWillEnter,
|
IonIcon,
|
||||||
IonRouterLink,
|
IonText,
|
||||||
} from '@ionic/react';
|
} from '@ionic/react';
|
||||||
|
import { storefrontOutline } from 'ionicons/icons';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { mail, lockClosed, logoFacebook } from 'ionicons/icons';
|
|
||||||
import { IonIcon } from '@ionic/react';
|
|
||||||
import { enablePreviewMode } from '../utils/previewMode';
|
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import { Capacitor } from '@capacitor/core';
|
|
||||||
import { FirebaseAuthentication } from '@capacitor-firebase/authentication';
|
|
||||||
|
|
||||||
const AuthPage: React.FC = () => {
|
const AuthPage: React.FC = () => {
|
||||||
const history = useHistory();
|
|
||||||
const [mode, setMode] = useState<'signin' | 'signup'>('signin');
|
const [mode, setMode] = useState<'signin' | 'signup'>('signin');
|
||||||
|
const [name, setName] = useState('');
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [message, setMessage] = useState<string | null>(null);
|
||||||
|
const [messageType, setMessageType] = useState<'error' | 'success'>('error');
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
const history = useHistory();
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
});
|
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
const showMessage = (msg: string, type: 'error' | 'success' = 'error') => {
|
||||||
setError(msg);
|
setMessage(msg);
|
||||||
setTimeout(() => setError(null), 4000);
|
setMessageType(type);
|
||||||
|
setTimeout(() => setMessage(null), 4000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAuth = async (e: React.FormEvent) => {
|
const handleAuth = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setLoading(true);
|
if (!email || !password || (mode === 'signup' && !name)) {
|
||||||
|
showMessage('Please fill in all fields');
|
||||||
try {
|
|
||||||
if (mode === 'signin') {
|
|
||||||
const { error } = await supabase.auth.signInWithPassword({
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
});
|
|
||||||
if (error) {
|
|
||||||
if (error.message.toLowerCase().includes('email not confirmed')) {
|
|
||||||
await supabase.auth.resend({ type: 'signup', email });
|
|
||||||
history.push('/verify-email', { email, type: 'signup' });
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw error;
|
|
||||||
}
|
setSubmitting(true);
|
||||||
history.push('/icebreaker');
|
setMessage(null);
|
||||||
} else {
|
|
||||||
|
try {
|
||||||
|
if (mode === 'signup') {
|
||||||
const { data, error } = await supabase.auth.signUp({
|
const { data, error } = await supabase.auth.signUp({
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
options: {
|
options: {
|
||||||
data: { onboarding_complete: false },
|
data: {
|
||||||
|
full_name: name,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
|
|
||||||
if (data.session) {
|
if (data.session) {
|
||||||
history.push('/onboarding/profile');
|
history.push('/home');
|
||||||
} else {
|
} else {
|
||||||
history.push('/verify-email', { email, type: 'signup' });
|
history.push('/verify-email', { email });
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} catch (err: any) {
|
const { data, error } = await supabase.auth.signInWithPassword({
|
||||||
showError(err.message);
|
email,
|
||||||
} finally {
|
password,
|
||||||
setLoading(false);
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const enterPreviewMode = () => {
|
if (error) {
|
||||||
enablePreviewMode();
|
if (error.message.toLowerCase().includes('email not confirmed')) {
|
||||||
history.push('/icebreaker');
|
await supabase.auth.resend({ type: 'signup', email });
|
||||||
};
|
history.push('/verify-email', { email, resent: true });
|
||||||
|
|
||||||
const handleSocialSignIn = async (provider: 'google' | 'apple') => {
|
|
||||||
if (!Capacitor.isNativePlatform()) {
|
|
||||||
showError(
|
|
||||||
`${provider === 'google' ? 'Google' : 'Apple'} Sign-In is only available on native devices.`
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
throw error;
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
let result;
|
|
||||||
if (provider === 'google') {
|
|
||||||
result = await FirebaseAuthentication.signInWithGoogle();
|
|
||||||
} else {
|
|
||||||
result = await FirebaseAuthentication.signInWithApple({
|
|
||||||
skipNativeAuth: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { error } = await supabase.auth.signInWithIdToken({
|
if (data.session) {
|
||||||
provider,
|
history.push('/home');
|
||||||
token: result.credential!.idToken!,
|
}
|
||||||
nonce: result.credential?.nonce,
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (error) throw error;
|
|
||||||
history.push('/icebreaker');
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showError(err.message);
|
showMessage(err.message || 'An authentication error occurred');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -120,301 +88,141 @@ const AuthPage: React.FC = () => {
|
|||||||
<IonPage>
|
<IonPage>
|
||||||
<IonContent
|
<IonContent
|
||||||
fullscreen
|
fullscreen
|
||||||
className="ion-padding"
|
|
||||||
style={{
|
style={{
|
||||||
'--background': 'var(--color-bg)',
|
'--background':
|
||||||
display: 'flex',
|
'linear-gradient(160deg, rgba(199,210,254,0.52) 0%, #f0f4ff 58%, #f8fafc 100%)',
|
||||||
flexDirection: 'column',
|
|
||||||
paddingTop: 'calc(var(--ion-safe-area-top) + 40px)',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ padding: '0 20px' }}>
|
<div className="auth-shell">
|
||||||
<div style={{ marginBottom: '44px', paddingTop: '24px' }}>
|
|
||||||
<h1
|
|
||||||
style={{
|
|
||||||
fontSize: '28px',
|
|
||||||
fontWeight: 800,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
margin: '0 0 42px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{mode === 'signin' ? 'Hi there, 👋' : 'Create account'}
|
|
||||||
</h1>
|
|
||||||
<h2
|
|
||||||
style={{
|
|
||||||
fontSize: '24px',
|
|
||||||
fontWeight: 700,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
margin: '0 0 12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{mode === 'signin'
|
|
||||||
? 'Sign in to continue'
|
|
||||||
: 'Sign up to continue'}
|
|
||||||
</h2>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '16px',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
margin: 0,
|
|
||||||
lineHeight: 1.35,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{mode === 'signin'
|
|
||||||
? "Don't have an account? Enter your email and password or choose one of the options below."
|
|
||||||
: 'Enter your email and password to start discovering people and places nearby.'}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
background: 'var(--color-surface-raised)',
|
alignItems: 'center',
|
||||||
padding: '4px',
|
gap: '12px',
|
||||||
borderRadius: 'var(--radius-pill)',
|
marginTop: '20px',
|
||||||
marginBottom: '20px',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{(['signin', 'signup'] as const).map((m) => (
|
<div
|
||||||
|
className="icon-container"
|
||||||
|
style={{ width: '44px', height: '44px' }}
|
||||||
|
>
|
||||||
|
<IonIcon icon={storefrontOutline} style={{ fontSize: '22px' }} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h1 className="bold" style={{ margin: '0', fontSize: '22px' }}>
|
||||||
|
ShopKeep
|
||||||
|
</h1>
|
||||||
|
<p className="secondary-text" style={{ margin: '0' }}>
|
||||||
|
Simple bookkeeping for you
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="auth-card">
|
||||||
|
<div className="pill-toggle">
|
||||||
<button
|
<button
|
||||||
key={m}
|
className={`pill-toggle-btn ${mode === 'signin' ? 'active' : ''}`}
|
||||||
onClick={() => setMode(m)}
|
onClick={() => setMode('signin')}
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
padding: '10px',
|
|
||||||
borderRadius: 'var(--radius-pill)',
|
|
||||||
border: 'none',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: 700,
|
|
||||||
transition: '0.2s',
|
|
||||||
background:
|
|
||||||
mode === m ? 'var(--ion-color-primary)' : 'transparent',
|
|
||||||
color: mode === m ? '#ffffff' : 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{m === 'signin' ? 'Sign In' : 'Sign Up'}
|
Sign in
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`pill-toggle-btn ${mode === 'signup' ? 'active' : ''}`}
|
||||||
|
onClick={() => setMode('signup')}
|
||||||
|
>
|
||||||
|
Create account
|
||||||
</button>
|
</button>
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
onSubmit={handleAuth}
|
onSubmit={handleAuth}
|
||||||
style={{
|
style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}
|
||||||
background: 'transparent',
|
|
||||||
padding: '0',
|
|
||||||
borderRadius: '0',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<IonItem
|
{mode === 'signup' && (
|
||||||
lines="none"
|
<div className="input-wrapper">
|
||||||
style={{
|
<IonInput
|
||||||
'--background': 'var(--color-input)',
|
label="Full Name"
|
||||||
'--border-radius': 'var(--radius-control)',
|
labelPlacement="floating"
|
||||||
'--border-width': '1px',
|
placeholder="Enter your name"
|
||||||
'--border-style': 'solid',
|
value={name}
|
||||||
'--border-color': 'var(--color-text-secondary)',
|
onIonChange={(e) => setName(e.detail.value!)}
|
||||||
'--min-height': '48px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={mail}
|
|
||||||
slot="start"
|
|
||||||
style={{ color: 'var(--ion-color-primary)', fontSize: '20px' }}
|
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="input-wrapper">
|
||||||
<IonInput
|
<IonInput
|
||||||
label="Email"
|
label="Email"
|
||||||
labelPlacement="floating"
|
labelPlacement="floating"
|
||||||
type="email"
|
type="email"
|
||||||
|
placeholder="name@example.com"
|
||||||
value={email}
|
value={email}
|
||||||
onIonInput={(e) => setEmail(e.detail.value!)}
|
onIonChange={(e) => setEmail(e.detail.value!)}
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
</IonItem>
|
</div>
|
||||||
|
|
||||||
<IonItem
|
<div className="input-wrapper">
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-input)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
'--border-width': '1px',
|
|
||||||
'--border-style': 'solid',
|
|
||||||
'--border-color': 'var(--color-text-secondary)',
|
|
||||||
'--min-height': '48px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={lockClosed}
|
|
||||||
slot="start"
|
|
||||||
style={{ color: 'var(--ion-color-primary)', fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
<IonInput
|
<IonInput
|
||||||
label="Password"
|
label="Password"
|
||||||
labelPlacement="floating"
|
labelPlacement="floating"
|
||||||
type="password"
|
type="password"
|
||||||
|
placeholder="Min. 6 characters"
|
||||||
value={password}
|
value={password}
|
||||||
onIonInput={(e) => setPassword(e.detail.value!)}
|
onIonChange={(e) => setPassword(e.detail.value!)}
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
</IonItem>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{message && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
background: 'rgba(220, 38, 38, 0.08)',
|
background:
|
||||||
color: 'var(--ion-color-danger)',
|
messageType === 'error'
|
||||||
|
? 'var(--color-danger-soft)'
|
||||||
|
: 'var(--color-success-soft)',
|
||||||
|
color:
|
||||||
|
messageType === 'error'
|
||||||
|
? 'var(--ion-color-danger-shade)'
|
||||||
|
: 'var(--ion-color-success-shade)',
|
||||||
padding: '12px',
|
padding: '12px',
|
||||||
borderRadius: 'var(--radius-control)',
|
borderRadius: '12px',
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{error}
|
{message}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<IonButton
|
<IonButton
|
||||||
type="submit"
|
type="submit"
|
||||||
expand="block"
|
expand="block"
|
||||||
disabled={loading}
|
className="bold"
|
||||||
style={{
|
style={{
|
||||||
|
height: '52px',
|
||||||
'--border-radius': 'var(--radius-pill)',
|
'--border-radius': 'var(--radius-pill)',
|
||||||
'--color': '#000000',
|
marginTop: '8px',
|
||||||
fontWeight: 800,
|
|
||||||
height: '48px',
|
|
||||||
margin: '8px 28px 0',
|
|
||||||
}}
|
}}
|
||||||
|
disabled={submitting}
|
||||||
>
|
>
|
||||||
{loading ? (
|
{submitting ? (
|
||||||
<IonSpinner name="crescent" />
|
<IonSpinner name="crescent" />
|
||||||
) : mode === 'signin' ? (
|
) : mode === 'signin' ? (
|
||||||
'Sign in'
|
'Sign in'
|
||||||
) : (
|
) : (
|
||||||
'Continue'
|
'Create account'
|
||||||
)}
|
)}
|
||||||
</IonButton>
|
</IonButton>
|
||||||
|
|
||||||
{mode === 'signin' && (
|
|
||||||
<IonRouterLink
|
|
||||||
routerLink="/forgot-password"
|
|
||||||
style={{
|
|
||||||
textAlign: 'center',
|
|
||||||
fontSize: '13px',
|
|
||||||
color: 'var(--ion-color-primary)',
|
|
||||||
marginTop: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Forgot password?
|
|
||||||
</IonRouterLink>
|
|
||||||
)}
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div
|
<div style={{ textAlign: 'center', marginTop: '8px' }}>
|
||||||
style={{
|
<IonText
|
||||||
textAlign: 'center',
|
color="primary"
|
||||||
margin: '56px 0 26px',
|
className="semibold"
|
||||||
fontSize: '13px',
|
style={{ fontSize: '13px', cursor: 'pointer' }}
|
||||||
color: 'var(--color-text-tertiary)',
|
onClick={() => history.push('/forgot-password')}
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
OR
|
Forgot password?
|
||||||
|
</IonText>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
padding: '0 28px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonButton
|
|
||||||
expand="block"
|
|
||||||
onClick={() => handleSocialSignIn('apple')}
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
'--background': '#ffffff',
|
|
||||||
'--color': '#000000',
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
'--box-shadow': 'none',
|
|
||||||
height: '48px',
|
|
||||||
fontWeight: 800,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
width="18"
|
|
||||||
height="18"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="currentColor"
|
|
||||||
style={{ marginRight: '10px' }}
|
|
||||||
>
|
|
||||||
<path d="M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.8-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M13 3.5c.73-.83 1.94-1.46 2.94-1.5.13 1.17-.34 2.35-1.04 3.19-.69.85-1.83 1.51-2.95 1.42-.15-1.15.41-2.35 1.05-3.11z" />
|
|
||||||
</svg>
|
|
||||||
Sign in with Apple
|
|
||||||
</IonButton>
|
|
||||||
<IonButton
|
|
||||||
expand="block"
|
|
||||||
onClick={() =>
|
|
||||||
showError(
|
|
||||||
'Facebook Sign-In is only available on native devices.'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
'--background': '#ffffff',
|
|
||||||
'--color': '#000000',
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
'--box-shadow': 'none',
|
|
||||||
height: '48px',
|
|
||||||
fontWeight: 800,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={logoFacebook}
|
|
||||||
style={{ marginRight: '10px', fontSize: '22px' }}
|
|
||||||
/>
|
|
||||||
Sign in with Facebook
|
|
||||||
</IonButton>
|
|
||||||
<IonButton
|
|
||||||
expand="block"
|
|
||||||
onClick={() => handleSocialSignIn('google')}
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
'--background': '#ffffff',
|
|
||||||
'--color': '#000000',
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
'--box-shadow': 'none',
|
|
||||||
height: '48px',
|
|
||||||
fontWeight: 800,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '24px',
|
|
||||||
fontWeight: 900,
|
|
||||||
marginRight: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
G
|
|
||||||
</span>
|
|
||||||
Sign in with Google
|
|
||||||
</IonButton>
|
|
||||||
<IonButton
|
|
||||||
expand="block"
|
|
||||||
onClick={enterPreviewMode}
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
'--background': 'var(--ion-color-primary)',
|
|
||||||
'--color': '#000000',
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
'--box-shadow': 'none',
|
|
||||||
height: '48px',
|
|
||||||
fontWeight: 800,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Preview with dummy data
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
|
|||||||
@@ -1,311 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonIcon,
|
|
||||||
IonButton,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
IonModal,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonTitle,
|
|
||||||
IonButtons,
|
|
||||||
IonItem,
|
|
||||||
IonTextarea,
|
|
||||||
IonSelect,
|
|
||||||
IonSelectOption,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
closeOutline,
|
|
||||||
cameraOutline,
|
|
||||||
imageOutline,
|
|
||||||
sendOutline,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
|
|
||||||
const CameraPage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const [file, setFile] = useState<File | null>(null);
|
|
||||||
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
|
||||||
const [caption, setCaption] = useState('');
|
|
||||||
const [placeId, setPlaceId] = useState<string | null>(null);
|
|
||||||
const [places, setPlaces] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [uploading, setUploading] = useState(false);
|
|
||||||
const [isPublishOpen, setIsPublishOpen] = useState(false);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
fetchPlaces();
|
|
||||||
});
|
|
||||||
|
|
||||||
const fetchPlaces = async () => {
|
|
||||||
const { data } = await supabase.from('places').select('id, name');
|
|
||||||
setPlaces(data || []);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const selectedFile = e.target.files?.[0];
|
|
||||||
if (selectedFile) {
|
|
||||||
setFile(selectedFile);
|
|
||||||
setPreviewUrl(URL.createObjectURL(selectedFile));
|
|
||||||
setIsPublishOpen(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePublish = async () => {
|
|
||||||
if (!file || !user || !placeId) {
|
|
||||||
setError('Please select a place and add a file.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setUploading(true);
|
|
||||||
try {
|
|
||||||
const fileExt = file.name.split('.').pop();
|
|
||||||
const fileName = `${user.id}-${Date.now()}.${fileExt}`;
|
|
||||||
const filePath = `${fileName}`;
|
|
||||||
|
|
||||||
// 1. Upload to storage
|
|
||||||
const { error: uploadError } = await supabase.storage
|
|
||||||
.from('reels')
|
|
||||||
.upload(filePath, file);
|
|
||||||
|
|
||||||
if (uploadError) throw uploadError;
|
|
||||||
|
|
||||||
// 2. Create reel record
|
|
||||||
const { error: reelError } = await supabase.from('reels').insert({
|
|
||||||
author_id: user.id,
|
|
||||||
place_id: placeId,
|
|
||||||
caption,
|
|
||||||
media_path: filePath,
|
|
||||||
media_type: file.type.startsWith('video') ? 'video' : 'image',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (reelError) throw reelError;
|
|
||||||
|
|
||||||
history.replace(`/reels/${placeId}`);
|
|
||||||
} catch (err: any) {
|
|
||||||
setError(err.message);
|
|
||||||
} finally {
|
|
||||||
setUploading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonContent fullscreen style={{ '--background': '#000000' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 'calc(14px + var(--ion-safe-area-top))',
|
|
||||||
left: '20px',
|
|
||||||
zIndex: 10,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonButton
|
|
||||||
fill="clear"
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{
|
|
||||||
'--background': 'rgba(0,0,0,0.3)',
|
|
||||||
'--color': '#ffffff',
|
|
||||||
'--border-radius': '50%',
|
|
||||||
width: '40px',
|
|
||||||
height: '40px',
|
|
||||||
margin: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon icon={closeOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: '100%',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
color: '#ffffff',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '120px',
|
|
||||||
height: '120px',
|
|
||||||
borderRadius: '50%',
|
|
||||||
background: 'rgba(255, 255, 255, 0.1)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
marginBottom: '24px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={cameraOutline}
|
|
||||||
style={{ fontSize: '48px', opacity: 0.5 }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<h2
|
|
||||||
style={{ fontSize: '20px', fontWeight: 800, marginBottom: '8px' }}
|
|
||||||
>
|
|
||||||
Create a Reel
|
|
||||||
</h2>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
opacity: 0.6,
|
|
||||||
fontSize: '14px',
|
|
||||||
marginBottom: '32px',
|
|
||||||
textAlign: 'center',
|
|
||||||
padding: '0 40px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Share your experience at a local spot. Select a photo or video to
|
|
||||||
begin.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
background: 'var(--ion-color-primary)',
|
|
||||||
color: '#ffffff',
|
|
||||||
padding: '14px 32px',
|
|
||||||
borderRadius: 'var(--radius-pill)',
|
|
||||||
fontWeight: 700,
|
|
||||||
fontSize: '15px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon icon={imageOutline} style={{ fontSize: '20px' }} />
|
|
||||||
Select Media
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
accept="image/*,video/*"
|
|
||||||
onChange={handleFileChange}
|
|
||||||
hidden
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Publish Modal */}
|
|
||||||
<IonModal
|
|
||||||
isOpen={isPublishOpen}
|
|
||||||
onDidDismiss={() => {
|
|
||||||
setIsPublishOpen(false);
|
|
||||||
setPreviewUrl(null);
|
|
||||||
setFile(null);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonHeader>
|
|
||||||
<IonToolbar>
|
|
||||||
<IonTitle>New Reel</IonTitle>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton onClick={() => setIsPublishOpen(false)}>
|
|
||||||
Cancel
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonButtons slot="end">
|
|
||||||
<IonButton
|
|
||||||
onClick={handlePublish}
|
|
||||||
disabled={uploading || !placeId}
|
|
||||||
>
|
|
||||||
{uploading ? <IonSpinner name="crescent" /> : 'Share'}
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
<IonContent className="ion-padding">
|
|
||||||
<div style={{ display: 'flex', gap: '16px', marginBottom: '24px' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '100px',
|
|
||||||
height: '140px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
overflow: 'hidden',
|
|
||||||
background: '#000',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{file?.type.startsWith('video') ? (
|
|
||||||
<video
|
|
||||||
src={previewUrl || ''}
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
objectFit: 'cover',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<img
|
|
||||||
src={previewUrl || ''}
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
objectFit: 'cover',
|
|
||||||
}}
|
|
||||||
alt="Preview"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<IonTextarea
|
|
||||||
placeholder="Write a caption..."
|
|
||||||
value={caption}
|
|
||||||
onIonInput={(e) => setCaption(e.detail.value!)}
|
|
||||||
rows={6}
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--padding-start': '12px',
|
|
||||||
'--border-radius': '12px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSelect
|
|
||||||
label="Tag a place"
|
|
||||||
labelPlacement="floating"
|
|
||||||
placeholder="Select place"
|
|
||||||
value={placeId}
|
|
||||||
onIonChange={(e) => setPlaceId(e.detail.value)}
|
|
||||||
>
|
|
||||||
{places.map((p) => (
|
|
||||||
<IonSelectOption key={p.id} value={p.id}>
|
|
||||||
{p.name}
|
|
||||||
</IonSelectOption>
|
|
||||||
))}
|
|
||||||
</IonSelect>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
color: 'var(--ion-color-danger)',
|
|
||||||
fontSize: '13px',
|
|
||||||
marginTop: '12px',
|
|
||||||
padding: '0 4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</IonContent>
|
|
||||||
</IonModal>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CameraPage;
|
|
||||||
@@ -1,263 +0,0 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonTitle,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonInput,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { chevronBackOutline, sendOutline } from 'ionicons/icons';
|
|
||||||
import { useHistory, useParams } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import Avatar from '../components/Avatar';
|
|
||||||
import { previewChats, previewMessages } from '../utils/previewData';
|
|
||||||
import { isPreviewMode } from '../utils/previewMode';
|
|
||||||
|
|
||||||
const ChatThreadPage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { conversationId } = useParams<{ conversationId: string }>();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const previewMode = isPreviewMode();
|
|
||||||
const [messages, setMessages] = useState<any[]>([]);
|
|
||||||
const [otherUser, setOtherUser] = useState<any>(null);
|
|
||||||
const [text, setText] = useState('');
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [sending, setSending] = useState(false);
|
|
||||||
const scrollRef = useRef<HTMLIonContentElement>(null);
|
|
||||||
|
|
||||||
const fetchThread = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
if (previewMode) {
|
|
||||||
const chat =
|
|
||||||
previewChats.find((item) => item.id === conversationId) ||
|
|
||||||
previewChats[0];
|
|
||||||
setOtherUser(chat.otherUser);
|
|
||||||
setMessages(previewMessages[chat.id] || []);
|
|
||||||
setLoading(false);
|
|
||||||
setTimeout(() => scrollRef.current?.scrollToBottom(300), 100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!user) return;
|
|
||||||
try {
|
|
||||||
// 1. Get other participant
|
|
||||||
const { data: conv } = await supabase
|
|
||||||
.from('conversations')
|
|
||||||
.select(
|
|
||||||
`
|
|
||||||
match_id,
|
|
||||||
matches(
|
|
||||||
user_a:profiles!matches_user_a_fkey(id, full_name, avatar_path),
|
|
||||||
user_b:profiles!matches_user_b_fkey(id, full_name, avatar_path)
|
|
||||||
)
|
|
||||||
`
|
|
||||||
)
|
|
||||||
.eq('id', conversationId)
|
|
||||||
.single();
|
|
||||||
|
|
||||||
if (conv) {
|
|
||||||
const match = (conv as any).matches;
|
|
||||||
setOtherUser(match.user_a.id === user.id ? match.user_b : match.user_a);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Get messages
|
|
||||||
const { data: msgs } = await supabase
|
|
||||||
.from('messages')
|
|
||||||
.select('*')
|
|
||||||
.eq('conversation_id', conversationId)
|
|
||||||
.order('created_at', { ascending: true });
|
|
||||||
|
|
||||||
setMessages(msgs || []);
|
|
||||||
setTimeout(() => scrollRef.current?.scrollToBottom(300), 100);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Fetch thread error:', err);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
fetchThread();
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSend = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (!text.trim() || (!user && !previewMode) || sending) return;
|
|
||||||
|
|
||||||
setSending(true);
|
|
||||||
const msgBody = text.trim();
|
|
||||||
setText('');
|
|
||||||
|
|
||||||
if (previewMode) {
|
|
||||||
const previewMessage = {
|
|
||||||
id: `preview-message-${Date.now()}`,
|
|
||||||
sender_id: 'preview-me',
|
|
||||||
body: msgBody,
|
|
||||||
created_at: new Date().toISOString(),
|
|
||||||
};
|
|
||||||
setMessages((prev) => [...prev, previewMessage]);
|
|
||||||
setTimeout(() => scrollRef.current?.scrollToBottom(300), 100);
|
|
||||||
setSending(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { data, error } = await supabase
|
|
||||||
.from('messages')
|
|
||||||
.insert({
|
|
||||||
conversation_id: conversationId,
|
|
||||||
sender_id: user.id,
|
|
||||||
body: msgBody,
|
|
||||||
})
|
|
||||||
.select()
|
|
||||||
.single();
|
|
||||||
|
|
||||||
if (error) throw error;
|
|
||||||
setMessages((prev) => [...prev, data]);
|
|
||||||
setTimeout(() => scrollRef.current?.scrollToBottom(300), 100);
|
|
||||||
|
|
||||||
// Invoke notification
|
|
||||||
supabase.functions.invoke('send-message-notification', {
|
|
||||||
body: { conversationId, messageId: data.id },
|
|
||||||
});
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Send error:', err);
|
|
||||||
} finally {
|
|
||||||
setSending(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ '--color': 'var(--color-text-primary)' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle>
|
|
||||||
{otherUser && (
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
|
|
||||||
>
|
|
||||||
<Avatar
|
|
||||||
src={otherUser.avatar_path}
|
|
||||||
name={otherUser.full_name}
|
|
||||||
size={32}
|
|
||||||
/>
|
|
||||||
<span style={{ fontSize: '16px', fontWeight: 700 }}>
|
|
||||||
{otherUser.full_name}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent
|
|
||||||
ref={scrollRef}
|
|
||||||
style={{ '--background': 'var(--color-bg)' }}
|
|
||||||
className="ion-padding"
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<div style={{ textAlign: 'center', padding: '40px' }}>
|
|
||||||
<IonSpinner name="crescent" color="primary" />
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '8px',
|
|
||||||
paddingBottom: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{messages.map((msg) => {
|
|
||||||
const isMine = previewMode
|
|
||||||
? msg.sender_id === 'preview-me'
|
|
||||||
: msg.sender_id === user?.id;
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
key={msg.id}
|
|
||||||
style={{
|
|
||||||
alignSelf: isMine ? 'flex-end' : 'flex-start',
|
|
||||||
maxWidth: '78%',
|
|
||||||
background: isMine
|
|
||||||
? 'var(--ion-color-primary)'
|
|
||||||
: 'var(--color-surface)',
|
|
||||||
color: isMine ? '#ffffff' : 'var(--color-text-primary)',
|
|
||||||
padding: '10px 14px',
|
|
||||||
borderRadius: isMine
|
|
||||||
? '18px 18px 4px 18px'
|
|
||||||
: '18px 18px 18px 4px',
|
|
||||||
fontSize: '14px',
|
|
||||||
lineHeight: 1.4,
|
|
||||||
boxShadow: '0 2px 8px rgba(76, 5, 25, 0.02)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{msg.body}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</IonContent>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: '#ffffff',
|
|
||||||
padding: '10px 20px calc(10px + var(--ion-safe-area-bottom))',
|
|
||||||
borderTop: '1px solid var(--color-border)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<form
|
|
||||||
onSubmit={handleSend}
|
|
||||||
style={{ display: 'flex', gap: '12px', alignItems: 'center' }}
|
|
||||||
>
|
|
||||||
<IonInput
|
|
||||||
value={text}
|
|
||||||
onIonInput={(e) => setText(e.detail.value!)}
|
|
||||||
placeholder="Type a message..."
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
'--padding-start': '16px',
|
|
||||||
fontSize: '14px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<IonButton
|
|
||||||
type="submit"
|
|
||||||
disabled={!text.trim() || sending}
|
|
||||||
style={{
|
|
||||||
'--border-radius': '50%',
|
|
||||||
width: '44px',
|
|
||||||
height: '44px',
|
|
||||||
margin: 0,
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{sending ? (
|
|
||||||
<IonSpinner name="crescent" />
|
|
||||||
) : (
|
|
||||||
<IonIcon icon={sendOutline} slot="icon-only" />
|
|
||||||
)}
|
|
||||||
</IonButton>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ChatThreadPage;
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
IonRefresher,
|
|
||||||
IonRefresherContent,
|
|
||||||
IonIcon,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { chatbubbleEllipsesOutline } from 'ionicons/icons';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import { formatTime } from '../utils/format';
|
|
||||||
import SearchRow from '../components/SearchRow';
|
|
||||||
import Avatar from '../components/Avatar';
|
|
||||||
import EmptyState from '../components/EmptyState';
|
|
||||||
import { previewChats } from '../utils/previewData';
|
|
||||||
import { isPreviewMode } from '../utils/previewMode';
|
|
||||||
|
|
||||||
const ChatsPage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const previewMode = isPreviewMode();
|
|
||||||
const [chats, setChats] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [query, setQuery] = useState('');
|
|
||||||
|
|
||||||
const fetchChats = async () => {
|
|
||||||
if (previewMode) {
|
|
||||||
setChats(previewChats);
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!user) return;
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const { data, error } = await supabase
|
|
||||||
.from('matches')
|
|
||||||
.select(
|
|
||||||
`
|
|
||||||
id,
|
|
||||||
last_message_at,
|
|
||||||
user_a:profiles!matches_user_a_fkey(id, full_name, avatar_path),
|
|
||||||
user_b:profiles!matches_user_b_fkey(id, full_name, avatar_path),
|
|
||||||
conversations(
|
|
||||||
id,
|
|
||||||
messages(
|
|
||||||
body,
|
|
||||||
created_at
|
|
||||||
)
|
|
||||||
)
|
|
||||||
`
|
|
||||||
)
|
|
||||||
.or(`user_a.eq.${user.id},user_b.eq.${user.id}`)
|
|
||||||
.order('last_message_at', { ascending: false });
|
|
||||||
|
|
||||||
if (error) throw error;
|
|
||||||
|
|
||||||
const formatted =
|
|
||||||
data?.map((m) => {
|
|
||||||
const otherUser = m.user_a.id === user.id ? m.user_b : m.user_a;
|
|
||||||
const conversation = m.conversations?.[0];
|
|
||||||
const lastMsg = conversation?.messages?.[0]; // ordered by handle-swipe or trigger later
|
|
||||||
return {
|
|
||||||
id: conversation?.id,
|
|
||||||
otherUser,
|
|
||||||
lastMessage: lastMsg?.body || 'New match! Start chatting.',
|
|
||||||
timestamp: m.last_message_at || lastMsg?.created_at,
|
|
||||||
};
|
|
||||||
}) || [];
|
|
||||||
|
|
||||||
setChats(formatted);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Fetch chats error:', err);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
fetchChats();
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleRefresh = async (event: CustomEvent) => {
|
|
||||||
await fetchChats();
|
|
||||||
event.detail.complete();
|
|
||||||
};
|
|
||||||
|
|
||||||
const displayChats = previewMode ? previewChats : chats;
|
|
||||||
const filteredChats = displayChats.filter(
|
|
||||||
(c) =>
|
|
||||||
c.otherUser.full_name.toLowerCase().includes(query.toLowerCase()) ||
|
|
||||||
c.lastMessage.toLowerCase().includes(query.toLowerCase())
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonContent fullscreen style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
<IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
|
|
||||||
<IonRefresherContent />
|
|
||||||
</IonRefresher>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{ padding: 'calc(16px + var(--ion-safe-area-top)) 20px 12px' }}
|
|
||||||
>
|
|
||||||
<h1
|
|
||||||
style={{
|
|
||||||
fontSize: '24px',
|
|
||||||
fontWeight: 800,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
margin: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Chats
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<SearchRow
|
|
||||||
value={query}
|
|
||||||
onChange={(e) => setQuery(e.detail.value!)}
|
|
||||||
placeholder="Search conversations"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{ paddingBottom: 'calc(92px + var(--ion-safe-area-bottom))' }}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<div style={{ textAlign: 'center', padding: '40px' }}>
|
|
||||||
<IonSpinner name="crescent" color="primary" />
|
|
||||||
</div>
|
|
||||||
) : filteredChats.length === 0 ? (
|
|
||||||
<EmptyState
|
|
||||||
icon={chatbubbleEllipsesOutline}
|
|
||||||
title="No chats yet"
|
|
||||||
message="Matches you message will appear here. Start swiping to find someone!"
|
|
||||||
ctaText="Find people"
|
|
||||||
onCtaClick={() => history.push('/icebreaker')}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
filteredChats.map((chat) => (
|
|
||||||
<div
|
|
||||||
key={chat.id}
|
|
||||||
onClick={() => history.push(`/chat/${chat.id}`)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
margin: '0 20px 12px',
|
|
||||||
padding: '16px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
boxShadow: 'var(--shadow-card)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Avatar
|
|
||||||
src={chat.otherUser.image || chat.otherUser.avatar_path}
|
|
||||||
name={chat.otherUser.full_name}
|
|
||||||
size={56}
|
|
||||||
/>
|
|
||||||
<div style={{ flex: 1, minWidth: 0 }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
marginBottom: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h3
|
|
||||||
style={{
|
|
||||||
fontSize: '16px',
|
|
||||||
fontWeight: 800,
|
|
||||||
margin: 0,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{chat.otherUser.full_name}
|
|
||||||
</h3>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '11px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
fontWeight: 600,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{formatTime(chat.timestamp)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
margin: 0,
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{chat.lastMessage}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ChatsPage;
|
|
||||||
@@ -0,0 +1,359 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
IonContent,
|
||||||
|
IonPage,
|
||||||
|
IonHeader,
|
||||||
|
IonToolbar,
|
||||||
|
IonTitle,
|
||||||
|
IonButtons,
|
||||||
|
IonButton,
|
||||||
|
IonIcon,
|
||||||
|
IonInput,
|
||||||
|
IonTextarea,
|
||||||
|
IonSpinner,
|
||||||
|
IonLabel,
|
||||||
|
IonSelect,
|
||||||
|
IonSelectOption,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { chevronBackOutline } from 'ionicons/icons';
|
||||||
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { getTodayISO } from '../utils/dates';
|
||||||
|
import MoneyInput from '../components/MoneyInput';
|
||||||
|
import { parseMoney } from '../utils/money';
|
||||||
|
|
||||||
|
interface Customer {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CreditFormPage: React.FC = () => {
|
||||||
|
const history = useHistory();
|
||||||
|
const location = useLocation<{ customerId?: string }>();
|
||||||
|
const { user } = useAuth();
|
||||||
|
|
||||||
|
const [mode, setMode] = useState<'existing' | 'new'>('existing');
|
||||||
|
const [customers, setCustomers] = useState<Customer[]>([]);
|
||||||
|
const [selectedCustomerId, setSelectedCustomerId] = useState<string>(
|
||||||
|
location.state?.customerId || ''
|
||||||
|
);
|
||||||
|
const [newName, setNewName] = useState('');
|
||||||
|
const [phone, setPhone] = useState('');
|
||||||
|
const [amount, setAmount] = useState('');
|
||||||
|
const [creditDate, setCreditDate] = useState(getTodayISO());
|
||||||
|
const [description, setDescription] = useState('');
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const [loadingCustomers, setLoadingCustomers] = useState(true);
|
||||||
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
|
const [message, setMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchCustomers = async () => {
|
||||||
|
if (!user) return;
|
||||||
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('credit_customers')
|
||||||
|
.select('id, name')
|
||||||
|
.eq('user_id', user.id)
|
||||||
|
.order('name');
|
||||||
|
|
||||||
|
if (error) throw error;
|
||||||
|
setCustomers(data || []);
|
||||||
|
if (!data || data.length === 0) {
|
||||||
|
setMode('new');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching customers:', err);
|
||||||
|
} finally {
|
||||||
|
setLoadingCustomers(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchCustomers();
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
|
const validate = () => {
|
||||||
|
const newErrors: Record<string, string> = {};
|
||||||
|
const parsedAmount = parseMoney(amount);
|
||||||
|
|
||||||
|
if (mode === 'existing' && !selectedCustomerId) {
|
||||||
|
newErrors.customer = 'Please select a customer';
|
||||||
|
}
|
||||||
|
if (mode === 'new' && !newName.trim()) {
|
||||||
|
newErrors.name = 'Customer name is required';
|
||||||
|
}
|
||||||
|
if (parsedAmount <= 0) {
|
||||||
|
newErrors.amount = 'Amount must be greater than 0';
|
||||||
|
}
|
||||||
|
if (!creditDate) {
|
||||||
|
newErrors.date = 'Date is required';
|
||||||
|
}
|
||||||
|
|
||||||
|
setErrors(newErrors);
|
||||||
|
return Object.keys(newErrors).length === 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
if (!validate() || !user) return;
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
setMessage(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
let customerId = selectedCustomerId;
|
||||||
|
|
||||||
|
if (mode === 'new') {
|
||||||
|
const { data: newCustomer, error: customerError } = await supabase
|
||||||
|
.from('credit_customers')
|
||||||
|
.insert([
|
||||||
|
{
|
||||||
|
user_id: user.id,
|
||||||
|
name: newName.trim(),
|
||||||
|
phone: phone.trim() || null,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
.select()
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (customerError) throw customerError;
|
||||||
|
customerId = newCustomer.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error: creditError } = await supabase.from('credits').insert([
|
||||||
|
{
|
||||||
|
user_id: user.id,
|
||||||
|
customer_id: customerId,
|
||||||
|
amount: parseMoney(amount),
|
||||||
|
credit_date: creditDate,
|
||||||
|
description: description.trim() || null,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (creditError) throw creditError;
|
||||||
|
|
||||||
|
history.goBack();
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('Error saving credit:', err);
|
||||||
|
setMessage(err.message || 'Could not save credit');
|
||||||
|
setTimeout(() => setMessage(null), 4000);
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f0f4ff' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton color="dark" onClick={() => history.goBack()}>
|
||||||
|
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
<IonTitle className="bold">Add credit</IonTitle>
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
|
||||||
|
<IonContent className="ion-padding" style={{ '--background': '#f0f4ff' }}>
|
||||||
|
<div className="form-card">
|
||||||
|
<div className="pill-toggle" style={{ marginBottom: '8px' }}>
|
||||||
|
<button
|
||||||
|
className={`pill-toggle-btn ${mode === 'existing' ? 'active' : ''}`}
|
||||||
|
onClick={() => setMode('existing')}
|
||||||
|
disabled={customers.length === 0}
|
||||||
|
>
|
||||||
|
Existing Customer
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`pill-toggle-btn ${mode === 'new' ? 'active' : ''}`}
|
||||||
|
onClick={() => setMode('new')}
|
||||||
|
>
|
||||||
|
New Customer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{mode === 'existing' ? (
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Select Customer
|
||||||
|
</IonLabel>
|
||||||
|
<div className="input-wrapper">
|
||||||
|
<IonSelect
|
||||||
|
interface="action-sheet"
|
||||||
|
placeholder="Choose a customer"
|
||||||
|
value={selectedCustomerId}
|
||||||
|
onIonChange={(e) => setSelectedCustomerId(e.detail.value)}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
>
|
||||||
|
{customers.map((c) => (
|
||||||
|
<IonSelectOption key={c.id} value={c.id}>
|
||||||
|
{c.name}
|
||||||
|
</IonSelectOption>
|
||||||
|
))}
|
||||||
|
</IonSelect>
|
||||||
|
</div>
|
||||||
|
{errors.customer && (
|
||||||
|
<IonLabel
|
||||||
|
color="danger"
|
||||||
|
style={{ fontSize: '12px', marginTop: '4px' }}
|
||||||
|
>
|
||||||
|
{errors.customer}
|
||||||
|
</IonLabel>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Customer Name
|
||||||
|
</IonLabel>
|
||||||
|
<div className="input-wrapper">
|
||||||
|
<IonInput
|
||||||
|
placeholder="e.g. John Doe"
|
||||||
|
value={newName}
|
||||||
|
onIonChange={(e) => setNewName(e.detail.value!)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{errors.name && (
|
||||||
|
<IonLabel
|
||||||
|
color="danger"
|
||||||
|
style={{ fontSize: '12px', marginTop: '4px' }}
|
||||||
|
>
|
||||||
|
{errors.name}
|
||||||
|
</IonLabel>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Phone (optional)
|
||||||
|
</IonLabel>
|
||||||
|
<div className="input-wrapper">
|
||||||
|
<IonInput
|
||||||
|
type="tel"
|
||||||
|
placeholder="e.g. +1 234 567 890"
|
||||||
|
value={phone}
|
||||||
|
onIonChange={(e) => setPhone(e.detail.value!)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<MoneyInput
|
||||||
|
label="Credit amount"
|
||||||
|
value={amount}
|
||||||
|
onValueChange={(val) => {
|
||||||
|
setAmount(val);
|
||||||
|
if (errors.amount) setErrors({ ...errors, amount: '' });
|
||||||
|
}}
|
||||||
|
error={errors.amount}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Credit date
|
||||||
|
</IonLabel>
|
||||||
|
<div className="input-wrapper">
|
||||||
|
<IonInput
|
||||||
|
type="date"
|
||||||
|
value={creditDate}
|
||||||
|
onIonChange={(e) => setCreditDate(e.detail.value!)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{errors.date && (
|
||||||
|
<IonLabel
|
||||||
|
color="danger"
|
||||||
|
style={{ fontSize: '12px', marginTop: '4px' }}
|
||||||
|
>
|
||||||
|
{errors.date}
|
||||||
|
</IonLabel>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Description (optional)
|
||||||
|
</IonLabel>
|
||||||
|
<div
|
||||||
|
className="input-wrapper"
|
||||||
|
style={{ minHeight: '96px', padding: '8px 16px' }}
|
||||||
|
>
|
||||||
|
<IonTextarea
|
||||||
|
placeholder="e.g. 2 bags of rice, sugar"
|
||||||
|
value={description}
|
||||||
|
onIonChange={(e) => setDescription(e.detail.value!)}
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{message && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'var(--color-danger-soft)',
|
||||||
|
color: 'var(--ion-color-danger-shade)',
|
||||||
|
padding: '12px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{message}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<IonButton
|
||||||
|
expand="block"
|
||||||
|
className="bold"
|
||||||
|
style={{
|
||||||
|
height: '52px',
|
||||||
|
'--border-radius': 'var(--radius-pill)',
|
||||||
|
marginTop: '16px',
|
||||||
|
}}
|
||||||
|
disabled={submitting || (loadingCustomers && mode === 'existing')}
|
||||||
|
onClick={handleSave}
|
||||||
|
>
|
||||||
|
{submitting ? <IonSpinner name="crescent" /> : 'Save credit'}
|
||||||
|
</IonButton>
|
||||||
|
</div>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CreditFormPage;
|
||||||
@@ -0,0 +1,361 @@
|
|||||||
|
import React, { useState, useCallback, useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
IonContent,
|
||||||
|
IonPage,
|
||||||
|
IonHeader,
|
||||||
|
IonToolbar,
|
||||||
|
IonTitle,
|
||||||
|
IonButtons,
|
||||||
|
IonButton,
|
||||||
|
IonIcon,
|
||||||
|
IonRefresher,
|
||||||
|
IonRefresherContent,
|
||||||
|
IonAlert,
|
||||||
|
useIonViewWillEnter,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import {
|
||||||
|
chevronBackOutline,
|
||||||
|
trashOutline,
|
||||||
|
receiptOutline,
|
||||||
|
personAddOutline,
|
||||||
|
cashOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import ActivityRow, { ActivityItem } from '../components/ActivityRow';
|
||||||
|
import EmptyState from '../components/EmptyState';
|
||||||
|
import { formatMoney } from '../utils/money';
|
||||||
|
|
||||||
|
const CustomerDetailPage: React.FC = () => {
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const { user, profile } = useAuth();
|
||||||
|
const history = useHistory();
|
||||||
|
const currency = profile?.currency || 'USD';
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [customer, setCustomer] = useState<any>(null);
|
||||||
|
const [activity, setActivity] = useState<ActivityItem[]>([]);
|
||||||
|
const [balance, setBalance] = useState(0);
|
||||||
|
const [showDeleteAlert, setShowDeleteAlert] = useState(false);
|
||||||
|
|
||||||
|
const fetchData = useCallback(async () => {
|
||||||
|
if (!user || !id) return;
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [
|
||||||
|
{ data: customerData },
|
||||||
|
{ data: creditsData },
|
||||||
|
{ data: repaymentsData },
|
||||||
|
] = await Promise.all([
|
||||||
|
supabase.from('credit_customers').select('*').eq('id', id).single(),
|
||||||
|
supabase
|
||||||
|
.from('credits')
|
||||||
|
.select('*')
|
||||||
|
.eq('customer_id', id)
|
||||||
|
.order('credit_date', { ascending: false }),
|
||||||
|
supabase
|
||||||
|
.from('repayments')
|
||||||
|
.select('*')
|
||||||
|
.eq('customer_id', id)
|
||||||
|
.order('repayment_date', { ascending: false }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (customerData) {
|
||||||
|
setCustomer(customerData);
|
||||||
|
|
||||||
|
const totalCredits = (creditsData || []).reduce(
|
||||||
|
(sum, c) => sum + Number(c.amount),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const totalRepayments = (repaymentsData || []).reduce(
|
||||||
|
(sum, r) => sum + Number(r.amount),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
setBalance(Math.max(0, totalCredits - totalRepayments));
|
||||||
|
|
||||||
|
const combinedActivity: ActivityItem[] = [
|
||||||
|
...(creditsData || []).map((c) => ({
|
||||||
|
id: c.id,
|
||||||
|
type: 'credit' as const,
|
||||||
|
amount: Number(c.amount),
|
||||||
|
date: c.credit_date,
|
||||||
|
note: c.description,
|
||||||
|
})),
|
||||||
|
...(repaymentsData || []).map((r) => ({
|
||||||
|
id: r.id,
|
||||||
|
type: 'repayment' as const,
|
||||||
|
amount: Number(r.amount),
|
||||||
|
date: r.repayment_date,
|
||||||
|
note: r.note,
|
||||||
|
})),
|
||||||
|
].sort((a, b) => b.date.localeCompare(a.date));
|
||||||
|
|
||||||
|
setActivity(combinedActivity);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching customer detail:', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [user, id]);
|
||||||
|
|
||||||
|
useIonViewWillEnter(() => {
|
||||||
|
fetchData();
|
||||||
|
}, [fetchData]);
|
||||||
|
|
||||||
|
const handleRefresh = async (e: CustomEvent) => {
|
||||||
|
await fetchData();
|
||||||
|
e.detail.complete();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = async () => {
|
||||||
|
try {
|
||||||
|
const { error } = await supabase
|
||||||
|
.from('credit_customers')
|
||||||
|
.delete()
|
||||||
|
.eq('id', id);
|
||||||
|
if (error) throw error;
|
||||||
|
history.push('/customers');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error deleting customer:', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getInitials = (name: string) => {
|
||||||
|
return name
|
||||||
|
.split(' ')
|
||||||
|
.map((n) => n[0])
|
||||||
|
.join('')
|
||||||
|
.toUpperCase()
|
||||||
|
.slice(0, 2);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!loading && !customer) {
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonContent
|
||||||
|
className="ion-padding"
|
||||||
|
style={{ '--background': '#f0f4ff' }}
|
||||||
|
>
|
||||||
|
<EmptyState
|
||||||
|
icon="alert-circle-outline"
|
||||||
|
title="Customer not found"
|
||||||
|
actionText="Go Back"
|
||||||
|
onAction={() => history.push('/customers')}
|
||||||
|
/>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f0f4ff' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton color="dark" onClick={() => history.push('/customers')}>
|
||||||
|
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
<IonTitle className="bold">Customer</IonTitle>
|
||||||
|
<IonButtons slot="end">
|
||||||
|
<IonButton color="danger" onClick={() => setShowDeleteAlert(true)}>
|
||||||
|
<IonIcon icon={trashOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
|
||||||
|
<IonContent fullscreen style={{ '--background': '#f0f4ff' }}>
|
||||||
|
<IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
|
||||||
|
<IonRefresherContent />
|
||||||
|
</IonRefresher>
|
||||||
|
|
||||||
|
<div className="page-padding" style={{ paddingTop: '16px' }}>
|
||||||
|
<div className="widget-card" style={{ padding: '24px 20px' }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
marginBottom: '20px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="icon-container bold"
|
||||||
|
style={{
|
||||||
|
width: '56px',
|
||||||
|
height: '56px',
|
||||||
|
fontSize: '18px',
|
||||||
|
marginRight: '16px',
|
||||||
|
borderRadius: '16px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{customer ? getInitials(customer.name) : ''}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2 className="bold" style={{ margin: '0', fontSize: '20px' }}>
|
||||||
|
{customer?.name}
|
||||||
|
</h2>
|
||||||
|
{customer?.phone && (
|
||||||
|
<p className="secondary-text" style={{ margin: '2px 0 0 0' }}>
|
||||||
|
{customer.phone}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ marginBottom: '24px' }}>
|
||||||
|
<span className="tertiary-text">OUTSTANDING BALANCE</span>
|
||||||
|
<div
|
||||||
|
className="tabular"
|
||||||
|
style={{
|
||||||
|
fontSize: '34px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color:
|
||||||
|
balance > 0
|
||||||
|
? 'var(--ion-color-danger)'
|
||||||
|
: 'var(--ion-color-success)',
|
||||||
|
marginTop: '4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{formatMoney(balance, currency)}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'inline-block',
|
||||||
|
padding: '4px 12px',
|
||||||
|
borderRadius: '999px',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
marginTop: '8px',
|
||||||
|
background:
|
||||||
|
balance > 0
|
||||||
|
? 'var(--color-danger-soft)'
|
||||||
|
: 'var(--color-success-soft)',
|
||||||
|
color:
|
||||||
|
balance > 0
|
||||||
|
? 'var(--ion-color-danger)'
|
||||||
|
: 'var(--ion-color-success)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{balance > 0 ? 'OWING' : 'CLEARED'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ display: 'flex', gap: '12px' }}>
|
||||||
|
<IonButton
|
||||||
|
fill="clear"
|
||||||
|
className="bold"
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: '14px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
'--border-radius': 'var(--radius-inner)',
|
||||||
|
height: '44px',
|
||||||
|
}}
|
||||||
|
onClick={() => history.push('/credit/new', { customerId: id })}
|
||||||
|
>
|
||||||
|
<IonIcon icon={personAddOutline} slot="start" />
|
||||||
|
Credit
|
||||||
|
</IonButton>
|
||||||
|
<IonButton
|
||||||
|
fill="solid"
|
||||||
|
className="bold"
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: '14px',
|
||||||
|
'--border-radius': 'var(--radius-inner)',
|
||||||
|
height: '44px',
|
||||||
|
}}
|
||||||
|
onClick={() =>
|
||||||
|
history.push('/repayment/new', { customerId: id })
|
||||||
|
}
|
||||||
|
disabled={balance === 0}
|
||||||
|
>
|
||||||
|
<IonIcon icon={cashOutline} slot="start" />
|
||||||
|
Repay
|
||||||
|
</IonButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="section-header">
|
||||||
|
<h2>Activity</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="page-padding" style={{ paddingBottom: '40px' }}>
|
||||||
|
{loading ? (
|
||||||
|
<div className="widget-card" style={{ gap: '16px' }}>
|
||||||
|
{[1, 2, 3].map((i) => (
|
||||||
|
<div
|
||||||
|
key={i}
|
||||||
|
style={{ display: 'flex', gap: '12px', alignItems: 'center' }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '40px',
|
||||||
|
height: '40px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div style={{ flex: 1 }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '60%',
|
||||||
|
height: '12px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '4px',
|
||||||
|
marginBottom: '6px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '40%',
|
||||||
|
height: '10px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '4px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : activity.length > 0 ? (
|
||||||
|
<div className="widget-card" style={{ padding: '8px 16px' }}>
|
||||||
|
{activity.map((item) => (
|
||||||
|
<ActivityRow
|
||||||
|
key={`${item.type}-${item.id}`}
|
||||||
|
item={item}
|
||||||
|
showDate
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<EmptyState
|
||||||
|
icon={receiptOutline}
|
||||||
|
title="No activity yet"
|
||||||
|
description="Record the first credit or repayment for this customer."
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<IonAlert
|
||||||
|
isOpen={showDeleteAlert}
|
||||||
|
onDidDismiss={() => setShowDeleteAlert(false)}
|
||||||
|
header="Delete Customer"
|
||||||
|
message="Are you sure you want to delete this customer? All their credit and repayment history will be lost."
|
||||||
|
buttons={[
|
||||||
|
{ text: 'Cancel', role: 'cancel' },
|
||||||
|
{ text: 'Delete', role: 'destructive', handler: handleDelete },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CustomerDetailPage;
|
||||||
@@ -0,0 +1,268 @@
|
|||||||
|
import React, { useState, useCallback, useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
IonContent,
|
||||||
|
IonPage,
|
||||||
|
IonIcon,
|
||||||
|
IonSegmentButton,
|
||||||
|
IonSearchbar,
|
||||||
|
IonRefresher,
|
||||||
|
IonRefresherContent,
|
||||||
|
useIonViewWillEnter,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { personAddOutline, peopleOutline } from 'ionicons/icons';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import MetricCard from '../components/MetricCard';
|
||||||
|
import CustomerRow from '../components/CustomerRow';
|
||||||
|
import EmptyState from '../components/EmptyState';
|
||||||
|
|
||||||
|
interface CustomerWithBalance {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
phone: string | null;
|
||||||
|
balance: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CustomersPage: React.FC = () => {
|
||||||
|
const { user } = useAuth();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [customers, setCustomers] = useState<CustomerWithBalance[]>([]);
|
||||||
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
|
|
||||||
|
const fetchData = useCallback(async () => {
|
||||||
|
if (!user) return;
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [
|
||||||
|
{ data: customersData },
|
||||||
|
{ data: creditsData },
|
||||||
|
{ data: repaymentsData },
|
||||||
|
] = await Promise.all([
|
||||||
|
supabase
|
||||||
|
.from('credit_customers')
|
||||||
|
.select('*')
|
||||||
|
.eq('user_id', user.id)
|
||||||
|
.order('name'),
|
||||||
|
supabase
|
||||||
|
.from('credits')
|
||||||
|
.select('customer_id, amount')
|
||||||
|
.eq('user_id', user.id),
|
||||||
|
supabase
|
||||||
|
.from('repayments')
|
||||||
|
.select('customer_id, amount')
|
||||||
|
.eq('user_id', user.id),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const customerBalances: CustomerWithBalance[] = (customersData || []).map(
|
||||||
|
(c) => {
|
||||||
|
const totalCredits = (creditsData || [])
|
||||||
|
.filter((cr) => cr.customer_id === c.id)
|
||||||
|
.reduce((sum, cr) => sum + Number(cr.amount), 0);
|
||||||
|
const totalRepayments = (repaymentsData || [])
|
||||||
|
.filter((r) => r.customer_id === c.id)
|
||||||
|
.reduce((sum, r) => sum + Number(r.amount), 0);
|
||||||
|
return {
|
||||||
|
id: c.id,
|
||||||
|
name: c.name,
|
||||||
|
phone: c.phone,
|
||||||
|
balance: Math.max(0, totalCredits - totalRepayments),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Sort: outstanding balances first, then by name
|
||||||
|
setCustomers(
|
||||||
|
customerBalances.sort((a, b) => {
|
||||||
|
if (a.balance > 0 && b.balance === 0) return -1;
|
||||||
|
if (a.balance === 0 && b.balance > 0) return 1;
|
||||||
|
return a.name.localeCompare(b.name);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching customers:', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
|
useIonViewWillEnter(() => {
|
||||||
|
fetchData();
|
||||||
|
}, [fetchData]);
|
||||||
|
|
||||||
|
const handleRefresh = async (e: CustomEvent) => {
|
||||||
|
await fetchData();
|
||||||
|
e.detail.complete();
|
||||||
|
};
|
||||||
|
|
||||||
|
const filteredCustomers = useMemo(() => {
|
||||||
|
const query = searchQuery.toLowerCase().trim();
|
||||||
|
if (!query) return customers;
|
||||||
|
return customers.filter(
|
||||||
|
(c) =>
|
||||||
|
c.name.toLowerCase().includes(query) ||
|
||||||
|
(c.phone && c.phone.toLowerCase().includes(query)),
|
||||||
|
);
|
||||||
|
}, [customers, searchQuery]);
|
||||||
|
|
||||||
|
const totalOutstanding = useMemo(() => {
|
||||||
|
return customers.reduce((sum, c) => sum + c.balance, 0);
|
||||||
|
}, [customers]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonContent
|
||||||
|
fullscreen
|
||||||
|
style={{
|
||||||
|
'--background':
|
||||||
|
'linear-gradient(160deg, rgba(199,210,254,0.35) 0%, #f0f4ff 58%, #f8fafc 100%)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
|
||||||
|
<IonRefresherContent />
|
||||||
|
</IonRefresher>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
padding: 'calc(16px + var(--ion-safe-area-top)) 20px 16px',
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<h1 className="bold" style={{ margin: '0', fontSize: '20px' }}>
|
||||||
|
Credit customers
|
||||||
|
</h1>
|
||||||
|
<p className="secondary-text" style={{ margin: '0' }}>
|
||||||
|
Track who owes your shop
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="icon-container"
|
||||||
|
style={{
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: '#ffffff',
|
||||||
|
color: 'var(--ion-color-primary)',
|
||||||
|
}}
|
||||||
|
onClick={() => history.push('/credit/new')}
|
||||||
|
>
|
||||||
|
<IonIcon icon={personAddOutline} style={{ fontSize: '22px' }} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="page-padding">
|
||||||
|
<IonSearchbar
|
||||||
|
value={searchQuery}
|
||||||
|
onIonInput={(e) => setSearchQuery(e.detail.value!)}
|
||||||
|
placeholder="Search customers"
|
||||||
|
className="custom-searchbar"
|
||||||
|
style={{
|
||||||
|
'--background': 'var(--color-surface-secondary)',
|
||||||
|
'--border-radius': '24px',
|
||||||
|
'--box-shadow': 'none',
|
||||||
|
padding: '0',
|
||||||
|
height: '44px',
|
||||||
|
marginBottom: '16px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<MetricCard
|
||||||
|
label="Total Outstanding"
|
||||||
|
value={totalOutstanding}
|
||||||
|
fullWidth
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="section-header">
|
||||||
|
<h2>
|
||||||
|
Customers{' '}
|
||||||
|
{!loading && (
|
||||||
|
<span className="tertiary-text" style={{ marginLeft: '4px' }}>
|
||||||
|
({customers.length})
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="page-padding" style={{ paddingBottom: '120px' }}>
|
||||||
|
{loading ? (
|
||||||
|
<div className="widget-card" style={{ gap: '16px' }}>
|
||||||
|
{[1, 2, 3].map((i) => (
|
||||||
|
<div
|
||||||
|
key={i}
|
||||||
|
style={{ display: 'flex', gap: '12px', alignItems: 'center' }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '44px',
|
||||||
|
height: '44px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div style={{ flex: 1 }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '50%',
|
||||||
|
height: '14px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '4px',
|
||||||
|
marginBottom: '6px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '30%',
|
||||||
|
height: '10px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '4px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : customers.length > 0 ? (
|
||||||
|
<>
|
||||||
|
{filteredCustomers.length > 0 ? (
|
||||||
|
<div className="widget-card" style={{ padding: '8px 16px' }}>
|
||||||
|
{filteredCustomers.map((c) => (
|
||||||
|
<CustomerRow
|
||||||
|
key={c.id}
|
||||||
|
id={c.id}
|
||||||
|
name={c.name}
|
||||||
|
phone={c.phone || undefined}
|
||||||
|
balance={c.balance}
|
||||||
|
onClick={() => history.push(`/customers/${c.id}`)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div style={{ textAlign: 'center', padding: '40px 20px' }}>
|
||||||
|
<p className="secondary-text">
|
||||||
|
No customers matching "{searchQuery}"
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<EmptyState
|
||||||
|
icon={peopleOutline}
|
||||||
|
title="No credit customers yet"
|
||||||
|
description="Add a credit sale to start tracking balances."
|
||||||
|
actionText="Add Credit"
|
||||||
|
onAction={() => history.push('/credit/new')}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CustomersPage;
|
||||||
@@ -1,378 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonTitle,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonItem,
|
|
||||||
IonInput,
|
|
||||||
IonTextarea,
|
|
||||||
IonSelect,
|
|
||||||
IonSelectOption,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
chevronBackOutline,
|
|
||||||
cameraOutline,
|
|
||||||
trashOutline,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import { getStorageUrl } from '../utils/storage';
|
|
||||||
|
|
||||||
const EditProfilePage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user, profile, refreshProfile } = useAuth();
|
|
||||||
const [fullName, setFullName] = useState(profile?.full_name || '');
|
|
||||||
const [bio, setBio] = useState(profile?.bio || '');
|
|
||||||
const [gender, setGender] = useState(profile?.gender || '');
|
|
||||||
const [relationshipGoal, setRelationshipGoal] = useState(
|
|
||||||
profile?.relationship_goal || ''
|
|
||||||
);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [photos, setPhotos] = useState<any[]>([]);
|
|
||||||
const [uploading, setUploading] = useState(false);
|
|
||||||
|
|
||||||
const fetchPhotos = async () => {
|
|
||||||
if (!user) return;
|
|
||||||
const { data } = await supabase
|
|
||||||
.from('profile_photos')
|
|
||||||
.select('*')
|
|
||||||
.eq('user_id', user.id)
|
|
||||||
.order('position');
|
|
||||||
setPhotos(data || []);
|
|
||||||
};
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
if (profile) {
|
|
||||||
setFullName(profile.full_name);
|
|
||||||
setBio(profile.bio || '');
|
|
||||||
setGender(profile.gender || '');
|
|
||||||
setRelationshipGoal(profile.relationship_goal || '');
|
|
||||||
}
|
|
||||||
fetchPhotos();
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSave = async () => {
|
|
||||||
if (!user) return;
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const { error } = await supabase
|
|
||||||
.from('profiles')
|
|
||||||
.update({
|
|
||||||
full_name: fullName,
|
|
||||||
bio,
|
|
||||||
gender,
|
|
||||||
relationship_goal: relationshipGoal,
|
|
||||||
})
|
|
||||||
.eq('id', user.id);
|
|
||||||
|
|
||||||
if (error) throw error;
|
|
||||||
await refreshProfile();
|
|
||||||
history.goBack();
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Save error:', err);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePhotoUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const file = e.target.files?.[0];
|
|
||||||
if (!file || !user) return;
|
|
||||||
|
|
||||||
setUploading(true);
|
|
||||||
try {
|
|
||||||
const fileExt = file.name.split('.').pop();
|
|
||||||
const fileName = `${user.id}-${Date.now()}.${fileExt}`;
|
|
||||||
const filePath = `profile-photos/${fileName}`;
|
|
||||||
|
|
||||||
const { error: uploadError } = await supabase.storage
|
|
||||||
.from('profile-photos')
|
|
||||||
.upload(filePath, file);
|
|
||||||
|
|
||||||
if (uploadError) throw uploadError;
|
|
||||||
|
|
||||||
const { error: dbError } = await supabase.from('profile_photos').insert({
|
|
||||||
user_id: user.id,
|
|
||||||
storage_path: filePath,
|
|
||||||
position: photos.length,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (dbError) throw dbError;
|
|
||||||
fetchPhotos();
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Photo upload error:', err);
|
|
||||||
} finally {
|
|
||||||
setUploading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const deletePhoto = async (id: string, path: string) => {
|
|
||||||
try {
|
|
||||||
await supabase.from('profile_photos').delete().eq('id', id);
|
|
||||||
await supabase.storage.from('profile-photos').remove([path]);
|
|
||||||
fetchPhotos();
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Delete photo error:', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const goals = [
|
|
||||||
{ label: 'Long-term partner', value: 'long_term' },
|
|
||||||
{ label: 'Long-term, but short-term OK', value: 'long_term_short_ok' },
|
|
||||||
{ label: 'Short-term, but long-term OK', value: 'short_term_long_ok' },
|
|
||||||
{ label: 'Short-term fun', value: 'short_term' },
|
|
||||||
{ label: 'New friends', value: 'friends' },
|
|
||||||
{ label: 'Still figuring it out', value: 'figuring_it_out' },
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ '--color': 'var(--color-text-primary)' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle>Edit Profile</IonTitle>
|
|
||||||
<IonButtons slot="end">
|
|
||||||
<IonButton
|
|
||||||
onClick={handleSave}
|
|
||||||
disabled={loading}
|
|
||||||
style={{ fontWeight: 700 }}
|
|
||||||
>
|
|
||||||
{loading ? <IonSpinner name="crescent" /> : 'Save'}
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent
|
|
||||||
className="ion-padding"
|
|
||||||
style={{ '--background': 'var(--color-bg)' }}
|
|
||||||
>
|
|
||||||
{/* Photo Manager */}
|
|
||||||
<div style={{ marginBottom: '24px' }}>
|
|
||||||
<h3
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: 800,
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
textTransform: 'uppercase',
|
|
||||||
marginBottom: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Profile Photos
|
|
||||||
</h3>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'grid',
|
|
||||||
gridTemplateColumns: 'repeat(3, 1fr)',
|
|
||||||
gap: '10px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{photos.map((photo) => (
|
|
||||||
<div
|
|
||||||
key={photo.id}
|
|
||||||
style={{
|
|
||||||
paddingBottom: '125%',
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
position: 'relative',
|
|
||||||
overflow: 'hidden',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src={
|
|
||||||
getStorageUrl('profile-photos', photo.storage_path) || ''
|
|
||||||
}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
objectFit: 'cover',
|
|
||||||
}}
|
|
||||||
alt="Profile"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
onClick={() => deletePhoto(photo.id, photo.storage_path)}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: '8px',
|
|
||||||
right: '8px',
|
|
||||||
background: 'rgba(0,0,0,0.5)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '50%',
|
|
||||||
width: '24px',
|
|
||||||
height: '24px',
|
|
||||||
color: '#fff',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon icon={trashOutline} style={{ fontSize: '14px' }} />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
{photos.length < 6 && (
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
paddingBottom: '125%',
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
position: 'relative',
|
|
||||||
border: '2px dashed var(--ion-color-primary)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{uploading ? (
|
|
||||||
<IonSpinner name="crescent" />
|
|
||||||
) : (
|
|
||||||
<IonIcon
|
|
||||||
icon={cameraOutline}
|
|
||||||
style={{
|
|
||||||
fontSize: '24px',
|
|
||||||
color: 'var(--ion-color-primary)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
accept="image/*"
|
|
||||||
onChange={handlePhotoUpload}
|
|
||||||
hidden
|
|
||||||
disabled={uploading}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Basic Info */}
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
padding: '16px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
boxShadow: 'var(--shadow-card)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonInput
|
|
||||||
label="Full Name"
|
|
||||||
labelPlacement="floating"
|
|
||||||
value={fullName}
|
|
||||||
onIonInput={(e) => setFullName(e.detail.value!)}
|
|
||||||
/>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSelect
|
|
||||||
label="Gender"
|
|
||||||
labelPlacement="floating"
|
|
||||||
value={gender}
|
|
||||||
onIonChange={(e) => setGender(e.detail.value)}
|
|
||||||
interface="action-sheet"
|
|
||||||
>
|
|
||||||
<IonSelectOption value="woman">Woman</IonSelectOption>
|
|
||||||
<IonSelectOption value="man">Man</IonSelectOption>
|
|
||||||
<IonSelectOption value="nonbinary">Non-binary</IonSelectOption>
|
|
||||||
<IonSelectOption value="other">Other</IonSelectOption>
|
|
||||||
<IonSelectOption value="prefer_not_to_say">
|
|
||||||
Prefer not to say
|
|
||||||
</IonSelectOption>
|
|
||||||
</IonSelect>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSelect
|
|
||||||
label="Relationship Goal"
|
|
||||||
labelPlacement="floating"
|
|
||||||
value={relationshipGoal}
|
|
||||||
onIonChange={(e) => setRelationshipGoal(e.detail.value)}
|
|
||||||
interface="action-sheet"
|
|
||||||
>
|
|
||||||
{goals.map((g) => (
|
|
||||||
<IonSelectOption key={g.value} value={g.value}>
|
|
||||||
{g.label}
|
|
||||||
</IonSelectOption>
|
|
||||||
))}
|
|
||||||
</IonSelect>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonTextarea
|
|
||||||
label="Bio"
|
|
||||||
labelPlacement="floating"
|
|
||||||
value={bio}
|
|
||||||
onIonInput={(e) => setBio(e.detail.value!)}
|
|
||||||
placeholder="Tell us about yourself..."
|
|
||||||
rows={4}
|
|
||||||
/>
|
|
||||||
</IonItem>
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditProfilePage;
|
|
||||||
@@ -1,44 +1,50 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
IonPage,
|
|
||||||
IonContent,
|
IonContent,
|
||||||
|
IonPage,
|
||||||
IonInput,
|
IonInput,
|
||||||
IonItem,
|
|
||||||
IonButton,
|
IonButton,
|
||||||
IonSpinner,
|
IonSpinner,
|
||||||
useIonViewWillEnter,
|
IonIcon,
|
||||||
} from '@ionic/react';
|
} from '@ionic/react';
|
||||||
|
import { chevronBackOutline } from 'ionicons/icons';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
|
|
||||||
const ForgotPasswordPage: React.FC = () => {
|
const ForgotPasswordPage: React.FC = () => {
|
||||||
const history = useHistory();
|
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [message, setMessage] = useState<string | null>(null);
|
||||||
|
const [messageType, setMessageType] = useState<'error' | 'success'>('error');
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
const history = useHistory();
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
});
|
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
const showMessage = (msg: string, type: 'error' | 'success' = 'error') => {
|
||||||
setError(msg);
|
setMessage(msg);
|
||||||
setTimeout(() => setError(null), 4000);
|
setMessageType(type);
|
||||||
|
setTimeout(() => setMessage(null), 4000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReset = async (e: React.FormEvent) => {
|
const handleReset = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setLoading(true);
|
if (!email) {
|
||||||
|
showMessage('Please enter your email');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
setMessage(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { error } = await supabase.auth.resetPasswordForEmail(email);
|
const { error } = await supabase.auth.resetPasswordForEmail(email);
|
||||||
|
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
|
|
||||||
history.push('/verify-email', { email, type: 'recovery' });
|
history.push('/verify-email', { email, type: 'recovery' });
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showError(err.message);
|
showMessage(err.message || 'An error occurred');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,104 +53,107 @@ const ForgotPasswordPage: React.FC = () => {
|
|||||||
<IonContent
|
<IonContent
|
||||||
fullscreen
|
fullscreen
|
||||||
style={{
|
style={{
|
||||||
'--background': 'var(--color-bg)',
|
'--background':
|
||||||
|
'linear-gradient(160deg, rgba(199,210,254,0.52) 0%, #f0f4ff 58%, #f8fafc 100%)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ padding: 'calc(var(--ion-safe-area-top) + 40px) 20px' }}>
|
<div className="auth-shell">
|
||||||
<div style={{ marginBottom: '32px' }}>
|
<IonButton
|
||||||
<h1
|
fill="clear"
|
||||||
|
color="dark"
|
||||||
|
onClick={() => history.push('/auth')}
|
||||||
style={{
|
style={{
|
||||||
fontSize: '28px',
|
position: 'absolute',
|
||||||
fontWeight: 800,
|
top: 'calc(var(--ion-safe-area-top, 0px) + 8px)',
|
||||||
color: 'var(--color-text-primary)',
|
left: '8px',
|
||||||
margin: '0 0 8px',
|
'--padding-start': '8px',
|
||||||
|
'--padding-end': '8px',
|
||||||
|
zIndex: 10,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Reset Password
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
width: '44px',
|
||||||
|
height: '44px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon icon={chevronBackOutline} />
|
||||||
|
</div>
|
||||||
|
</IonButton>
|
||||||
|
|
||||||
|
<div style={{ marginTop: '80px' }}>
|
||||||
|
<h1
|
||||||
|
className="bold"
|
||||||
|
style={{ fontSize: '24px', margin: '0 0 8px 0' }}
|
||||||
|
>
|
||||||
|
Reset password
|
||||||
</h1>
|
</h1>
|
||||||
<p
|
<p
|
||||||
style={{
|
className="secondary-text"
|
||||||
fontSize: '15px',
|
style={{ margin: '0', fontSize: '14px' }}
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
margin: 0,
|
|
||||||
lineHeight: 1.5,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Enter your email and we'll send you a code to reset your password.
|
Enter your email and we'll send a 6-digit recovery code.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="auth-card">
|
||||||
<form
|
<form
|
||||||
onSubmit={handleReset}
|
onSubmit={handleReset}
|
||||||
style={{
|
style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}
|
||||||
background: 'var(--color-surface)',
|
|
||||||
padding: '24px',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
|
<div className="input-wrapper">
|
||||||
<IonInput
|
<IonInput
|
||||||
label="Email"
|
label="Email"
|
||||||
labelPlacement="floating"
|
labelPlacement="floating"
|
||||||
type="email"
|
type="email"
|
||||||
|
placeholder="name@example.com"
|
||||||
value={email}
|
value={email}
|
||||||
onIonInput={(e) => setEmail(e.detail.value!)}
|
onIonChange={(e) => setEmail(e.detail.value!)}
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
</IonItem>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{message && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
background: 'rgba(220, 38, 38, 0.08)',
|
background:
|
||||||
color: 'var(--ion-color-danger)',
|
messageType === 'error'
|
||||||
|
? 'var(--color-danger-soft)'
|
||||||
|
: 'var(--color-success-soft)',
|
||||||
|
color:
|
||||||
|
messageType === 'error'
|
||||||
|
? 'var(--ion-color-danger-shade)'
|
||||||
|
: 'var(--ion-color-success-shade)',
|
||||||
padding: '12px',
|
padding: '12px',
|
||||||
borderRadius: 'var(--radius-control)',
|
borderRadius: '12px',
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
|
textAlign: 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{error}
|
{message}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<IonButton
|
<IonButton
|
||||||
type="submit"
|
type="submit"
|
||||||
expand="block"
|
expand="block"
|
||||||
disabled={loading}
|
className="bold"
|
||||||
style={{
|
style={{
|
||||||
|
height: '52px',
|
||||||
'--border-radius': 'var(--radius-pill)',
|
'--border-radius': 'var(--radius-pill)',
|
||||||
height: '48px',
|
|
||||||
marginTop: '8px',
|
marginTop: '8px',
|
||||||
}}
|
}}
|
||||||
|
disabled={submitting}
|
||||||
>
|
>
|
||||||
{loading ? <IonSpinner name="crescent" /> : 'Send Code'}
|
{submitting ? <IonSpinner name="crescent" /> : 'Send code'}
|
||||||
</IonButton>
|
</IonButton>
|
||||||
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{
|
|
||||||
background: 'none',
|
|
||||||
border: 'none',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: 600,
|
|
||||||
marginTop: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Back to Sign In
|
|
||||||
</button>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,558 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonIcon,
|
|
||||||
IonButton,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
IonRefresher,
|
|
||||||
IonRefresherContent,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
locationOutline,
|
|
||||||
notificationsOutline,
|
|
||||||
star,
|
|
||||||
cameraOutline,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import { formatDistance } from '../utils/format';
|
|
||||||
import { getStorageUrl } from '../utils/storage';
|
|
||||||
import SearchRow from '../components/SearchRow';
|
|
||||||
import EmptyState from '../components/EmptyState';
|
|
||||||
import { previewPlaces } from '../utils/previewData';
|
|
||||||
import { isPreviewMode } from '../utils/previewMode';
|
|
||||||
|
|
||||||
const HangoutPage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const previewMode = isPreviewMode();
|
|
||||||
const [places, setPlaces] = useState<any[]>([]);
|
|
||||||
const [reelStories, setReelStories] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [query, setQuery] = useState('');
|
|
||||||
const [sort, setSort] = useState<'most_busy' | 'nearest' | 'top_rated'>(
|
|
||||||
'most_busy'
|
|
||||||
);
|
|
||||||
|
|
||||||
const fetchPlaces = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
if (previewMode) {
|
|
||||||
setPlaces(previewPlaces);
|
|
||||||
setReelStories(previewPlaces);
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// Phase 1: simple local query. Phase 2: use places-nearby Edge Function
|
|
||||||
const { data, error } = await supabase
|
|
||||||
.from('places')
|
|
||||||
.select(
|
|
||||||
`
|
|
||||||
*,
|
|
||||||
reels(id)
|
|
||||||
`
|
|
||||||
)
|
|
||||||
.order('rating', { ascending: false });
|
|
||||||
|
|
||||||
if (error) throw error;
|
|
||||||
setPlaces(data || []);
|
|
||||||
|
|
||||||
// Derive stories (places with reels)
|
|
||||||
const stories =
|
|
||||||
data?.filter((p) => p.reels?.length > 0).slice(0, 10) || [];
|
|
||||||
setReelStories(stories);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Fetch places error:', err);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
fetchPlaces();
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleRefresh = async (event: CustomEvent) => {
|
|
||||||
await fetchPlaces();
|
|
||||||
event.detail.complete();
|
|
||||||
};
|
|
||||||
|
|
||||||
const displayPlaces = previewMode ? previewPlaces : places;
|
|
||||||
const displayStories = previewMode ? previewPlaces : reelStories;
|
|
||||||
const filteredPlaces = displayPlaces.filter(
|
|
||||||
(p) =>
|
|
||||||
p.name.toLowerCase().includes(query.toLowerCase()) ||
|
|
||||||
p.category.toLowerCase().includes(query.toLowerCase())
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonContent fullscreen style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
<IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
|
|
||||||
<IonRefresherContent />
|
|
||||||
</IonRefresher>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: 'calc(14px + var(--ion-safe-area-top)) 20px 8px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '40px',
|
|
||||||
height: '40px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
background: 'rgba(255,255,255,0.06)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={locationOutline}
|
|
||||||
style={{ color: 'var(--ion-color-primary)', fontSize: '18px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '2px' }}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '11px',
|
|
||||||
fontWeight: 600,
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
letterSpacing: '0.04em',
|
|
||||||
textTransform: 'uppercase',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Nearby now
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '17px',
|
|
||||||
fontWeight: 700,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
lineHeight: 1.1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Midrand, ZA
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<IonButton
|
|
||||||
fill="clear"
|
|
||||||
onClick={() => history.push('/notifications')}
|
|
||||||
style={{
|
|
||||||
'--background': 'rgba(255,255,255,0.06)',
|
|
||||||
'--color': 'var(--color-text-primary)',
|
|
||||||
'--border-radius': '12px',
|
|
||||||
width: '44px',
|
|
||||||
height: '44px',
|
|
||||||
margin: 0,
|
|
||||||
'--padding-start': 0,
|
|
||||||
'--padding-end': 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={notificationsOutline}
|
|
||||||
slot="icon-only"
|
|
||||||
style={{ fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<SearchRow
|
|
||||||
value={query}
|
|
||||||
onChange={(e) => setQuery(e.detail.value!)}
|
|
||||||
placeholder="Search place of interest"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
gap: '10px',
|
|
||||||
padding: '2px 20px 26px',
|
|
||||||
overflowX: 'auto',
|
|
||||||
WebkitOverflowScrolling: 'touch',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{(['most_busy', 'nearest', 'top_rated'] as const).map((s) => {
|
|
||||||
const active = sort === s;
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={s}
|
|
||||||
onClick={() => setSort(s)}
|
|
||||||
style={{
|
|
||||||
padding: '10px 16px',
|
|
||||||
borderRadius: 'var(--radius-pill)',
|
|
||||||
border: 'none',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: active ? 700 : 600,
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
background: active
|
|
||||||
? 'linear-gradient(180deg, #f24f88 0%, var(--ion-color-primary) 100%)'
|
|
||||||
: 'rgba(255,255,255,0.05)',
|
|
||||||
color: active ? '#ffffff' : 'rgba(255,255,255,0.82)',
|
|
||||||
boxShadow: active
|
|
||||||
? '0 10px 24px rgba(254, 60, 114, 0.26)'
|
|
||||||
: 'none',
|
|
||||||
transition: '0.2s ease',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{s.replace('_', ' ').replace(/\b\w/g, (l) => l.toUpperCase())}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Reels Stories Section */}
|
|
||||||
<div style={{ marginBottom: '26px' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
padding: '0 20px 14px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h2
|
|
||||||
style={{
|
|
||||||
fontSize: '18px',
|
|
||||||
fontWeight: 800,
|
|
||||||
margin: 0,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
letterSpacing: '-0.02em',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Reels
|
|
||||||
</h2>
|
|
||||||
<button
|
|
||||||
onClick={() => history.push('/camera')}
|
|
||||||
style={{
|
|
||||||
width: '44px',
|
|
||||||
height: '44px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
border: 'none',
|
|
||||||
background:
|
|
||||||
'linear-gradient(180deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.06) 100%)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
cursor: 'pointer',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={cameraOutline}
|
|
||||||
style={{ fontSize: '20px', color: 'var(--color-text-primary)' }}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
gap: '14px',
|
|
||||||
padding: '0 20px',
|
|
||||||
overflowX: 'auto',
|
|
||||||
WebkitOverflowScrolling: 'touch',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ flexShrink: 0, width: '76px', textAlign: 'center' }}>
|
|
||||||
<div
|
|
||||||
onClick={() => history.push('/camera')}
|
|
||||||
style={{
|
|
||||||
width: '68px',
|
|
||||||
height: '68px',
|
|
||||||
borderRadius: '50%',
|
|
||||||
padding: '2px',
|
|
||||||
background:
|
|
||||||
'linear-gradient(180deg, #f24f88 0%, #a60b4a 100%)',
|
|
||||||
marginBottom: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
borderRadius: '50%',
|
|
||||||
background: '#08080a',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={cameraOutline}
|
|
||||||
style={{
|
|
||||||
fontSize: '22px',
|
|
||||||
color: 'var(--ion-color-primary)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '11px',
|
|
||||||
fontWeight: 600,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
opacity: 0.95,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
My reels
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{displayStories.map((story) => (
|
|
||||||
<div
|
|
||||||
key={story.id}
|
|
||||||
onClick={() => history.push(`/reels/${story.id}`)}
|
|
||||||
style={{ flexShrink: 0, width: '76px', textAlign: 'center' }}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '68px',
|
|
||||||
height: '68px',
|
|
||||||
borderRadius: '50%',
|
|
||||||
padding: '2px',
|
|
||||||
background:
|
|
||||||
'linear-gradient(180deg, #f24f88 0%, #a60b4a 100%)',
|
|
||||||
marginBottom: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
borderRadius: '50%',
|
|
||||||
padding: '3px',
|
|
||||||
background: '#08080a',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src={
|
|
||||||
story.image ||
|
|
||||||
getStorageUrl('place-media', story.image_path) ||
|
|
||||||
''
|
|
||||||
}
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
borderRadius: '50%',
|
|
||||||
objectFit: 'cover',
|
|
||||||
}}
|
|
||||||
alt={story.name}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '11px',
|
|
||||||
fontWeight: 600,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
display: 'block',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
opacity: 0.95,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{story.name}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Places List */}
|
|
||||||
<div
|
|
||||||
style={{ paddingBottom: 'calc(92px + var(--ion-safe-area-bottom))' }}
|
|
||||||
>
|
|
||||||
<h2
|
|
||||||
style={{
|
|
||||||
fontSize: '18px',
|
|
||||||
fontWeight: 800,
|
|
||||||
margin: '0 20px 16px',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Places of interest 📍
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
{loading ? (
|
|
||||||
<div style={{ textAlign: 'center', padding: '40px' }}>
|
|
||||||
<IonSpinner name="crescent" color="primary" />
|
|
||||||
</div>
|
|
||||||
) : filteredPlaces.length === 0 ? (
|
|
||||||
<EmptyState
|
|
||||||
icon={locationOutline}
|
|
||||||
title="No places found"
|
|
||||||
message="We couldn't find any places matching your search nearby."
|
|
||||||
ctaText="Refresh"
|
|
||||||
onCtaClick={fetchPlaces}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
filteredPlaces.map((place, index) => (
|
|
||||||
<div
|
|
||||||
key={place.id}
|
|
||||||
onClick={() => history.push(`/reels/${place.id}`)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
margin: '0 20px 12px',
|
|
||||||
padding: '12px',
|
|
||||||
display: 'flex',
|
|
||||||
gap: '12px',
|
|
||||||
boxShadow: 'var(--shadow-card)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
flexShrink: 0,
|
|
||||||
width: '112px',
|
|
||||||
height: '88px',
|
|
||||||
borderRadius: 'var(--radius-control)',
|
|
||||||
overflow: 'hidden',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src={
|
|
||||||
place.image ||
|
|
||||||
getStorageUrl('place-media', place.image_path) ||
|
|
||||||
''
|
|
||||||
}
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
objectFit: 'cover',
|
|
||||||
}}
|
|
||||||
alt={place.name}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div style={{ flex: 1, position: 'relative' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'flex-start',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h3
|
|
||||||
style={{
|
|
||||||
fontSize: '16px',
|
|
||||||
fontWeight: 800,
|
|
||||||
margin: '0 0 4px',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{index + 1}. {place.name}
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
margin: '0 0 4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{place.category}
|
|
||||||
</p>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
margin: '0 0 8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{place.distance || '0.9 mi'}
|
|
||||||
</p>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ display: 'flex', gap: '1px' }}>
|
|
||||||
{[1, 2, 3, 4, 5].map((s) => (
|
|
||||||
<IonIcon
|
|
||||||
key={s}
|
|
||||||
icon={star}
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
color:
|
|
||||||
s <= place.rating
|
|
||||||
? 'var(--ion-color-primary)'
|
|
||||||
: 'var(--color-border)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '11px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
fontWeight: 600,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{place.review_count > 1000
|
|
||||||
? `${(place.review_count / 1000).toFixed(1)}k`
|
|
||||||
: place.review_count}{' '}
|
|
||||||
Reviews
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{place.busyness === 'busy' && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
right: 0,
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '10px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
fontWeight: 600,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Busy
|
|
||||||
</span>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--ion-color-primary)',
|
|
||||||
color: '#ffffff',
|
|
||||||
fontSize: '9px',
|
|
||||||
fontWeight: 800,
|
|
||||||
padding: '2px 6px',
|
|
||||||
borderRadius: 'var(--radius-pill)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
LIVE
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HangoutPage;
|
|
||||||
@@ -0,0 +1,339 @@
|
|||||||
|
import React, { useState, useCallback, useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
IonContent,
|
||||||
|
IonPage,
|
||||||
|
IonIcon,
|
||||||
|
IonRefresher,
|
||||||
|
IonRefresherContent,
|
||||||
|
IonSegment,
|
||||||
|
IonSegmentButton,
|
||||||
|
IonLabel,
|
||||||
|
IonActionSheet,
|
||||||
|
useIonViewWillEnter,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import {
|
||||||
|
addOutline,
|
||||||
|
receiptOutline,
|
||||||
|
personAddOutline,
|
||||||
|
cashOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import ActivityRow, { ActivityItem } from '../components/ActivityRow';
|
||||||
|
import EmptyState from '../components/EmptyState';
|
||||||
|
import MetricCard from '../components/MetricCard';
|
||||||
|
import { groupItemsByDate, formatRelativeDate } from '../utils/dates';
|
||||||
|
|
||||||
|
const HistoryPage: React.FC = () => {
|
||||||
|
const { user } = useAuth();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [filter, setFilter] = useState<
|
||||||
|
'all' | 'sales' | 'credit' | 'repayments'
|
||||||
|
>('all');
|
||||||
|
const [items, setItems] = useState<ActivityItem[]>([]);
|
||||||
|
const [showQuickAdd, setShowQuickAdd] = useState(false);
|
||||||
|
|
||||||
|
const fetchData = useCallback(async () => {
|
||||||
|
if (!user) return;
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [
|
||||||
|
{ data: salesData },
|
||||||
|
{ data: creditsData },
|
||||||
|
{ data: repaymentsData },
|
||||||
|
] = await Promise.all([
|
||||||
|
supabase
|
||||||
|
.from('sales')
|
||||||
|
.select('*')
|
||||||
|
.eq('user_id', user.id)
|
||||||
|
.order('sale_date', { ascending: false }),
|
||||||
|
supabase
|
||||||
|
.from('credits')
|
||||||
|
.select('*, credit_customers(name)')
|
||||||
|
.eq('user_id', user.id)
|
||||||
|
.order('credit_date', { ascending: false }),
|
||||||
|
supabase
|
||||||
|
.from('repayments')
|
||||||
|
.select('*, credit_customers(name)')
|
||||||
|
.eq('user_id', user.id)
|
||||||
|
.order('repayment_date', { ascending: false }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const combined: ActivityItem[] = [
|
||||||
|
...(salesData || []).map((s) => ({
|
||||||
|
id: s.id,
|
||||||
|
type: 'sale' as const,
|
||||||
|
amount: Number(s.amount),
|
||||||
|
date: s.sale_date,
|
||||||
|
note: s.note,
|
||||||
|
})),
|
||||||
|
...(creditsData || []).map((c) => ({
|
||||||
|
id: c.id,
|
||||||
|
type: 'credit' as const,
|
||||||
|
amount: Number(c.amount),
|
||||||
|
date: c.credit_date,
|
||||||
|
customerName: (c.credit_customers as any)?.name,
|
||||||
|
note: c.description,
|
||||||
|
customerId: c.customer_id,
|
||||||
|
})),
|
||||||
|
...(repaymentsData || []).map((r) => ({
|
||||||
|
id: r.id,
|
||||||
|
type: 'repayment' as const,
|
||||||
|
amount: Number(r.amount),
|
||||||
|
date: r.repayment_date,
|
||||||
|
customerName: (r.credit_customers as any)?.name,
|
||||||
|
note: r.note,
|
||||||
|
customerId: r.customer_id,
|
||||||
|
})),
|
||||||
|
].sort((a, b) => b.date.localeCompare(a.date));
|
||||||
|
|
||||||
|
setItems(combined);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching history:', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
|
useIonViewWillEnter(() => {
|
||||||
|
fetchData();
|
||||||
|
}, [fetchData]);
|
||||||
|
|
||||||
|
const handleRefresh = async (e: CustomEvent) => {
|
||||||
|
await fetchData();
|
||||||
|
e.detail.complete();
|
||||||
|
};
|
||||||
|
|
||||||
|
const filteredItems = useMemo(() => {
|
||||||
|
if (filter === 'all') return items;
|
||||||
|
if (filter === 'sales') return items.filter((i) => i.type === 'sale');
|
||||||
|
if (filter === 'credit') return items.filter((i) => i.type === 'credit');
|
||||||
|
if (filter === 'repayments')
|
||||||
|
return items.filter((i) => i.type === 'repayment');
|
||||||
|
return items;
|
||||||
|
}, [items, filter]);
|
||||||
|
|
||||||
|
const groupedItems = useMemo(() => {
|
||||||
|
return groupItemsByDate(filteredItems);
|
||||||
|
}, [filteredItems]);
|
||||||
|
|
||||||
|
const totals = useMemo(() => {
|
||||||
|
const salesTotal = items
|
||||||
|
.filter((i) => i.type === 'sale')
|
||||||
|
.reduce((sum, i) => sum + i.amount, 0);
|
||||||
|
const repaymentsTotal = items
|
||||||
|
.filter((i) => i.type === 'repayment')
|
||||||
|
.reduce((sum, i) => sum + i.amount, 0);
|
||||||
|
return { salesTotal, repaymentsTotal };
|
||||||
|
}, [items]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonContent
|
||||||
|
fullscreen
|
||||||
|
style={{
|
||||||
|
'--background':
|
||||||
|
'linear-gradient(160deg, rgba(199,210,254,0.35) 0%, #f0f4ff 58%, #f8fafc 100%)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
|
||||||
|
<IonRefresherContent />
|
||||||
|
</IonRefresher>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
padding: 'calc(16px + var(--ion-safe-area-top)) 20px 16px',
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<h1 className="bold" style={{ margin: '0', fontSize: '20px' }}>
|
||||||
|
History
|
||||||
|
</h1>
|
||||||
|
<p className="secondary-text" style={{ margin: '0' }}>
|
||||||
|
All your transactions
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="icon-container"
|
||||||
|
style={{
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: '#ffffff',
|
||||||
|
color: 'var(--ion-color-primary)',
|
||||||
|
}}
|
||||||
|
onClick={() => setShowQuickAdd(true)}
|
||||||
|
>
|
||||||
|
<IonIcon icon={addOutline} style={{ fontSize: '22px' }} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="page-padding">
|
||||||
|
<IonSegment
|
||||||
|
value={filter}
|
||||||
|
onIonChange={(e) => setFilter(e.detail.value as any)}
|
||||||
|
style={{
|
||||||
|
'--background': 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '4px',
|
||||||
|
marginBottom: '16px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSegmentButton
|
||||||
|
value="all"
|
||||||
|
style={{
|
||||||
|
'--indicator-color': 'var(--ion-color-primary)',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonLabel className="semibold">All</IonLabel>
|
||||||
|
</IonSegmentButton>
|
||||||
|
<IonSegmentButton value="sales">
|
||||||
|
<IonLabel className="semibold">Sales</IonLabel>
|
||||||
|
</IonSegmentButton>
|
||||||
|
<IonSegmentButton value="credit">
|
||||||
|
<IonLabel className="semibold">Credit</IonLabel>
|
||||||
|
</IonSegmentButton>
|
||||||
|
<IonSegmentButton value="repayments">
|
||||||
|
<IonLabel className="semibold">Paid</IonLabel>
|
||||||
|
</IonSegmentButton>
|
||||||
|
</IonSegment>
|
||||||
|
|
||||||
|
<div className="metric-pair-row">
|
||||||
|
<MetricCard
|
||||||
|
label="Total Sales"
|
||||||
|
value={totals.salesTotal}
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
<MetricCard
|
||||||
|
label="Total Repaid"
|
||||||
|
value={totals.repaymentsTotal}
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className="page-padding"
|
||||||
|
style={{ paddingBottom: '120px', marginTop: '8px' }}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<div className="widget-card" style={{ gap: '16px' }}>
|
||||||
|
{[1, 2, 3].map((i) => (
|
||||||
|
<div
|
||||||
|
key={i}
|
||||||
|
style={{ display: 'flex', gap: '12px', alignItems: 'center' }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '40px',
|
||||||
|
height: '40px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div style={{ flex: 1 }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '60%',
|
||||||
|
height: '12px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '4px',
|
||||||
|
marginBottom: '6px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '40%',
|
||||||
|
height: '10px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '4px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : groupedItems.length > 0 ? (
|
||||||
|
groupedItems.map((group) => (
|
||||||
|
<div key={group.date} style={{ marginBottom: '20px' }}>
|
||||||
|
<div className="tertiary-text" style={{ marginBottom: '12px' }}>
|
||||||
|
{formatRelativeDate(group.date)}
|
||||||
|
</div>
|
||||||
|
<div className="widget-card" style={{ padding: '8px 16px' }}>
|
||||||
|
{group.items.map((item) => (
|
||||||
|
<ActivityRow
|
||||||
|
key={`${item.type}-${item.id}`}
|
||||||
|
item={item}
|
||||||
|
onClick={
|
||||||
|
item.customerId
|
||||||
|
? () => history.push(`/customers/${item.customerId}`)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<EmptyState
|
||||||
|
icon={receiptOutline}
|
||||||
|
title={
|
||||||
|
filter === 'all' ? 'No activity yet' : `No ${filter} found`
|
||||||
|
}
|
||||||
|
description={
|
||||||
|
filter === 'all'
|
||||||
|
? 'Start recording sales and credits to see your history.'
|
||||||
|
: `You haven't recorded any ${filter} yet.`
|
||||||
|
}
|
||||||
|
actionText={
|
||||||
|
filter === 'all' || filter === 'sales'
|
||||||
|
? 'Add Sale'
|
||||||
|
: filter === 'credit'
|
||||||
|
? 'Add Credit'
|
||||||
|
: 'Record Repayment'
|
||||||
|
}
|
||||||
|
onAction={() => {
|
||||||
|
if (filter === 'sales' || filter === 'all')
|
||||||
|
history.push('/sale/new');
|
||||||
|
else if (filter === 'credit') history.push('/credit/new');
|
||||||
|
else history.push('/repayment/new');
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<IonActionSheet
|
||||||
|
isOpen={showQuickAdd}
|
||||||
|
onDidDismiss={() => setShowQuickAdd(false)}
|
||||||
|
header="Quick Actions"
|
||||||
|
buttons={[
|
||||||
|
{
|
||||||
|
text: 'Add Sale',
|
||||||
|
icon: receiptOutline,
|
||||||
|
handler: () => history.push('/sale/new'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Add Credit',
|
||||||
|
icon: personAddOutline,
|
||||||
|
handler: () => history.push('/credit/new'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Record Repayment',
|
||||||
|
icon: cashOutline,
|
||||||
|
handler: () => history.push('/repayment/new'),
|
||||||
|
},
|
||||||
|
{ text: 'Cancel', role: 'cancel' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default HistoryPage;
|
||||||
@@ -1,30 +1,360 @@
|
|||||||
import React from "react";
|
import React, { useState, useCallback } from 'react';
|
||||||
import {
|
import {
|
||||||
IonContent,
|
IonContent,
|
||||||
IonHeader,
|
|
||||||
IonPage,
|
IonPage,
|
||||||
IonTitle,
|
IonIcon,
|
||||||
IonToolbar,
|
IonButton,
|
||||||
} from "@ionic/react";
|
IonActionSheet,
|
||||||
|
IonRefresher,
|
||||||
|
IonRefresherContent,
|
||||||
|
useIonViewWillEnter,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import {
|
||||||
|
addCircleOutline,
|
||||||
|
personAddOutline,
|
||||||
|
cashOutline,
|
||||||
|
receiptOutline,
|
||||||
|
walletOutline,
|
||||||
|
checkmarkCircleOutline,
|
||||||
|
personCircleOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import MetricCard from '../components/MetricCard';
|
||||||
|
import ActivityRow, { ActivityItem } from '../components/ActivityRow';
|
||||||
|
import EmptyState from '../components/EmptyState';
|
||||||
|
import { getTodayISO } from '../utils/dates';
|
||||||
|
|
||||||
const Home: React.FC = () => (
|
const Home: React.FC = () => {
|
||||||
|
const { user, profile } = useAuth();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [showQuickActions, setShowQuickActions] = useState(false);
|
||||||
|
const [summary, setSummary] = useState({
|
||||||
|
todaySales: 0,
|
||||||
|
outstandingCredit: 0,
|
||||||
|
monthRepayments: 0,
|
||||||
|
recentActivity: [] as ActivityItem[],
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchData = useCallback(async () => {
|
||||||
|
if (!user) return;
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const today = getTodayISO();
|
||||||
|
const firstOfMonth = new Date();
|
||||||
|
firstOfMonth.setDate(1);
|
||||||
|
const firstOfMonthISO = firstOfMonth.toISOString().split('T')[0];
|
||||||
|
|
||||||
|
// Parallel queries for efficiency
|
||||||
|
const [
|
||||||
|
{ data: salesToday },
|
||||||
|
{ data: creditsData },
|
||||||
|
{ data: repaymentsData },
|
||||||
|
{ data: recentSales },
|
||||||
|
{ data: recentCredits },
|
||||||
|
{ data: recentRepayments },
|
||||||
|
] = await Promise.all([
|
||||||
|
supabase.from('sales').select('amount').eq('sale_date', today),
|
||||||
|
supabase.from('credits').select('amount'),
|
||||||
|
supabase.from('repayments').select('amount, repayment_date'),
|
||||||
|
supabase
|
||||||
|
.from('sales')
|
||||||
|
.select('*')
|
||||||
|
.order('created_at', { ascending: false })
|
||||||
|
.limit(5),
|
||||||
|
supabase
|
||||||
|
.from('credits')
|
||||||
|
.select('*, credit_customers(name)')
|
||||||
|
.order('created_at', { ascending: false })
|
||||||
|
.limit(5),
|
||||||
|
supabase
|
||||||
|
.from('repayments')
|
||||||
|
.select('*, credit_customers(name)')
|
||||||
|
.order('created_at', { ascending: false })
|
||||||
|
.limit(5),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Calculate totals
|
||||||
|
const todaySalesTotal = (salesToday || []).reduce(
|
||||||
|
(sum, s) => sum + Number(s.amount),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const totalCredits = (creditsData || []).reduce(
|
||||||
|
(sum, c) => sum + Number(c.amount),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const totalRepayments = (repaymentsData || []).reduce(
|
||||||
|
(sum, r) => sum + Number(r.amount),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const monthRepaymentsTotal = (repaymentsData || [])
|
||||||
|
.filter((r) => r.repayment_date >= firstOfMonthISO)
|
||||||
|
.reduce((sum, r) => sum + Number(r.amount), 0);
|
||||||
|
|
||||||
|
// Combine activity
|
||||||
|
const activity: ActivityItem[] = [
|
||||||
|
...(recentSales || []).map((s) => ({
|
||||||
|
id: s.id,
|
||||||
|
type: 'sale' as const,
|
||||||
|
amount: Number(s.amount),
|
||||||
|
date: s.sale_date,
|
||||||
|
note: s.note,
|
||||||
|
})),
|
||||||
|
...(recentCredits || []).map((c) => ({
|
||||||
|
id: c.id,
|
||||||
|
type: 'credit' as const,
|
||||||
|
amount: Number(c.amount),
|
||||||
|
date: c.credit_date,
|
||||||
|
customerName: (c.credit_customers as any)?.name,
|
||||||
|
note: c.description,
|
||||||
|
customerId: c.customer_id,
|
||||||
|
})),
|
||||||
|
...(recentRepayments || []).map((r) => ({
|
||||||
|
id: r.id,
|
||||||
|
type: 'repayment' as const,
|
||||||
|
amount: Number(r.amount),
|
||||||
|
date: r.repayment_date,
|
||||||
|
customerName: (r.credit_customers as any)?.name,
|
||||||
|
note: r.note,
|
||||||
|
customerId: r.customer_id,
|
||||||
|
})),
|
||||||
|
].sort((a, b) => b.id.localeCompare(a.id)); // Simplified sort for MVP, ideally use created_at
|
||||||
|
|
||||||
|
setSummary({
|
||||||
|
todaySales: todaySalesTotal,
|
||||||
|
outstandingCredit: Math.max(0, totalCredits - totalRepayments),
|
||||||
|
monthRepayments: monthRepaymentsTotal,
|
||||||
|
recentActivity: activity.slice(0, 10),
|
||||||
|
});
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('Error fetching dashboard data:', err);
|
||||||
|
setError('Could not load dashboard data');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
|
useIonViewWillEnter(() => {
|
||||||
|
fetchData();
|
||||||
|
}, [fetchData]);
|
||||||
|
|
||||||
|
const handleRefresh = async (e: CustomEvent) => {
|
||||||
|
await fetchData();
|
||||||
|
e.detail.complete();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getGreeting = () => {
|
||||||
|
const hour = new Date().getHours();
|
||||||
|
if (hour < 12) return 'Good morning';
|
||||||
|
if (hour < 17) return 'Good afternoon';
|
||||||
|
return 'Good evening';
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
<IonPage>
|
<IonPage>
|
||||||
<IonHeader translucent className="home-header">
|
<IonContent
|
||||||
<IonToolbar className="home-toolbar">
|
fullscreen
|
||||||
<IonTitle>Home</IonTitle>
|
style={{
|
||||||
</IonToolbar>
|
'--background':
|
||||||
</IonHeader>
|
'linear-gradient(160deg, rgba(199,210,254,0.45) 0%, #f0f4ff 58%, #f8fafc 100%)',
|
||||||
<IonContent fullscreen className="home-content">
|
}}
|
||||||
<div className="home-shell minimal-home-shell">
|
>
|
||||||
<section className="minimal-welcome-card subtle-welcome-card">
|
<IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
|
||||||
<h1>Welcome to your new app</h1>
|
<IonRefresherContent />
|
||||||
<p className="minimal-subtitle">
|
</IonRefresher>
|
||||||
Chat with the assistant to start adding features and pages
|
|
||||||
</p>
|
<div
|
||||||
</section>
|
style={{
|
||||||
|
padding: 'calc(16px + var(--ion-safe-area-top)) 20px 16px',
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<div className="secondary-text">{getGreeting()}</div>
|
||||||
|
<h1 className="bold" style={{ margin: '0', fontSize: '20px' }}>
|
||||||
|
{profile?.shop_name || profile?.full_name || 'My Shop'}
|
||||||
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
className="icon-container"
|
||||||
|
style={{
|
||||||
|
borderRadius: '999px',
|
||||||
|
background: 'var(--color-accent-soft)',
|
||||||
|
}}
|
||||||
|
onClick={() => setShowQuickActions(true)}
|
||||||
|
>
|
||||||
|
<IonIcon icon={personCircleOutline} style={{ fontSize: '24px' }} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="page-padding">
|
||||||
|
<MetricCard
|
||||||
|
label="Today's Sales"
|
||||||
|
value={summary.todaySales}
|
||||||
|
fullWidth
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="metric-pair-row" style={{ marginTop: '12px' }}>
|
||||||
|
<MetricCard
|
||||||
|
label="Outstanding"
|
||||||
|
value={summary.outstandingCredit}
|
||||||
|
icon={walletOutline}
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
<MetricCard
|
||||||
|
label="Repaid (Month)"
|
||||||
|
value={summary.monthRepayments}
|
||||||
|
icon={checkmarkCircleOutline}
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className="pill-toggle"
|
||||||
|
style={{ marginTop: '12px', background: '#ffffff', padding: '8px' }}
|
||||||
|
>
|
||||||
|
<IonButton
|
||||||
|
fill="clear"
|
||||||
|
className="bold"
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: '13px',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
onClick={() => history.push('/sale/new')}
|
||||||
|
>
|
||||||
|
<IonIcon icon={addCircleOutline} slot="start" />
|
||||||
|
Add Sale
|
||||||
|
</IonButton>
|
||||||
|
<IonButton
|
||||||
|
fill="clear"
|
||||||
|
className="bold"
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: '13px',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
onClick={() => history.push('/credit/new')}
|
||||||
|
>
|
||||||
|
<IonIcon icon={personAddOutline} slot="start" />
|
||||||
|
Credit
|
||||||
|
</IonButton>
|
||||||
|
<IonButton
|
||||||
|
fill="clear"
|
||||||
|
className="bold"
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: '13px',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
onClick={() => history.push('/repayment/new')}
|
||||||
|
>
|
||||||
|
<IonIcon icon={cashOutline} slot="start" />
|
||||||
|
Repay
|
||||||
|
</IonButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="section-header">
|
||||||
|
<h2>Recent activity</h2>
|
||||||
|
<span className="see-all" onClick={() => history.push('/history')}>
|
||||||
|
See all
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="page-padding" style={{ paddingBottom: '120px' }}>
|
||||||
|
{loading ? (
|
||||||
|
<div className="widget-card" style={{ gap: '16px' }}>
|
||||||
|
{[1, 2, 3].map((i) => (
|
||||||
|
<div
|
||||||
|
key={i}
|
||||||
|
style={{ display: 'flex', gap: '12px', alignItems: 'center' }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '40px',
|
||||||
|
height: '40px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div style={{ flex: 1 }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '60%',
|
||||||
|
height: '12px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '4px',
|
||||||
|
marginBottom: '6px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '40%',
|
||||||
|
height: '10px',
|
||||||
|
background: 'var(--color-surface-secondary)',
|
||||||
|
borderRadius: '4px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : summary.recentActivity.length > 0 ? (
|
||||||
|
<div className="widget-card" style={{ padding: '8px 16px' }}>
|
||||||
|
{summary.recentActivity.map((item) => (
|
||||||
|
<ActivityRow
|
||||||
|
key={`${item.type}-${item.id}`}
|
||||||
|
item={item}
|
||||||
|
onClick={
|
||||||
|
item.customerId
|
||||||
|
? () => history.push(`/customers/${item.customerId}`)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<EmptyState
|
||||||
|
icon={receiptOutline}
|
||||||
|
title="No activity yet"
|
||||||
|
description="Record your first sale or credit to see it here."
|
||||||
|
actionText="Add Sale"
|
||||||
|
onAction={() => history.push('/sale/new')}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<IonActionSheet
|
||||||
|
isOpen={showQuickActions}
|
||||||
|
onDidDismiss={() => setShowQuickActions(false)}
|
||||||
|
header="Settings"
|
||||||
|
buttons={[
|
||||||
|
{
|
||||||
|
text: 'Sign Out',
|
||||||
|
role: 'destructive',
|
||||||
|
handler: () => {
|
||||||
|
supabase.auth.signOut();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Cancel',
|
||||||
|
role: 'cancel',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default Home;
|
export default Home;
|
||||||
|
|||||||
@@ -1,699 +0,0 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
|
||||||
import {
|
|
||||||
IonButton,
|
|
||||||
IonContent,
|
|
||||||
IonIcon,
|
|
||||||
IonPage,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
apps,
|
|
||||||
close,
|
|
||||||
heart,
|
|
||||||
optionsOutline,
|
|
||||||
paperPlane,
|
|
||||||
refreshOutline,
|
|
||||||
walk,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import Lottie from 'lottie-react';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import { getStorageUrl } from '../utils/storage';
|
|
||||||
import { previewProfiles } from '../utils/previewData';
|
|
||||||
import { isPreviewMode } from '../utils/previewMode';
|
|
||||||
import heartsAnimation from '../assets/images/hearts.json';
|
|
||||||
|
|
||||||
type SwipeAction = 'like' | 'skip';
|
|
||||||
|
|
||||||
type DragState = {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
startX: number;
|
|
||||||
startY: number;
|
|
||||||
active: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const SWIPE_THRESHOLD = 105;
|
|
||||||
const EXIT_DISTANCE = 620;
|
|
||||||
|
|
||||||
const calculateAge = (birthDate?: string | null, fallback?: number) => {
|
|
||||||
if (fallback) return fallback;
|
|
||||||
if (!birthDate) return null;
|
|
||||||
const birth = new Date(birthDate);
|
|
||||||
if (Number.isNaN(birth.getTime())) return null;
|
|
||||||
const today = new Date();
|
|
||||||
let age = today.getFullYear() - birth.getFullYear();
|
|
||||||
const monthDiff = today.getMonth() - birth.getMonth();
|
|
||||||
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
|
|
||||||
age -= 1;
|
|
||||||
}
|
|
||||||
return age;
|
|
||||||
};
|
|
||||||
|
|
||||||
const IcebreakerPage: React.FC = () => {
|
|
||||||
const { user } = useAuth();
|
|
||||||
const previewMode = isPreviewMode();
|
|
||||||
const cardRef = useRef<HTMLDivElement | null>(null);
|
|
||||||
const [profiles, setProfiles] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [currentIndex, setCurrentIndex] = useState(0);
|
|
||||||
const [swiping, setSwiping] = useState(false);
|
|
||||||
const [showHearts, setShowHearts] = useState(false);
|
|
||||||
const [drag, setDrag] = useState<DragState | null>(null);
|
|
||||||
const [exitDirection, setExitDirection] = useState<SwipeAction | null>(null);
|
|
||||||
|
|
||||||
const fetchProfiles = async () => {
|
|
||||||
if (previewMode) {
|
|
||||||
setProfiles(previewProfiles);
|
|
||||||
setCurrentIndex(0);
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const { data: swipedData } = await supabase
|
|
||||||
.from('swipes')
|
|
||||||
.select('swiped_id')
|
|
||||||
.eq('swiper_id', user.id);
|
|
||||||
|
|
||||||
const swipedIds = swipedData?.map((s) => s.swiped_id) || [];
|
|
||||||
const excludedIds = [user.id, ...swipedIds].filter(Boolean);
|
|
||||||
|
|
||||||
let query = supabase
|
|
||||||
.from('profiles')
|
|
||||||
.select('*, profile_photos(storage_path, position)')
|
|
||||||
.neq('id', user.id)
|
|
||||||
.limit(20);
|
|
||||||
|
|
||||||
if (excludedIds.length > 0) {
|
|
||||||
query = query.not('id', 'in', `(${excludedIds.join(',')})`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data, error } = await query;
|
|
||||||
if (error) throw error;
|
|
||||||
setProfiles(data || []);
|
|
||||||
setCurrentIndex(0);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Profile fetch error:', err);
|
|
||||||
setProfiles([]);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
fetchProfiles();
|
|
||||||
});
|
|
||||||
|
|
||||||
const displayProfiles = previewMode ? previewProfiles : profiles;
|
|
||||||
const currentProfile = displayProfiles.length
|
|
||||||
? displayProfiles[currentIndex % displayProfiles.length]
|
|
||||||
: null;
|
|
||||||
const nextProfile =
|
|
||||||
displayProfiles.length > 1
|
|
||||||
? displayProfiles[(currentIndex + 1) % displayProfiles.length]
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const getProfileImages = (profile: any) => {
|
|
||||||
if (!profile) return [];
|
|
||||||
if (Array.isArray(profile.images) && profile.images.length > 0) {
|
|
||||||
return profile.images;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
Array.isArray(profile.profile_photos) &&
|
|
||||||
profile.profile_photos.length > 0
|
|
||||||
) {
|
|
||||||
return profile.profile_photos
|
|
||||||
.slice()
|
|
||||||
.sort((a: any, b: any) => (a.position || 0) - (b.position || 0))
|
|
||||||
.map((photo: any) =>
|
|
||||||
getStorageUrl('profile-photos', photo.storage_path)
|
|
||||||
)
|
|
||||||
.filter(Boolean);
|
|
||||||
}
|
|
||||||
return [
|
|
||||||
profile.image ||
|
|
||||||
profile.avatar ||
|
|
||||||
getStorageUrl('avatars', profile.avatar_path) ||
|
|
||||||
'',
|
|
||||||
].filter(Boolean);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getProfileImage = (profile: any) => getProfileImages(profile)[0] || '';
|
|
||||||
|
|
||||||
const commitSwipe = async (action: SwipeAction) => {
|
|
||||||
if (displayProfiles.length === 0) return;
|
|
||||||
|
|
||||||
if (previewMode) {
|
|
||||||
setCurrentIndex((prev) => (prev + 1) % displayProfiles.length);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const targetUserId = profiles[currentIndex]?.id;
|
|
||||||
if (!targetUserId) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { data, error } = await supabase.functions.invoke('handle-swipe', {
|
|
||||||
body: { targetUserId, action },
|
|
||||||
});
|
|
||||||
if (error) throw error;
|
|
||||||
if (data?.matched && action === 'like') {
|
|
||||||
setShowHearts(true);
|
|
||||||
setTimeout(() => setShowHearts(false), 1250);
|
|
||||||
}
|
|
||||||
setCurrentIndex((prev) => prev + 1);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Swipe error:', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const animateSwipe = (action: SwipeAction) => {
|
|
||||||
if (swiping || !currentProfile) return;
|
|
||||||
setSwiping(true);
|
|
||||||
setExitDirection(action);
|
|
||||||
setDrag((prev) => ({
|
|
||||||
x: action === 'like' ? EXIT_DISTANCE : -EXIT_DISTANCE,
|
|
||||||
y: prev?.y || -12,
|
|
||||||
startX: prev?.startX || 0,
|
|
||||||
startY: prev?.startY || 0,
|
|
||||||
active: false,
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (action === 'like') {
|
|
||||||
setShowHearts(true);
|
|
||||||
setTimeout(() => setShowHearts(false), 1250);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.setTimeout(async () => {
|
|
||||||
await commitSwipe(action);
|
|
||||||
setDrag(null);
|
|
||||||
setExitDirection(null);
|
|
||||||
setSwiping(false);
|
|
||||||
}, 280);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
||||||
if (swiping || !currentProfile) return;
|
|
||||||
cardRef.current?.setPointerCapture(event.pointerId);
|
|
||||||
setDrag({
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
startX: event.clientX,
|
|
||||||
startY: event.clientY,
|
|
||||||
active: true,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePointerMove = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
||||||
if (!drag?.active || swiping) return;
|
|
||||||
setDrag({
|
|
||||||
...drag,
|
|
||||||
x: event.clientX - drag.startX,
|
|
||||||
y: event.clientY - drag.startY,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePointerUp = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
||||||
if (!drag || swiping) return;
|
|
||||||
cardRef.current?.releasePointerCapture(event.pointerId);
|
|
||||||
|
|
||||||
const absX = Math.abs(drag.x);
|
|
||||||
const absY = Math.abs(drag.y);
|
|
||||||
|
|
||||||
if (absX < 8 && absY < 8) {
|
|
||||||
const isRightHalf = event.clientX > window.innerWidth / 2;
|
|
||||||
setDrag(null);
|
|
||||||
animateSwipe(isRightHalf ? 'like' : 'skip');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (drag.x > SWIPE_THRESHOLD) {
|
|
||||||
animateSwipe('like');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (drag.x < -SWIPE_THRESHOLD) {
|
|
||||||
animateSwipe('skip');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setDrag({ ...drag, x: 0, y: 0, active: false });
|
|
||||||
window.setTimeout(() => setDrag(null), 180);
|
|
||||||
};
|
|
||||||
|
|
||||||
const dragX = drag?.x || 0;
|
|
||||||
const dragY = drag?.y || 0;
|
|
||||||
const rotate = Math.max(-12, Math.min(12, dragX / 22));
|
|
||||||
const transition = drag?.active
|
|
||||||
? 'none'
|
|
||||||
: 'transform 280ms cubic-bezier(.2,.9,.22,1), opacity 220ms ease';
|
|
||||||
const topTransform = `translate3d(${dragX}px, ${dragY}px, 0) rotate(${rotate}deg)`;
|
|
||||||
|
|
||||||
const name = currentProfile?.full_name || currentProfile?.name || 'Nearby';
|
|
||||||
const age = calculateAge(currentProfile?.birth_date, currentProfile?.age);
|
|
||||||
const distance =
|
|
||||||
currentProfile?.distance || currentProfile?.travelTime || '3 min';
|
|
||||||
const interests =
|
|
||||||
currentProfile?.interests || currentProfile?.userProfile?.interests || [];
|
|
||||||
const currentImages = getProfileImages(currentProfile);
|
|
||||||
const currentImage = currentImages[0] || getProfileImage(currentProfile);
|
|
||||||
const topProgressBars =
|
|
||||||
currentImages.length > 0 ? currentImages : [currentImage];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonContent
|
|
||||||
fullscreen
|
|
||||||
style={{ '--background': '#000000' }}
|
|
||||||
scrollY={false}
|
|
||||||
>
|
|
||||||
<main
|
|
||||||
style={{
|
|
||||||
position: 'fixed',
|
|
||||||
inset: 0,
|
|
||||||
background: '#000000',
|
|
||||||
overflow: 'hidden',
|
|
||||||
touchAction: 'none',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
inset: 0,
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
color: '#ffffff',
|
|
||||||
fontSize: 15,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Finding people nearby…
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!loading && nextProfile && (
|
|
||||||
<article
|
|
||||||
aria-hidden="true"
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
top: 'calc(var(--ion-safe-area-top, 0px) + 6px)',
|
|
||||||
bottom: 'calc(76px + var(--ion-safe-area-bottom, 0px))',
|
|
||||||
borderRadius: 0,
|
|
||||||
overflow: 'hidden',
|
|
||||||
background: '#111111',
|
|
||||||
transform: 'scale(0.975)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src={getProfileImage(nextProfile)}
|
|
||||||
alt="Next profile"
|
|
||||||
draggable={false}
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
objectFit: 'cover',
|
|
||||||
objectPosition: 'center',
|
|
||||||
userSelect: 'none',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</article>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!loading && currentProfile && (
|
|
||||||
<article
|
|
||||||
ref={cardRef}
|
|
||||||
onPointerDown={handlePointerDown}
|
|
||||||
onPointerMove={handlePointerMove}
|
|
||||||
onPointerUp={handlePointerUp}
|
|
||||||
onPointerCancel={handlePointerUp}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
top: 'calc(var(--ion-safe-area-top, 0px) + 6px)',
|
|
||||||
bottom: 'calc(76px + var(--ion-safe-area-bottom, 0px))',
|
|
||||||
borderRadius: 0,
|
|
||||||
transform: topTransform,
|
|
||||||
transition,
|
|
||||||
opacity: exitDirection ? 0.9 : 1,
|
|
||||||
overflow: 'hidden',
|
|
||||||
background: '#111111',
|
|
||||||
cursor: drag?.active ? 'grabbing' : 'grab',
|
|
||||||
willChange: 'transform, opacity',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
key={currentProfile.id}
|
|
||||||
src={currentImage}
|
|
||||||
alt={name}
|
|
||||||
draggable={false}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
inset: 0,
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
objectFit: 'cover',
|
|
||||||
objectPosition: 'center',
|
|
||||||
userSelect: 'none',
|
|
||||||
pointerEvents: 'none',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
inset: 0,
|
|
||||||
background:
|
|
||||||
'linear-gradient(180deg, rgba(0,0,0,0.08) 0%, rgba(0,0,0,0.02) 45%, rgba(0,0,0,0.62) 73%, rgba(0,0,0,0.96) 100%)',
|
|
||||||
pointerEvents: 'none',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 7,
|
|
||||||
left: 8,
|
|
||||||
right: 8,
|
|
||||||
display: 'grid',
|
|
||||||
gridTemplateColumns: `repeat(${topProgressBars.length}, 1fr)`,
|
|
||||||
gap: 4,
|
|
||||||
zIndex: 4,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{topProgressBars.map((_, index) => (
|
|
||||||
<div
|
|
||||||
key={`media-progress-${index}`}
|
|
||||||
style={{
|
|
||||||
height: 3,
|
|
||||||
borderRadius: 999,
|
|
||||||
background:
|
|
||||||
index === 0
|
|
||||||
? 'rgba(255,255,255,0.94)'
|
|
||||||
: 'rgba(30,30,30,0.72)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<IonButton
|
|
||||||
fill="clear"
|
|
||||||
aria-label="Filter profiles"
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 24,
|
|
||||||
right: 14,
|
|
||||||
zIndex: 8,
|
|
||||||
'--color': '#fe3c72',
|
|
||||||
'--background': 'rgba(28, 28, 28, 0.76)',
|
|
||||||
'--border-radius': '999px',
|
|
||||||
width: 48,
|
|
||||||
height: 48,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={optionsOutline}
|
|
||||||
slot="icon-only"
|
|
||||||
style={{ fontSize: 27 }}
|
|
||||||
/>
|
|
||||||
</IonButton>
|
|
||||||
|
|
||||||
<section
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
left: 14,
|
|
||||||
right: 14,
|
|
||||||
bottom: '34px',
|
|
||||||
zIndex: 4,
|
|
||||||
color: '#ffffff',
|
|
||||||
pointerEvents: 'none',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'flex-start',
|
|
||||||
gap: 14,
|
|
||||||
marginBottom: 22,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 0,
|
|
||||||
textShadow: '0 2px 14px rgba(0,0,0,0.75)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h1
|
|
||||||
style={{
|
|
||||||
margin: '0 0 4px',
|
|
||||||
fontSize: 30,
|
|
||||||
lineHeight: 1,
|
|
||||||
fontWeight: 900,
|
|
||||||
letterSpacing: -0.8,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{name}, {age || ''}
|
|
||||||
</h1>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: 6,
|
|
||||||
color: '#ffffff',
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: 800,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={walk}
|
|
||||||
style={{
|
|
||||||
color: '#ffffff',
|
|
||||||
flexShrink: 0,
|
|
||||||
fontSize: 25,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<span>{distance}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<IonButton
|
|
||||||
aria-label="Send heart message"
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
animateSwipe('like');
|
|
||||||
}}
|
|
||||||
style={{
|
|
||||||
'--background': '#fe3c72',
|
|
||||||
'--color': '#111111',
|
|
||||||
'--border-radius': '999px',
|
|
||||||
width: 52,
|
|
||||||
height: 52,
|
|
||||||
marginTop: 2,
|
|
||||||
pointerEvents: 'auto',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={paperPlane}
|
|
||||||
slot="icon-only"
|
|
||||||
style={{ fontSize: 24 }}
|
|
||||||
/>
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: 8,
|
|
||||||
marginBottom: 10,
|
|
||||||
fontSize: 21,
|
|
||||||
fontWeight: 900,
|
|
||||||
textShadow: '0 2px 12px rgba(0,0,0,0.8)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={apps}
|
|
||||||
style={{ color: '#ffffff', fontSize: 32, flexShrink: 0 }}
|
|
||||||
/>
|
|
||||||
<span>Interests</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexWrap: 'wrap',
|
|
||||||
gap: 8,
|
|
||||||
maxWidth: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{interests
|
|
||||||
.slice(0, 5)
|
|
||||||
.map((interest: string, index: number) => (
|
|
||||||
<span
|
|
||||||
key={interest}
|
|
||||||
style={{
|
|
||||||
padding: '7px 13px',
|
|
||||||
borderRadius: 999,
|
|
||||||
background:
|
|
||||||
index === 0 || index === 3
|
|
||||||
? '#fe3c72'
|
|
||||||
: 'rgba(44, 53, 57, 0.78)',
|
|
||||||
color: '#ffffff',
|
|
||||||
fontSize: 16,
|
|
||||||
lineHeight: 1,
|
|
||||||
fontWeight: 650,
|
|
||||||
backdropFilter: 'blur(12px)',
|
|
||||||
maxWidth: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{interest}
|
|
||||||
</span>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</article>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!loading && displayProfiles.length === 0 && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
inset: 0,
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: 14,
|
|
||||||
color: '#ffffff',
|
|
||||||
padding: 24,
|
|
||||||
textAlign: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ fontSize: 18, fontWeight: 800 }}>
|
|
||||||
No nearby profiles right now.
|
|
||||||
</div>
|
|
||||||
<IonButton
|
|
||||||
onClick={fetchProfiles}
|
|
||||||
style={{
|
|
||||||
'--background': '#fe3c72',
|
|
||||||
'--border-radius': '999px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon icon={refreshOutline} slot="start" />
|
|
||||||
Refresh
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!loading && currentProfile && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 'calc(24px + var(--ion-safe-area-bottom, 0px))',
|
|
||||||
zIndex: 10,
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-around',
|
|
||||||
alignItems: 'center',
|
|
||||||
padding: '0 54px',
|
|
||||||
pointerEvents: 'none',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonButton
|
|
||||||
aria-label="Skip"
|
|
||||||
onClick={() => animateSwipe('skip')}
|
|
||||||
style={{
|
|
||||||
'--background': 'rgba(45,45,45,0.92)',
|
|
||||||
'--color': '#ff9f0a',
|
|
||||||
'--border-radius': '999px',
|
|
||||||
width: 70,
|
|
||||||
height: 70,
|
|
||||||
pointerEvents: 'auto',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={close}
|
|
||||||
slot="icon-only"
|
|
||||||
style={{ fontSize: 40, fontWeight: 900 }}
|
|
||||||
/>
|
|
||||||
</IonButton>
|
|
||||||
<IonButton
|
|
||||||
aria-label="Like"
|
|
||||||
onClick={() => animateSwipe('like')}
|
|
||||||
style={{
|
|
||||||
'--background': 'rgba(45,45,45,0.92)',
|
|
||||||
'--color': '#ff0000',
|
|
||||||
'--border-radius': '999px',
|
|
||||||
width: 70,
|
|
||||||
height: 70,
|
|
||||||
pointerEvents: 'auto',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={heart}
|
|
||||||
slot="icon-only"
|
|
||||||
style={{ fontSize: 42 }}
|
|
||||||
/>
|
|
||||||
</IonButton>
|
|
||||||
<IonButton
|
|
||||||
aria-label="Message"
|
|
||||||
onClick={() => animateSwipe('like')}
|
|
||||||
style={{
|
|
||||||
'--background': 'rgba(45,45,45,0.92)',
|
|
||||||
'--color': '#1683ff',
|
|
||||||
'--border-radius': '999px',
|
|
||||||
width: 70,
|
|
||||||
height: 70,
|
|
||||||
pointerEvents: 'auto',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={paperPlane}
|
|
||||||
slot="icon-only"
|
|
||||||
style={{ fontSize: 38 }}
|
|
||||||
/>
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{showHearts && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
inset: 0,
|
|
||||||
zIndex: 20,
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
pointerEvents: 'none',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Lottie
|
|
||||||
animationData={heartsAnimation}
|
|
||||||
loop={false}
|
|
||||||
style={{ width: 310 }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</main>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default IcebreakerPage;
|
|
||||||
@@ -1,54 +1,59 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
IonPage,
|
|
||||||
IonContent,
|
IonContent,
|
||||||
|
IonPage,
|
||||||
IonInput,
|
IonInput,
|
||||||
IonItem,
|
|
||||||
IonButton,
|
IonButton,
|
||||||
IonSpinner,
|
IonSpinner,
|
||||||
useIonViewWillEnter,
|
IonIcon,
|
||||||
} from '@ionic/react';
|
} from '@ionic/react';
|
||||||
|
import { chevronBackOutline } from 'ionicons/icons';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
|
|
||||||
const NewPasswordPage: React.FC = () => {
|
const NewPasswordPage: React.FC = () => {
|
||||||
const history = useHistory();
|
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const [confirmPassword, setConfirmPassword] = useState('');
|
const [confirmPassword, setConfirmPassword] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [message, setMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
const history = useHistory();
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
});
|
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
const showMessage = (msg: string) => {
|
||||||
setError(msg);
|
setMessage(msg);
|
||||||
setTimeout(() => setError(null), 4000);
|
setTimeout(() => setMessage(null), 4000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpdate = async (e: React.FormEvent) => {
|
const handleUpdate = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (password !== confirmPassword) {
|
if (!password || !confirmPassword) {
|
||||||
showError("Passwords don't match");
|
showMessage('Please fill in all fields');
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (password.length < 6) {
|
|
||||||
showError('Password must be at least 6 characters');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(true);
|
if (password.length < 6) {
|
||||||
|
showMessage('Password must be at least 6 characters');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password !== confirmPassword) {
|
||||||
|
showMessage('Passwords do not match');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
setMessage(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { error } = await supabase.auth.updateUser({ password });
|
const { error } = await supabase.auth.updateUser({ password });
|
||||||
|
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
history.push('/icebreaker');
|
|
||||||
|
history.push('/home');
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showError(err.message);
|
showMessage(err.message || 'An error occurred');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,106 +62,116 @@ const NewPasswordPage: React.FC = () => {
|
|||||||
<IonContent
|
<IonContent
|
||||||
fullscreen
|
fullscreen
|
||||||
style={{
|
style={{
|
||||||
'--background': 'var(--color-bg)',
|
'--background':
|
||||||
|
'linear-gradient(160deg, rgba(199,210,254,0.52) 0%, #f0f4ff 58%, #f8fafc 100%)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ padding: 'calc(var(--ion-safe-area-top) + 40px) 20px' }}>
|
<div className="auth-shell">
|
||||||
<div style={{ marginBottom: '32px' }}>
|
<IonButton
|
||||||
<h1
|
fill="clear"
|
||||||
|
color="dark"
|
||||||
|
onClick={() => history.push('/auth')}
|
||||||
style={{
|
style={{
|
||||||
fontSize: '28px',
|
position: 'absolute',
|
||||||
fontWeight: 800,
|
top: 'calc(var(--ion-safe-area-top, 0px) + 8px)',
|
||||||
color: 'var(--color-text-primary)',
|
left: '8px',
|
||||||
margin: '0 0 8px',
|
'--padding-start': '8px',
|
||||||
|
'--padding-end': '8px',
|
||||||
|
zIndex: 10,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Create New Password
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
width: '44px',
|
||||||
|
height: '44px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon icon={chevronBackOutline} />
|
||||||
|
</div>
|
||||||
|
</IonButton>
|
||||||
|
|
||||||
|
<div style={{ marginTop: '80px' }}>
|
||||||
|
<h1
|
||||||
|
className="bold"
|
||||||
|
style={{ fontSize: '24px', margin: '0 0 8px 0' }}
|
||||||
|
>
|
||||||
|
Create new password
|
||||||
</h1>
|
</h1>
|
||||||
<p
|
<p
|
||||||
style={{
|
className="secondary-text"
|
||||||
fontSize: '15px',
|
style={{ margin: '0', fontSize: '14px' }}
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
margin: 0,
|
|
||||||
lineHeight: 1.5,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Choose a strong password for your InSpot account.
|
Set a strong password to protect your account.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="auth-card">
|
||||||
<form
|
<form
|
||||||
onSubmit={handleUpdate}
|
onSubmit={handleUpdate}
|
||||||
style={{
|
style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}
|
||||||
background: 'var(--color-surface)',
|
|
||||||
padding: '24px',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
|
<div className="input-wrapper">
|
||||||
<IonInput
|
<IonInput
|
||||||
label="New Password"
|
label="New Password"
|
||||||
labelPlacement="floating"
|
labelPlacement="floating"
|
||||||
type="password"
|
type="password"
|
||||||
|
placeholder="Min. 6 characters"
|
||||||
value={password}
|
value={password}
|
||||||
onIonInput={(e) => setPassword(e.detail.value!)}
|
onIonChange={(e) => setPassword(e.detail.value!)}
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
</IonItem>
|
</div>
|
||||||
|
|
||||||
<IonItem
|
<div className="input-wrapper">
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonInput
|
<IonInput
|
||||||
label="Confirm Password"
|
label="Confirm Password"
|
||||||
labelPlacement="floating"
|
labelPlacement="floating"
|
||||||
type="password"
|
type="password"
|
||||||
|
placeholder="Repeat your password"
|
||||||
value={confirmPassword}
|
value={confirmPassword}
|
||||||
onIonInput={(e) => setConfirmPassword(e.detail.value!)}
|
onIonChange={(e) => setConfirmPassword(e.detail.value!)}
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
</IonItem>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{message && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
background: 'rgba(220, 38, 38, 0.08)',
|
background: 'var(--color-danger-soft)',
|
||||||
color: 'var(--ion-color-danger)',
|
color: 'var(--ion-color-danger-shade)',
|
||||||
padding: '12px',
|
padding: '12px',
|
||||||
borderRadius: 'var(--radius-control)',
|
borderRadius: '12px',
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
|
textAlign: 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{error}
|
{message}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<IonButton
|
<IonButton
|
||||||
type="submit"
|
type="submit"
|
||||||
expand="block"
|
expand="block"
|
||||||
disabled={loading}
|
className="bold"
|
||||||
style={{
|
style={{
|
||||||
|
height: '52px',
|
||||||
'--border-radius': 'var(--radius-pill)',
|
'--border-radius': 'var(--radius-pill)',
|
||||||
height: '48px',
|
|
||||||
marginTop: '8px',
|
marginTop: '8px',
|
||||||
}}
|
}}
|
||||||
|
disabled={submitting}
|
||||||
>
|
>
|
||||||
{loading ? <IonSpinner name="crescent" /> : 'Update Password'}
|
{submitting ? (
|
||||||
|
<IonSpinner name="crescent" />
|
||||||
|
) : (
|
||||||
|
'Update password'
|
||||||
|
)}
|
||||||
</IonButton>
|
</IonButton>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,242 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonTitle,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
chevronBackOutline,
|
|
||||||
notificationsOutline,
|
|
||||||
heart,
|
|
||||||
chatbubble,
|
|
||||||
people,
|
|
||||||
flash,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import { formatTime } from '../utils/format';
|
|
||||||
import EmptyState from '../components/EmptyState';
|
|
||||||
import { previewNotifications } from '../utils/previewData';
|
|
||||||
import { isPreviewMode } from '../utils/previewMode';
|
|
||||||
import Lottie from 'lottie-react';
|
|
||||||
import notificationsAnimation from '../assets/images/InSpotNotifications.json';
|
|
||||||
|
|
||||||
const NotificationsPage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const previewMode = isPreviewMode();
|
|
||||||
const [notifications, setNotifications] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
|
|
||||||
const fetchNotifications = async () => {
|
|
||||||
if (previewMode) {
|
|
||||||
setNotifications(previewNotifications);
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!user) return;
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const { data, error } = await supabase
|
|
||||||
.from('notifications')
|
|
||||||
.select('*')
|
|
||||||
.eq('user_id', user.id)
|
|
||||||
.order('created_at', { ascending: false });
|
|
||||||
|
|
||||||
if (error) throw error;
|
|
||||||
setNotifications(data || []);
|
|
||||||
|
|
||||||
// Mark as read after a short delay
|
|
||||||
if (data && data.some((n) => !n.read_at)) {
|
|
||||||
setTimeout(async () => {
|
|
||||||
await supabase
|
|
||||||
.from('notifications')
|
|
||||||
.update({ read_at: new Date().toISOString() })
|
|
||||||
.eq('user_id', user.id)
|
|
||||||
.is('read_at', null);
|
|
||||||
}, 2000);
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Fetch notifications error:', err);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
fetchNotifications();
|
|
||||||
});
|
|
||||||
|
|
||||||
const getIcon = (type: string) => {
|
|
||||||
switch (type) {
|
|
||||||
case 'reel_like':
|
|
||||||
return heart;
|
|
||||||
case 'reel_comment':
|
|
||||||
return chatbubble;
|
|
||||||
case 'match':
|
|
||||||
return people;
|
|
||||||
case 'message':
|
|
||||||
return chatbubble;
|
|
||||||
default:
|
|
||||||
return flash;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ '--color': 'var(--color-text-primary)' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle>Notifications</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent fullscreen style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
{previewMode && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '12px 20px 0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Lottie
|
|
||||||
animationData={notificationsAnimation}
|
|
||||||
loop
|
|
||||||
style={{ width: 120 }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div style={{ padding: '16px 20px' }}>
|
|
||||||
{loading ? (
|
|
||||||
<div style={{ textAlign: 'center', padding: '40px' }}>
|
|
||||||
<IonSpinner name="crescent" color="primary" />
|
|
||||||
</div>
|
|
||||||
) : notifications.length === 0 ? (
|
|
||||||
<EmptyState
|
|
||||||
icon={notificationsOutline}
|
|
||||||
title="No notifications yet"
|
|
||||||
message="When you get likes, matches, or messages, they'll show up here."
|
|
||||||
ctaText="Go discover"
|
|
||||||
onCtaClick={() => history.push('/icebreaker')}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '12px' }}
|
|
||||||
>
|
|
||||||
{notifications.map((n) => (
|
|
||||||
<div
|
|
||||||
key={n.id}
|
|
||||||
onClick={() => {
|
|
||||||
if (previewMode && !n.read_at) {
|
|
||||||
setNotifications((prev) =>
|
|
||||||
prev.map((item) =>
|
|
||||||
item.id === n.id
|
|
||||||
? { ...item, read_at: new Date().toISOString() }
|
|
||||||
: item
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (n.deep_link) history.push(n.deep_link);
|
|
||||||
}}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
padding: '16px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
boxShadow: 'var(--shadow-card)',
|
|
||||||
opacity: n.read_at ? 0.7 : 1,
|
|
||||||
position: 'relative',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-accent-soft)',
|
|
||||||
width: '44px',
|
|
||||||
height: '44px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={getIcon(n.type)}
|
|
||||||
style={{
|
|
||||||
color: 'var(--ion-color-primary)',
|
|
||||||
fontSize: '20px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div style={{ flex: 1 }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: 700,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
marginBottom: '2px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{n.title}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
lineHeight: 1.4,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{n.body}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '11px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
marginTop: '4px',
|
|
||||||
fontWeight: 600,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{formatTime(n.created_at)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{!n.read_at && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '8px',
|
|
||||||
height: '8px',
|
|
||||||
background: 'var(--ion-color-primary)',
|
|
||||||
borderRadius: '50%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default NotificationsPage;
|
|
||||||
@@ -1,318 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonInput,
|
|
||||||
IonItem,
|
|
||||||
IonButton,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
IonSelect,
|
|
||||||
IonSelectOption,
|
|
||||||
IonTextarea,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import Avatar from '../components/Avatar';
|
|
||||||
|
|
||||||
const OnboardingProfilePage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user, refreshProfile } = useAuth();
|
|
||||||
const [fullName, setFullName] = useState('');
|
|
||||||
const [birthDate, setBirthDate] = useState('');
|
|
||||||
const [bio, setBio] = useState('');
|
|
||||||
const [gender, setGender] = useState('');
|
|
||||||
const [relationshipGoal, setRelationshipGoal] = useState('');
|
|
||||||
const [avatarPath, setAvatarPath] = useState<string | null>(null);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [uploading, setUploading] = useState(false);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
if (!user) history.replace('/auth');
|
|
||||||
});
|
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
|
||||||
setError(msg);
|
|
||||||
setTimeout(() => setError(null), 4000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
const file = e.target.files?.[0];
|
|
||||||
if (!file || !user) return;
|
|
||||||
|
|
||||||
setUploading(true);
|
|
||||||
try {
|
|
||||||
const fileExt = file.name.split('.').pop();
|
|
||||||
const fileName = `${user.id}-${Math.random()}.${fileExt}`;
|
|
||||||
const filePath = `avatars/${fileName}`;
|
|
||||||
|
|
||||||
const { error: uploadError } = await supabase.storage
|
|
||||||
.from('avatars')
|
|
||||||
.upload(filePath, file);
|
|
||||||
|
|
||||||
if (uploadError) throw uploadError;
|
|
||||||
setAvatarPath(filePath);
|
|
||||||
} catch (err: any) {
|
|
||||||
showError(err.message);
|
|
||||||
} finally {
|
|
||||||
setUploading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleComplete = async () => {
|
|
||||||
if (!fullName || !birthDate || !gender || !relationshipGoal || !user) {
|
|
||||||
showError('Please fill in all required fields');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const { error } = await supabase.from('profiles').upsert({
|
|
||||||
id: user.id,
|
|
||||||
full_name: fullName,
|
|
||||||
birth_date: birthDate,
|
|
||||||
bio,
|
|
||||||
gender,
|
|
||||||
relationship_goal: relationshipGoal,
|
|
||||||
avatar_path: avatarPath,
|
|
||||||
onboarding_complete: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (error) throw error;
|
|
||||||
await refreshProfile();
|
|
||||||
history.push('/icebreaker');
|
|
||||||
} catch (err: any) {
|
|
||||||
showError(err.message);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const goals = [
|
|
||||||
{ label: 'Long-term partner', value: 'long_term' },
|
|
||||||
{ label: 'Long-term, but short-term OK', value: 'long_term_short_ok' },
|
|
||||||
{ label: 'Short-term, but long-term OK', value: 'short_term_long_ok' },
|
|
||||||
{ label: 'Short-term fun', value: 'short_term' },
|
|
||||||
{ label: 'New friends', value: 'friends' },
|
|
||||||
{ label: 'Still figuring it out', value: 'figuring_it_out' },
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonContent fullscreen style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding:
|
|
||||||
'calc(var(--ion-safe-area-top) + 40px) 20px calc(var(--ion-safe-area-bottom) + 40px)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ marginBottom: '32px', textAlign: 'center' }}>
|
|
||||||
<h1
|
|
||||||
style={{
|
|
||||||
fontSize: '28px',
|
|
||||||
fontWeight: 800,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
margin: '0 0 8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Create your profile
|
|
||||||
</h1>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
margin: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Let others know who you are.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
marginBottom: '32px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ position: 'relative' }}>
|
|
||||||
<Avatar
|
|
||||||
src={avatarPath}
|
|
||||||
name={fullName}
|
|
||||||
size={120}
|
|
||||||
style={{ border: '4px solid #ffffff' }}
|
|
||||||
/>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
bottom: 0,
|
|
||||||
right: 0,
|
|
||||||
background: 'var(--ion-color-primary)',
|
|
||||||
color: '#ffffff',
|
|
||||||
width: '36px',
|
|
||||||
height: '36px',
|
|
||||||
borderRadius: '50%',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
cursor: 'pointer',
|
|
||||||
border: '3px solid #ffffff',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{uploading ? <IonSpinner name="crescent" /> : '+'}
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
accept="image/*"
|
|
||||||
onChange={handleFileUpload}
|
|
||||||
hidden
|
|
||||||
disabled={uploading}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
padding: '24px',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonInput
|
|
||||||
label="Full Name"
|
|
||||||
labelPlacement="floating"
|
|
||||||
value={fullName}
|
|
||||||
onIonInput={(e) => setFullName(e.detail.value!)}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonInput
|
|
||||||
label="Birth Date"
|
|
||||||
labelPlacement="floating"
|
|
||||||
type="date"
|
|
||||||
value={birthDate}
|
|
||||||
onIonInput={(e) => setBirthDate(e.detail.value!)}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSelect
|
|
||||||
label="Gender"
|
|
||||||
labelPlacement="floating"
|
|
||||||
value={gender}
|
|
||||||
onIonChange={(e) => setGender(e.detail.value)}
|
|
||||||
interface="action-sheet"
|
|
||||||
>
|
|
||||||
<IonSelectOption value="woman">Woman</IonSelectOption>
|
|
||||||
<IonSelectOption value="man">Man</IonSelectOption>
|
|
||||||
<IonSelectOption value="nonbinary">Non-binary</IonSelectOption>
|
|
||||||
<IonSelectOption value="other">Other</IonSelectOption>
|
|
||||||
<IonSelectOption value="prefer_not_to_say">
|
|
||||||
Prefer not to say
|
|
||||||
</IonSelectOption>
|
|
||||||
</IonSelect>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSelect
|
|
||||||
label="What are you looking for?"
|
|
||||||
labelPlacement="floating"
|
|
||||||
value={relationshipGoal}
|
|
||||||
onIonChange={(e) => setRelationshipGoal(e.detail.value)}
|
|
||||||
interface="action-sheet"
|
|
||||||
>
|
|
||||||
{goals.map((g) => (
|
|
||||||
<IonSelectOption key={g.value} value={g.value}>
|
|
||||||
{g.label}
|
|
||||||
</IonSelectOption>
|
|
||||||
))}
|
|
||||||
</IonSelect>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonItem
|
|
||||||
lines="none"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonTextarea
|
|
||||||
label="Bio"
|
|
||||||
labelPlacement="floating"
|
|
||||||
value={bio}
|
|
||||||
onIonInput={(e) => setBio(e.detail.value!)}
|
|
||||||
placeholder="Write something about yourself..."
|
|
||||||
rows={4}
|
|
||||||
/>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(220, 38, 38, 0.08)',
|
|
||||||
color: 'var(--ion-color-danger)',
|
|
||||||
padding: '12px',
|
|
||||||
borderRadius: 'var(--radius-control)',
|
|
||||||
fontSize: '13px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<IonButton
|
|
||||||
expand="block"
|
|
||||||
disabled={loading || uploading}
|
|
||||||
onClick={handleComplete}
|
|
||||||
style={{
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
height: '48px',
|
|
||||||
marginTop: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? <IonSpinner name="crescent" /> : 'Complete Profile'}
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default OnboardingProfilePage;
|
|
||||||
@@ -1,300 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonTitle,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
chevronBackOutline,
|
|
||||||
checkmarkCircle,
|
|
||||||
cardOutline,
|
|
||||||
infiniteOutline,
|
|
||||||
eyeOutline,
|
|
||||||
heartOutline,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import { formatCurrency } from '../utils/format';
|
|
||||||
import { createCheckout, pollPaymentStatus } from '../utils/payments';
|
|
||||||
|
|
||||||
const PremiumPage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [status, setStatus] = useState<
|
|
||||||
'idle' | 'opening' | 'pending' | 'paid' | 'failed'
|
|
||||||
>('idle');
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSubscribe = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
setStatus('opening');
|
|
||||||
try {
|
|
||||||
const { checkoutUrl, paymentId } = await createCheckout(9.99, 'premium');
|
|
||||||
|
|
||||||
// Phase 1 stub behavior: simulate payment by following stub return
|
|
||||||
window.open(checkoutUrl, '_blank');
|
|
||||||
|
|
||||||
setStatus('pending');
|
|
||||||
const result = await pollPaymentStatus(paymentId);
|
|
||||||
|
|
||||||
if (result === 'paid') {
|
|
||||||
setStatus('paid');
|
|
||||||
setTimeout(() => history.goBack(), 2000);
|
|
||||||
} else {
|
|
||||||
setStatus('failed');
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Payment error:', err);
|
|
||||||
setStatus('failed');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const benefits = [
|
|
||||||
{
|
|
||||||
icon: infiniteOutline,
|
|
||||||
title: 'Unlimited Swipes',
|
|
||||||
desc: 'Swipe as much as you want.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: eyeOutline,
|
|
||||||
title: 'See Who Likes You',
|
|
||||||
desc: 'Check out your admirers instantly.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: heartOutline,
|
|
||||||
title: '5 Super Likes / Day',
|
|
||||||
desc: 'Stand out from the crowd.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: checkmarkCircle,
|
|
||||||
title: 'Verified Badge',
|
|
||||||
desc: 'Get more trust and matches.',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ '--color': 'var(--color-text-primary)' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle>InSpot Premium</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent fullscreen style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
<div style={{ padding: '24px 20px' }}>
|
|
||||||
{/* Pricing Card */}
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
padding: '32px 24px',
|
|
||||||
textAlign: 'center',
|
|
||||||
boxShadow: 'var(--shadow-card)',
|
|
||||||
marginBottom: '32px',
|
|
||||||
border: '2px solid var(--ion-color-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: 800,
|
|
||||||
color: 'var(--ion-color-primary)',
|
|
||||||
marginBottom: '8px',
|
|
||||||
textTransform: 'uppercase',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Full Access
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'baseline',
|
|
||||||
justifyContent: 'center',
|
|
||||||
gap: '4px',
|
|
||||||
marginBottom: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '40px',
|
|
||||||
fontWeight: 800,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
$9.99
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
fontWeight: 600,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
/ month
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
margin: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Cancel anytime. No hidden fees.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h3
|
|
||||||
style={{
|
|
||||||
fontSize: '18px',
|
|
||||||
fontWeight: 800,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
marginBottom: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
What's included
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '20px',
|
|
||||||
marginBottom: '40px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{benefits.map((b, i) => (
|
|
||||||
<div
|
|
||||||
key={i}
|
|
||||||
style={{ display: 'flex', alignItems: 'center', gap: '16px' }}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-accent-soft)',
|
|
||||||
width: '44px',
|
|
||||||
height: '44px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={b.icon}
|
|
||||||
style={{
|
|
||||||
color: 'var(--ion-color-primary)',
|
|
||||||
fontSize: '22px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: 700,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{b.title}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{b.desc}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{status === 'paid' && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(22, 163, 74, 0.08)',
|
|
||||||
color: 'var(--ion-color-success)',
|
|
||||||
padding: '16px',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
textAlign: 'center',
|
|
||||||
marginBottom: '24px',
|
|
||||||
fontWeight: 700,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Payment successful! Welcome to Premium.
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{status === 'failed' && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(220, 38, 38, 0.08)',
|
|
||||||
color: 'var(--ion-color-danger)',
|
|
||||||
padding: '16px',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
textAlign: 'center',
|
|
||||||
marginBottom: '24px',
|
|
||||||
fontWeight: 700,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Payment failed or cancelled. Please try again.
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'fixed',
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
background: '#ffffff',
|
|
||||||
padding: '16px 20px calc(16px + var(--ion-safe-area-bottom))',
|
|
||||||
borderTop: '1px solid rgba(76, 5, 25, 0.05)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonButton
|
|
||||||
expand="block"
|
|
||||||
disabled={loading || status === 'paid'}
|
|
||||||
onClick={handleSubscribe}
|
|
||||||
style={{
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
height: '52px',
|
|
||||||
fontSize: '16px',
|
|
||||||
fontWeight: 700,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? <IonSpinner name="crescent" /> : 'Get Premium Now'}
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PremiumPage;
|
|
||||||
@@ -1,497 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonIcon,
|
|
||||||
IonButton,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
IonAlert,
|
|
||||||
IonItem,
|
|
||||||
IonLabel,
|
|
||||||
IonList,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
settingsOutline,
|
|
||||||
notificationsOutline,
|
|
||||||
checkmarkCircle,
|
|
||||||
chevronForwardOutline,
|
|
||||||
cardOutline,
|
|
||||||
shieldCheckmarkOutline,
|
|
||||||
logOutOutline,
|
|
||||||
trashOutline,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import Avatar from '../components/Avatar';
|
|
||||||
import { getStorageUrl } from '../utils/storage';
|
|
||||||
import { previewCurrentUser, previewReels } from '../utils/previewData';
|
|
||||||
import { isPreviewMode, disablePreviewMode } from '../utils/previewMode';
|
|
||||||
|
|
||||||
const ProfilePage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user, profile, signOut } = useAuth();
|
|
||||||
const previewMode = isPreviewMode();
|
|
||||||
const displayProfile = previewMode && !profile ? previewCurrentUser : profile;
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [reels, setReels] = useState<any[]>([]);
|
|
||||||
const [showDeleteAlert, setShowDeleteAlert] = useState(false);
|
|
||||||
|
|
||||||
const fetchData = async () => {
|
|
||||||
if (previewMode && !user) {
|
|
||||||
setReels(previewReels);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!user) return;
|
|
||||||
const { data } = await supabase
|
|
||||||
.from('reels')
|
|
||||||
.select('id, media_path')
|
|
||||||
.eq('author_id', user.id)
|
|
||||||
.limit(6);
|
|
||||||
setReels(data || []);
|
|
||||||
};
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
fetchData();
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleDeleteAccount = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const { error } = await supabase.functions.invoke('delete-account', {
|
|
||||||
body: { confirm: true },
|
|
||||||
});
|
|
||||||
if (error) throw error;
|
|
||||||
await signOut();
|
|
||||||
history.replace('/auth');
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Delete error:', err);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonContent fullscreen style={{ '--background': 'var(--color-bg)' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: 'calc(16px + var(--ion-safe-area-top)) 20px 12px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h1
|
|
||||||
style={{
|
|
||||||
fontSize: '24px',
|
|
||||||
fontWeight: 800,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
margin: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Profile
|
|
||||||
</h1>
|
|
||||||
<div style={{ display: 'flex', gap: '12px' }}>
|
|
||||||
<IonButton
|
|
||||||
fill="clear"
|
|
||||||
onClick={() => history.push('/notifications')}
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-surface)',
|
|
||||||
'--color': 'var(--color-text-primary)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
width: '44px',
|
|
||||||
height: '44px',
|
|
||||||
margin: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={notificationsOutline}
|
|
||||||
slot="icon-only"
|
|
||||||
style={{ fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
</IonButton>
|
|
||||||
<IonButton
|
|
||||||
fill="clear"
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-surface)',
|
|
||||||
'--color': 'var(--color-text-primary)',
|
|
||||||
'--border-radius': 'var(--radius-control)',
|
|
||||||
width: '44px',
|
|
||||||
height: '44px',
|
|
||||||
margin: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={settingsOutline}
|
|
||||||
slot="icon-only"
|
|
||||||
style={{ fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ padding: '0 20px 24px' }}>
|
|
||||||
{/* Profile Card */}
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
padding: '24px',
|
|
||||||
textAlign: 'center',
|
|
||||||
boxShadow: 'var(--shadow-card)',
|
|
||||||
marginBottom: '24px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'relative',
|
|
||||||
display: 'inline-block',
|
|
||||||
marginBottom: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Avatar
|
|
||||||
src={displayProfile?.avatar_path}
|
|
||||||
name={displayProfile?.full_name}
|
|
||||||
size={96}
|
|
||||||
style={{ border: '4px solid var(--color-bg)' }}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
bottom: 0,
|
|
||||||
right: 0,
|
|
||||||
background: '#ffffff',
|
|
||||||
borderRadius: '50%',
|
|
||||||
padding: '2px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={checkmarkCircle}
|
|
||||||
style={{
|
|
||||||
color: 'var(--ion-color-success)',
|
|
||||||
fontSize: '24px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<h2
|
|
||||||
style={{
|
|
||||||
fontSize: '22px',
|
|
||||||
fontWeight: 800,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
margin: '0 0 4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{displayProfile?.full_name || 'InSpot User'}
|
|
||||||
</h2>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'inline-block',
|
|
||||||
background: 'var(--color-accent-soft)',
|
|
||||||
color: 'var(--ion-color-primary)',
|
|
||||||
padding: '4px 12px',
|
|
||||||
borderRadius: 'var(--radius-pill)',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: 700,
|
|
||||||
marginBottom: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Long-term partner
|
|
||||||
</div>
|
|
||||||
<IonButton
|
|
||||||
expand="block"
|
|
||||||
onClick={() => history.push('/profile/edit')}
|
|
||||||
style={{
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
height: '44px',
|
|
||||||
'--background': 'var(--color-surface-raised)',
|
|
||||||
'--color': 'var(--ion-color-primary)',
|
|
||||||
'--box-shadow': 'none',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Edit Profile
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Premium CTA */}
|
|
||||||
<div
|
|
||||||
onClick={() => history.push('/premium')}
|
|
||||||
style={{
|
|
||||||
background:
|
|
||||||
'linear-gradient(135deg, var(--ion-color-primary) 0%, var(--ion-color-primary-dark) 100%)',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
padding: '20px',
|
|
||||||
color: '#ffffff',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '16px',
|
|
||||||
marginBottom: '24px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(255,255,255,0.2)',
|
|
||||||
width: '48px',
|
|
||||||
height: '48px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon icon={cardOutline} style={{ fontSize: '24px' }} />
|
|
||||||
</div>
|
|
||||||
<div style={{ flex: 1 }}>
|
|
||||||
<div style={{ fontSize: '15px', fontWeight: 800 }}>
|
|
||||||
InSpot Premium
|
|
||||||
</div>
|
|
||||||
<div style={{ fontSize: '12px', opacity: 0.8 }}>
|
|
||||||
Get unlimited swipes and see who likes you.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<IonIcon
|
|
||||||
icon={chevronForwardOutline}
|
|
||||||
style={{ fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* My Reels */}
|
|
||||||
<div style={{ marginBottom: '24px' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
marginBottom: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h3
|
|
||||||
style={{
|
|
||||||
fontSize: '18px',
|
|
||||||
fontWeight: 800,
|
|
||||||
margin: 0,
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
My Reels
|
|
||||||
</h3>
|
|
||||||
<IonButton
|
|
||||||
fill="clear"
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
'--color': 'var(--ion-color-primary)',
|
|
||||||
fontWeight: 700,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
See all
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'grid',
|
|
||||||
gridTemplateColumns: 'repeat(3, 1fr)',
|
|
||||||
gap: '10px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{reels.map((reel) => (
|
|
||||||
<div
|
|
||||||
key={reel.id}
|
|
||||||
style={{
|
|
||||||
paddingBottom: '133%',
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
position: 'relative',
|
|
||||||
overflow: 'hidden',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src={
|
|
||||||
reel.image ||
|
|
||||||
getStorageUrl('reels', reel.media_path) ||
|
|
||||||
''
|
|
||||||
}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
objectFit: 'cover',
|
|
||||||
}}
|
|
||||||
alt="Reel"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
<div
|
|
||||||
onClick={() => history.push('/camera')}
|
|
||||||
style={{
|
|
||||||
paddingBottom: '133%',
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
position: 'relative',
|
|
||||||
border: '2px dashed var(--ion-color-primary)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={trashOutline}
|
|
||||||
style={{
|
|
||||||
fontSize: '24px',
|
|
||||||
color: 'var(--ion-color-primary)',
|
|
||||||
transform: 'rotate(45deg)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Settings List */}
|
|
||||||
<IonList
|
|
||||||
lines="none"
|
|
||||||
style={{ background: 'transparent', padding: 0 }}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: 'var(--radius-card)',
|
|
||||||
padding: '8px',
|
|
||||||
boxShadow: 'var(--shadow-card)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonItem button detail={false} onClick={() => {}}>
|
|
||||||
<div
|
|
||||||
slot="start"
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-accent-soft)',
|
|
||||||
width: '36px',
|
|
||||||
height: '36px',
|
|
||||||
borderRadius: '10px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
marginRight: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={shieldCheckmarkOutline}
|
|
||||||
color="primary"
|
|
||||||
style={{ fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<IonLabel style={{ fontSize: '15px', fontWeight: 600 }}>
|
|
||||||
Privacy & Safety
|
|
||||||
</IonLabel>
|
|
||||||
<IonIcon
|
|
||||||
icon={chevronForwardOutline}
|
|
||||||
slot="end"
|
|
||||||
style={{
|
|
||||||
fontSize: '16px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</IonItem>
|
|
||||||
<IonItem
|
|
||||||
button
|
|
||||||
detail={false}
|
|
||||||
onClick={() => {
|
|
||||||
localStorage.removeItem('inspot-preview-mode');
|
|
||||||
signOut();
|
|
||||||
history.replace('/auth');
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
slot="start"
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-bg)',
|
|
||||||
width: '36px',
|
|
||||||
height: '36px',
|
|
||||||
borderRadius: '10px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
marginRight: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={logOutOutline}
|
|
||||||
color="dark"
|
|
||||||
style={{ fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<IonLabel style={{ fontSize: '15px', fontWeight: 600 }}>
|
|
||||||
Sign Out
|
|
||||||
</IonLabel>
|
|
||||||
</IonItem>
|
|
||||||
<IonItem
|
|
||||||
button
|
|
||||||
detail={false}
|
|
||||||
onClick={() => setShowDeleteAlert(true)}
|
|
||||||
style={{ '--color': 'var(--ion-color-danger)' }}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
slot="start"
|
|
||||||
style={{
|
|
||||||
background: 'rgba(220, 38, 38, 0.08)',
|
|
||||||
width: '36px',
|
|
||||||
height: '36px',
|
|
||||||
borderRadius: '10px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
marginRight: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={trashOutline}
|
|
||||||
color="danger"
|
|
||||||
style={{ fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<IonLabel style={{ fontSize: '15px', fontWeight: 600 }}>
|
|
||||||
Delete Account
|
|
||||||
</IonLabel>
|
|
||||||
</IonItem>
|
|
||||||
</div>
|
|
||||||
</IonList>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<IonAlert
|
|
||||||
isOpen={showDeleteAlert}
|
|
||||||
onDidDismiss={() => setShowDeleteAlert(false)}
|
|
||||||
header="Delete Account"
|
|
||||||
message="Are you sure you want to permanently delete your account? This action cannot be undone."
|
|
||||||
buttons={[
|
|
||||||
{ text: 'Cancel', role: 'cancel' },
|
|
||||||
{
|
|
||||||
text: 'Delete',
|
|
||||||
role: 'destructive',
|
|
||||||
handler: handleDeleteAccount,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ProfilePage;
|
|
||||||
@@ -1,481 +0,0 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonIcon,
|
|
||||||
IonButton,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
IonModal,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonTitle,
|
|
||||||
IonButtons,
|
|
||||||
IonItem,
|
|
||||||
IonInput,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
closeOutline,
|
|
||||||
heartOutline,
|
|
||||||
heart,
|
|
||||||
chatbubbleOutline,
|
|
||||||
shareSocialOutline,
|
|
||||||
logoWhatsapp,
|
|
||||||
pinOutline,
|
|
||||||
send,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { useHistory, useParams } from 'react-router-dom';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import { formatCompactNumber, formatDate } from '../utils/format';
|
|
||||||
import { getStorageUrl } from '../utils/storage';
|
|
||||||
import Avatar from '../components/Avatar';
|
|
||||||
import { previewPlaces, previewReels } from '../utils/previewData';
|
|
||||||
import { isPreviewMode } from '../utils/previewMode';
|
|
||||||
|
|
||||||
const ReelsPage: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { placeId } = useParams<{ placeId: string }>();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const [reels, setReels] = useState<any[]>([]);
|
|
||||||
const [place, setPlace] = useState<any>(null);
|
|
||||||
const [activeIndex, setActiveIndex] = useState(0);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [commentsOpen, setCommentsOpen] = useState(false);
|
|
||||||
const [commentDraft, setCommentDraft] = useState('');
|
|
||||||
const [comments, setComments] = useState<any[]>([]);
|
|
||||||
const [likedReels, setLikedReels] = useState<Set<string>>(new Set());
|
|
||||||
const previewMode = isPreviewMode();
|
|
||||||
|
|
||||||
const fetchReels = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
if (previewMode) {
|
|
||||||
setPlace(previewPlaces.find((p) => p.id === placeId) || previewPlaces[0]);
|
|
||||||
setReels(previewReels);
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const { data: placeData } = await supabase
|
|
||||||
.from('places')
|
|
||||||
.select('*')
|
|
||||||
.eq('id', placeId)
|
|
||||||
.single();
|
|
||||||
setPlace(placeData);
|
|
||||||
|
|
||||||
const { data, error } = await supabase
|
|
||||||
.from('reels')
|
|
||||||
.select(
|
|
||||||
`
|
|
||||||
*,
|
|
||||||
author:profiles(id, full_name, avatar_path)
|
|
||||||
`
|
|
||||||
)
|
|
||||||
.eq('place_id', placeId)
|
|
||||||
.order('created_at', { ascending: false });
|
|
||||||
|
|
||||||
if (error) throw error;
|
|
||||||
setReels(data || []);
|
|
||||||
|
|
||||||
if (user) {
|
|
||||||
const { data: likes } = await supabase
|
|
||||||
.from('reel_likes')
|
|
||||||
.select('reel_id')
|
|
||||||
.eq('user_id', user.id);
|
|
||||||
setLikedReels(new Set(likes?.map((l) => l.reel_id) || []));
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Fetch reels error:', err);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
setStatusBarStyle(Style.Dark);
|
|
||||||
fetchReels();
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleLike = async (reelId: string) => {
|
|
||||||
if (!user && !previewMode) return;
|
|
||||||
const isLiked = likedReels.has(reelId);
|
|
||||||
|
|
||||||
// Optimistic update
|
|
||||||
const newLiked = new Set(likedReels);
|
|
||||||
if (isLiked) newLiked.delete(reelId);
|
|
||||||
else newLiked.add(reelId);
|
|
||||||
setLikedReels(newLiked);
|
|
||||||
|
|
||||||
if (previewMode) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (isLiked) {
|
|
||||||
await supabase
|
|
||||||
.from('reel_likes')
|
|
||||||
.delete()
|
|
||||||
.eq('reel_id', reelId)
|
|
||||||
.eq('user_id', user.id);
|
|
||||||
} else {
|
|
||||||
await supabase
|
|
||||||
.from('reel_likes')
|
|
||||||
.insert({ reel_id: reelId, user_id: user.id });
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Like error:', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const currentReel = reels[activeIndex];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonContent fullscreen style={{ '--background': '#000000' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 'calc(14px + var(--ion-safe-area-top))',
|
|
||||||
left: '20px',
|
|
||||||
zIndex: 10,
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonButton
|
|
||||||
fill="clear"
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{
|
|
||||||
'--background': 'rgba(0,0,0,0.3)',
|
|
||||||
'--color': '#ffffff',
|
|
||||||
'--border-radius': '50%',
|
|
||||||
width: '40px',
|
|
||||||
height: '40px',
|
|
||||||
margin: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon icon={closeOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
<span style={{ color: '#ffffff', fontWeight: 800, fontSize: '18px' }}>
|
|
||||||
Reels
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{loading ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
height: '100%',
|
|
||||||
background: '#000000',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSpinner name="crescent" color="primary" />
|
|
||||||
</div>
|
|
||||||
) : reels.length === 0 ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
height: '100%',
|
|
||||||
color: '#ffffff',
|
|
||||||
padding: '20px',
|
|
||||||
textAlign: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<p>No reels found for this place.</p>
|
|
||||||
<IonButton
|
|
||||||
expand="block"
|
|
||||||
fill="outline"
|
|
||||||
color="light"
|
|
||||||
onClick={() => history.push('/camera')}
|
|
||||||
>
|
|
||||||
Add the first reel
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div
|
|
||||||
onClick={() =>
|
|
||||||
reels.length > 1 &&
|
|
||||||
setActiveIndex((prev) => (prev + 1) % reels.length)
|
|
||||||
}
|
|
||||||
style={{ height: '100%', width: '100%', position: 'relative' }}
|
|
||||||
>
|
|
||||||
{/* Media Area */}
|
|
||||||
<div style={{ width: '100%', height: '100%' }}>
|
|
||||||
{currentReel.media_type === 'video' ? (
|
|
||||||
<video
|
|
||||||
src={
|
|
||||||
currentReel.image ||
|
|
||||||
getStorageUrl('reels', currentReel.media_path) ||
|
|
||||||
''
|
|
||||||
}
|
|
||||||
autoPlay
|
|
||||||
loop
|
|
||||||
muted
|
|
||||||
playsInline
|
|
||||||
style={{ width: '100%', height: '100%', objectFit: 'cover' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<img
|
|
||||||
src={
|
|
||||||
currentReel.image ||
|
|
||||||
getStorageUrl('reels', currentReel.media_path) ||
|
|
||||||
''
|
|
||||||
}
|
|
||||||
style={{ width: '100%', height: '100%', objectFit: 'cover' }}
|
|
||||||
alt="Reel content"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Action Rail */}
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
right: '12px',
|
|
||||||
bottom: '150px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '20px',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
handleLike(currentReel.id);
|
|
||||||
}}
|
|
||||||
style={{ textAlign: 'center' }}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={likedReels.has(currentReel.id) ? heart : heartOutline}
|
|
||||||
style={{
|
|
||||||
fontSize: '32px',
|
|
||||||
color: likedReels.has(currentReel.id)
|
|
||||||
? 'var(--ion-color-primary)'
|
|
||||||
: '#ffffff',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
color: '#ffffff',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: 700,
|
|
||||||
marginTop: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{formatCompactNumber(currentReel.likes_count || 0)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
setCommentsOpen(true);
|
|
||||||
}}
|
|
||||||
style={{ textAlign: 'center' }}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={chatbubbleOutline}
|
|
||||||
style={{ fontSize: '30px', color: '#ffffff' }}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
color: '#ffffff',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: 700,
|
|
||||||
marginTop: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{formatCompactNumber(currentReel.comments_count || 0)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<IonIcon
|
|
||||||
icon={shareSocialOutline}
|
|
||||||
style={{ fontSize: '28px', color: '#ffffff' }}
|
|
||||||
/>
|
|
||||||
<IonIcon
|
|
||||||
icon={logoWhatsapp}
|
|
||||||
style={{ fontSize: '28px', color: '#ffffff' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Caption Overlay */}
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
bottom: 'calc(32px + var(--ion-safe-area-bottom))',
|
|
||||||
left: '20px',
|
|
||||||
right: '88px',
|
|
||||||
color: '#ffffff',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '8px',
|
|
||||||
marginBottom: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--ion-color-primary)',
|
|
||||||
width: '36px',
|
|
||||||
height: '36px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={pinOutline}
|
|
||||||
style={{ fontSize: '18px', color: '#ffffff' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div style={{ fontSize: '13px', fontWeight: 800 }}>
|
|
||||||
{place?.name}
|
|
||||||
</div>
|
|
||||||
<div style={{ fontSize: '11px', opacity: 0.7 }}>
|
|
||||||
{formatDate(currentReel.created_at)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '10px',
|
|
||||||
marginBottom: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Avatar
|
|
||||||
src={currentReel.author.avatar_path}
|
|
||||||
name={currentReel.author.full_name}
|
|
||||||
size={42}
|
|
||||||
/>
|
|
||||||
<span style={{ fontSize: '15px', fontWeight: 700 }}>
|
|
||||||
{currentReel.author.full_name}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
margin: 0,
|
|
||||||
opacity: 0.9,
|
|
||||||
lineHeight: 1.4,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{currentReel.caption}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Simple Next/Prev Controls for Phase 1 */}
|
|
||||||
{reels.length > 1 && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
bottom: '100px',
|
|
||||||
right: '12px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonButton
|
|
||||||
size="small"
|
|
||||||
fill="clear"
|
|
||||||
disabled={activeIndex === 0}
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
setActiveIndex((prev) => prev - 1);
|
|
||||||
}}
|
|
||||||
style={{ '--color': '#ffffff' }}
|
|
||||||
>
|
|
||||||
Prev
|
|
||||||
</IonButton>
|
|
||||||
<IonButton
|
|
||||||
size="small"
|
|
||||||
fill="clear"
|
|
||||||
disabled={activeIndex === reels.length - 1}
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
setActiveIndex((prev) => prev + 1);
|
|
||||||
}}
|
|
||||||
style={{ '--color': '#ffffff' }}
|
|
||||||
>
|
|
||||||
Next
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Comments Sheet */}
|
|
||||||
<IonModal
|
|
||||||
isOpen={commentsOpen}
|
|
||||||
onDidDismiss={() => setCommentsOpen(false)}
|
|
||||||
initialBreakpoint={0.5}
|
|
||||||
breakpoints={[0, 0.5, 0.9]}
|
|
||||||
>
|
|
||||||
<IonHeader>
|
|
||||||
<IonToolbar>
|
|
||||||
<IonTitle>Comments</IonTitle>
|
|
||||||
<IonButtons slot="end">
|
|
||||||
<IonButton onClick={() => setCommentsOpen(false)}>
|
|
||||||
Close
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
<IonContent className="ion-padding">
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
textAlign: 'center',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
padding: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
No comments yet. Be the first to comment!
|
|
||||||
</div>
|
|
||||||
{/* Input area fixed at bottom of modal content */}
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'sticky',
|
|
||||||
bottom: 0,
|
|
||||||
background: '#ffffff',
|
|
||||||
padding: '12px 0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', gap: '12px', alignItems: 'center' }}
|
|
||||||
>
|
|
||||||
<IonInput
|
|
||||||
value={commentDraft}
|
|
||||||
onIonInput={(e) => setCommentDraft(e.detail.value!)}
|
|
||||||
placeholder="Add a comment..."
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-bg)',
|
|
||||||
'--border-radius': 'var(--radius-pill)',
|
|
||||||
'--padding-start': '16px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<IonButton fill="clear" disabled={!commentDraft.trim()}>
|
|
||||||
<IonIcon icon={send} slot="icon-only" color="primary" />
|
|
||||||
</IonButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
|
||||||
</IonModal>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ReelsPage;
|
|
||||||
@@ -0,0 +1,353 @@
|
|||||||
|
import React, { useState, useEffect, useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
IonContent,
|
||||||
|
IonPage,
|
||||||
|
IonHeader,
|
||||||
|
IonToolbar,
|
||||||
|
IonTitle,
|
||||||
|
IonButtons,
|
||||||
|
IonButton,
|
||||||
|
IonIcon,
|
||||||
|
IonInput,
|
||||||
|
IonTextarea,
|
||||||
|
IonSpinner,
|
||||||
|
IonLabel,
|
||||||
|
IonSelect,
|
||||||
|
IonSelectOption,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { chevronBackOutline } from 'ionicons/icons';
|
||||||
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { getTodayISO } from '../utils/dates';
|
||||||
|
import MoneyInput from '../components/MoneyInput';
|
||||||
|
import { parseMoney, formatMoney } from '../utils/money';
|
||||||
|
import EmptyState from '../components/EmptyState';
|
||||||
|
|
||||||
|
interface CustomerWithBalance {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
balance: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const RepaymentFormPage: React.FC = () => {
|
||||||
|
const history = useHistory();
|
||||||
|
const location = useLocation<{ customerId?: string }>();
|
||||||
|
const { user, profile } = useAuth();
|
||||||
|
const currency = profile?.currency || 'USD';
|
||||||
|
|
||||||
|
const [customers, setCustomers] = useState<CustomerWithBalance[]>([]);
|
||||||
|
const [selectedCustomerId, setSelectedCustomerId] = useState<string>(
|
||||||
|
location.state?.customerId || ''
|
||||||
|
);
|
||||||
|
const [amount, setAmount] = useState('');
|
||||||
|
const [repaymentDate, setRepaymentDate] = useState(getTodayISO());
|
||||||
|
const [note, setNote] = useState('');
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const [loadingCustomers, setLoadingCustomers] = useState(true);
|
||||||
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
|
const [message, setMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchCustomersAndBalances = async () => {
|
||||||
|
if (!user) return;
|
||||||
|
try {
|
||||||
|
const [
|
||||||
|
{ data: customersData },
|
||||||
|
{ data: creditsData },
|
||||||
|
{ data: repaymentsData },
|
||||||
|
] = await Promise.all([
|
||||||
|
supabase
|
||||||
|
.from('credit_customers')
|
||||||
|
.select('id, name')
|
||||||
|
.eq('user_id', user.id),
|
||||||
|
supabase
|
||||||
|
.from('credits')
|
||||||
|
.select('customer_id, amount')
|
||||||
|
.eq('user_id', user.id),
|
||||||
|
supabase
|
||||||
|
.from('repayments')
|
||||||
|
.select('customer_id, amount')
|
||||||
|
.eq('user_id', user.id),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const customerBalances: CustomerWithBalance[] = (
|
||||||
|
customersData || []
|
||||||
|
).map((c) => {
|
||||||
|
const totalCredits = (creditsData || [])
|
||||||
|
.filter((cr) => cr.customer_id === c.id)
|
||||||
|
.reduce((sum, cr) => sum + Number(cr.amount), 0);
|
||||||
|
const totalRepayments = (repaymentsData || [])
|
||||||
|
.filter((r) => r.customer_id === c.id)
|
||||||
|
.reduce((sum, r) => sum + Number(r.amount), 0);
|
||||||
|
return {
|
||||||
|
id: c.id,
|
||||||
|
name: c.name,
|
||||||
|
balance: Math.max(0, totalCredits - totalRepayments),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filter for customers with an outstanding balance
|
||||||
|
const activeCustomers = customerBalances.filter((c) => c.balance > 0);
|
||||||
|
setCustomers(activeCustomers);
|
||||||
|
|
||||||
|
// If a customer was passed in but has no balance, we should handle it
|
||||||
|
if (
|
||||||
|
selectedCustomerId &&
|
||||||
|
!activeCustomers.find((c) => c.id === selectedCustomerId)
|
||||||
|
) {
|
||||||
|
setSelectedCustomerId('');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching customers for repayment:', err);
|
||||||
|
} finally {
|
||||||
|
setLoadingCustomers(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchCustomersAndBalances();
|
||||||
|
}, [user, selectedCustomerId]);
|
||||||
|
|
||||||
|
const selectedCustomer = useMemo(
|
||||||
|
() => customers.find((c) => c.id === selectedCustomerId),
|
||||||
|
[customers, selectedCustomerId]
|
||||||
|
);
|
||||||
|
|
||||||
|
const validate = () => {
|
||||||
|
const newErrors: Record<string, string> = {};
|
||||||
|
const parsedAmount = parseMoney(amount);
|
||||||
|
|
||||||
|
if (!selectedCustomerId) {
|
||||||
|
newErrors.customer = 'Please select a customer';
|
||||||
|
} else if (selectedCustomer && parsedAmount > selectedCustomer.balance) {
|
||||||
|
newErrors.amount = `Amount cannot exceed outstanding balance of ${formatMoney(
|
||||||
|
selectedCustomer.balance,
|
||||||
|
currency
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsedAmount <= 0) {
|
||||||
|
newErrors.amount = 'Amount must be greater than 0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!repaymentDate) {
|
||||||
|
newErrors.date = 'Date is required';
|
||||||
|
}
|
||||||
|
|
||||||
|
setErrors(newErrors);
|
||||||
|
return Object.keys(newErrors).length === 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
if (!validate() || !user) return;
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
setMessage(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { error } = await supabase.from('repayments').insert([
|
||||||
|
{
|
||||||
|
user_id: user.id,
|
||||||
|
customer_id: selectedCustomerId,
|
||||||
|
amount: parseMoney(amount),
|
||||||
|
repayment_date: repaymentDate,
|
||||||
|
note: note.trim() || null,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (error) throw error;
|
||||||
|
|
||||||
|
history.goBack();
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('Error saving repayment:', err);
|
||||||
|
setMessage(err.message || 'Could not save repayment');
|
||||||
|
setTimeout(() => setMessage(null), 4000);
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f0f4ff' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton color="dark" onClick={() => history.goBack()}>
|
||||||
|
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
<IonTitle className="bold">Record repayment</IonTitle>
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
|
||||||
|
<IonContent className="ion-padding" style={{ '--background': '#f0f4ff' }}>
|
||||||
|
{!loadingCustomers && customers.length === 0 ? (
|
||||||
|
<EmptyState
|
||||||
|
icon="wallet-outline"
|
||||||
|
title="No outstanding credit"
|
||||||
|
description="You don't have any customers with an outstanding balance right now."
|
||||||
|
actionText="Add Credit"
|
||||||
|
onAction={() => history.push('/credit/new')}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="form-card">
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Select Customer
|
||||||
|
</IonLabel>
|
||||||
|
<div className="input-wrapper">
|
||||||
|
<IonSelect
|
||||||
|
interface="action-sheet"
|
||||||
|
placeholder="Choose a customer"
|
||||||
|
value={selectedCustomerId}
|
||||||
|
onIonChange={(e) => setSelectedCustomerId(e.detail.value)}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
disabled={loadingCustomers}
|
||||||
|
>
|
||||||
|
{customers.map((c) => (
|
||||||
|
<IonSelectOption key={c.id} value={c.id}>
|
||||||
|
{c.name} ({formatMoney(c.balance, currency)})
|
||||||
|
</IonSelectOption>
|
||||||
|
))}
|
||||||
|
</IonSelect>
|
||||||
|
</div>
|
||||||
|
{errors.customer && (
|
||||||
|
<IonLabel
|
||||||
|
color="danger"
|
||||||
|
style={{ fontSize: '12px', marginTop: '4px' }}
|
||||||
|
>
|
||||||
|
{errors.customer}
|
||||||
|
</IonLabel>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{selectedCustomer && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'rgba(99,102,241,0.10)',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '16px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="tertiary-text" style={{ fontSize: '10px' }}>
|
||||||
|
OUTSTANDING BALANCE
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className="bold tabular"
|
||||||
|
style={{
|
||||||
|
fontSize: '22px',
|
||||||
|
color: 'var(--ion-color-primary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{formatMoney(selectedCustomer.balance, currency)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<MoneyInput
|
||||||
|
label="Repayment amount"
|
||||||
|
value={amount}
|
||||||
|
onValueChange={(val) => {
|
||||||
|
setAmount(val);
|
||||||
|
if (errors.amount) setErrors({ ...errors, amount: '' });
|
||||||
|
}}
|
||||||
|
error={errors.amount}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Repayment date
|
||||||
|
</IonLabel>
|
||||||
|
<div className="input-wrapper">
|
||||||
|
<IonInput
|
||||||
|
type="date"
|
||||||
|
value={repaymentDate}
|
||||||
|
onIonChange={(e) => setRepaymentDate(e.detail.value!)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{errors.date && (
|
||||||
|
<IonLabel
|
||||||
|
color="danger"
|
||||||
|
style={{ fontSize: '12px', marginTop: '4px' }}
|
||||||
|
>
|
||||||
|
{errors.date}
|
||||||
|
</IonLabel>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Note (optional)
|
||||||
|
</IonLabel>
|
||||||
|
<div
|
||||||
|
className="input-wrapper"
|
||||||
|
style={{ minHeight: '96px', padding: '8px 16px' }}
|
||||||
|
>
|
||||||
|
<IonTextarea
|
||||||
|
placeholder="e.g. Paid in full"
|
||||||
|
value={note}
|
||||||
|
onIonChange={(e) => setNote(e.detail.value!)}
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{message && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'var(--color-danger-soft)',
|
||||||
|
color: 'var(--ion-color-danger-shade)',
|
||||||
|
padding: '12px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{message}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<IonButton
|
||||||
|
expand="block"
|
||||||
|
className="bold"
|
||||||
|
style={{
|
||||||
|
height: '52px',
|
||||||
|
'--border-radius': 'var(--radius-pill)',
|
||||||
|
marginTop: '16px',
|
||||||
|
}}
|
||||||
|
disabled={submitting || loadingCustomers}
|
||||||
|
onClick={handleSave}
|
||||||
|
>
|
||||||
|
{submitting ? <IonSpinner name="crescent" /> : 'Save repayment'}
|
||||||
|
</IonButton>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RepaymentFormPage;
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import {
|
||||||
|
IonContent,
|
||||||
|
IonPage,
|
||||||
|
IonHeader,
|
||||||
|
IonToolbar,
|
||||||
|
IonTitle,
|
||||||
|
IonButtons,
|
||||||
|
IonButton,
|
||||||
|
IonIcon,
|
||||||
|
IonInput,
|
||||||
|
IonTextarea,
|
||||||
|
IonSpinner,
|
||||||
|
IonLabel,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { chevronBackOutline } from 'ionicons/icons';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { getTodayISO } from '../utils/dates';
|
||||||
|
import MoneyInput from '../components/MoneyInput';
|
||||||
|
import { parseMoney } from '../utils/money';
|
||||||
|
|
||||||
|
const SaleFormPage: React.FC = () => {
|
||||||
|
const history = useHistory();
|
||||||
|
const { user } = useAuth();
|
||||||
|
|
||||||
|
const [amount, setAmount] = useState('');
|
||||||
|
const [saleDate, setSaleDate] = useState(getTodayISO());
|
||||||
|
const [note, setNote] = useState('');
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
|
const [message, setMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const validate = () => {
|
||||||
|
const newErrors: Record<string, string> = {};
|
||||||
|
const parsedAmount = parseMoney(amount);
|
||||||
|
|
||||||
|
if (parsedAmount <= 0) {
|
||||||
|
newErrors.amount = 'Amount must be greater than 0';
|
||||||
|
}
|
||||||
|
if (!saleDate) {
|
||||||
|
newErrors.date = 'Date is required';
|
||||||
|
}
|
||||||
|
|
||||||
|
setErrors(newErrors);
|
||||||
|
return Object.keys(newErrors).length === 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
if (!validate() || !user) return;
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
setMessage(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { error } = await supabase.from('sales').insert([
|
||||||
|
{
|
||||||
|
user_id: user.id,
|
||||||
|
amount: parseMoney(amount),
|
||||||
|
sale_date: saleDate,
|
||||||
|
note: note.trim() || null,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (error) throw error;
|
||||||
|
|
||||||
|
history.goBack();
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('Error saving sale:', err);
|
||||||
|
setMessage(err.message || 'Could not save sale');
|
||||||
|
setTimeout(() => setMessage(null), 4000);
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f0f4ff' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton color="dark" onClick={() => history.goBack()}>
|
||||||
|
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
<IonTitle className="bold">Add sale</IonTitle>
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
|
||||||
|
<IonContent className="ion-padding" style={{ '--background': '#f0f4ff' }}>
|
||||||
|
<div className="form-card">
|
||||||
|
<MoneyInput
|
||||||
|
label="Sale amount"
|
||||||
|
value={amount}
|
||||||
|
onValueChange={(val) => {
|
||||||
|
setAmount(val);
|
||||||
|
if (errors.amount) setErrors({ ...errors, amount: '' });
|
||||||
|
}}
|
||||||
|
error={errors.amount}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Sale date
|
||||||
|
</IonLabel>
|
||||||
|
<div className="input-wrapper">
|
||||||
|
<IonInput
|
||||||
|
type="date"
|
||||||
|
value={saleDate}
|
||||||
|
onIonChange={(e) => setSaleDate(e.detail.value!)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{errors.date && (
|
||||||
|
<IonLabel
|
||||||
|
color="danger"
|
||||||
|
style={{ fontSize: '12px', marginTop: '4px' }}
|
||||||
|
>
|
||||||
|
{errors.date}
|
||||||
|
</IonLabel>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="form-field">
|
||||||
|
<IonLabel
|
||||||
|
className="semibold"
|
||||||
|
style={{
|
||||||
|
marginBottom: '8px',
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Note (optional)
|
||||||
|
</IonLabel>
|
||||||
|
<div
|
||||||
|
className="input-wrapper"
|
||||||
|
style={{ minHeight: '96px', padding: '8px 16px' }}
|
||||||
|
>
|
||||||
|
<IonTextarea
|
||||||
|
placeholder="e.g. Morning rush items"
|
||||||
|
value={note}
|
||||||
|
onIonChange={(e) => setNote(e.detail.value!)}
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{message && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'var(--color-danger-soft)',
|
||||||
|
color: 'var(--ion-color-danger-shade)',
|
||||||
|
padding: '12px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{message}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<IonButton
|
||||||
|
expand="block"
|
||||||
|
className="bold"
|
||||||
|
style={{
|
||||||
|
height: '52px',
|
||||||
|
'--border-radius': 'var(--radius-pill)',
|
||||||
|
marginTop: '16px',
|
||||||
|
}}
|
||||||
|
disabled={submitting}
|
||||||
|
onClick={handleSave}
|
||||||
|
>
|
||||||
|
{submitting ? <IonSpinner name="crescent" /> : 'Save sale'}
|
||||||
|
</IonButton>
|
||||||
|
</div>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SaleFormPage;
|
||||||
@@ -1,99 +1,123 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
IonPage,
|
|
||||||
IonContent,
|
IonContent,
|
||||||
|
IonPage,
|
||||||
|
IonInput,
|
||||||
IonButton,
|
IonButton,
|
||||||
IonSpinner,
|
IonSpinner,
|
||||||
useIonViewWillEnter,
|
IonIcon,
|
||||||
|
IonText,
|
||||||
} from '@ionic/react';
|
} from '@ionic/react';
|
||||||
|
import { chevronBackOutline } from 'ionicons/icons';
|
||||||
import { useHistory, useLocation } from 'react-router-dom';
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
import { setStatusBarStyle, Style } from '../utils/statusBar';
|
|
||||||
import OtpInput from '../components/OtpInput';
|
interface LocationState {
|
||||||
|
email: string;
|
||||||
|
type?: 'signup' | 'recovery';
|
||||||
|
resent?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
const VerifyEmailPage: React.FC = () => {
|
const VerifyEmailPage: React.FC = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const location = useLocation<{
|
const location = useLocation<LocationState>();
|
||||||
email: string;
|
const email = location.state?.email || '';
|
||||||
type: 'signup' | 'recovery';
|
|
||||||
}>();
|
|
||||||
const [code, setCode] = useState('');
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [cooldown, setCooldown] = useState(60);
|
|
||||||
|
|
||||||
const email = location.state?.email;
|
|
||||||
const type = location.state?.type || 'signup';
|
const type = location.state?.type || 'signup';
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
const [digits, setDigits] = useState<string[]>(['', '', '', '', '', '']);
|
||||||
setStatusBarStyle(Style.Dark);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
if (!email) {
|
const [resending, setResending] = useState(false);
|
||||||
history.replace('/auth');
|
const [cooldown, setCooldown] = useState(location.state?.resent ? 60 : 0);
|
||||||
}
|
const [message, setMessage] = useState<string | null>(null);
|
||||||
});
|
const [messageType, setMessageType] = useState<'error' | 'success'>('error');
|
||||||
|
|
||||||
|
const inputRefs = useRef<HTMLIonInputElement[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (cooldown > 0) {
|
if (cooldown > 0) {
|
||||||
const timer = setTimeout(() => setCooldown(cooldown - 1), 1000);
|
const timer = setInterval(() => {
|
||||||
return () => clearTimeout(timer);
|
setCooldown((c) => c - 1);
|
||||||
|
}, 1000);
|
||||||
|
return () => clearInterval(timer);
|
||||||
}
|
}
|
||||||
}, [cooldown]);
|
}, [cooldown]);
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
const showMessage = (msg: string, type: 'error' | 'success' = 'error') => {
|
||||||
setError(msg);
|
setMessage(msg);
|
||||||
setTimeout(() => setError(null), 4000);
|
setMessageType(type);
|
||||||
|
setTimeout(() => setMessage(null), 4000);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDigitChange = (index: number, value: string) => {
|
||||||
|
const newDigits = [...digits];
|
||||||
|
// Only take the last character (for overwriting)
|
||||||
|
const val = value.slice(-1);
|
||||||
|
|
||||||
|
if (val && !/^\d+$/.test(val)) return;
|
||||||
|
|
||||||
|
newDigits[index] = val;
|
||||||
|
setDigits(newDigits);
|
||||||
|
|
||||||
|
if (val && index < 5) {
|
||||||
|
inputRefs.current[index + 1]?.setFocus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = (index: number, e: any) => {
|
||||||
|
if (e.key === 'Backspace' && !digits[index] && index > 0) {
|
||||||
|
inputRefs.current[index - 1]?.setFocus();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleVerify = async () => {
|
const handleVerify = async () => {
|
||||||
if (code.length !== 6) return;
|
const code = digits.join('');
|
||||||
setLoading(true);
|
if (code.length < 6) {
|
||||||
|
showMessage('Please enter the 6-digit code');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSubmitting(true);
|
||||||
|
setMessage(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let result;
|
const { data, error } = await supabase.auth.verifyOtp({
|
||||||
if (type === 'recovery') {
|
|
||||||
const params: any = {
|
|
||||||
email,
|
email,
|
||||||
token: code,
|
token: code,
|
||||||
type: 'recovery',
|
type: (type === 'recovery' ? 'recovery' : 'signup') as any,
|
||||||
};
|
|
||||||
result = await (supabase.auth as any).verifyOtp(params);
|
|
||||||
} else {
|
|
||||||
result = await supabase.auth.verifyOtp({
|
|
||||||
email,
|
|
||||||
token: code,
|
|
||||||
type: 'email',
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (result.error) throw result.error;
|
if (error) throw error;
|
||||||
|
|
||||||
if (type === 'recovery') {
|
if (type === 'recovery') {
|
||||||
history.push('/new-password', { email });
|
history.push('/new-password');
|
||||||
} else {
|
} else {
|
||||||
history.push('/onboarding/profile');
|
history.push('/home');
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showError(err.message);
|
showMessage(err.message || 'Invalid or expired code');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleResend = async () => {
|
const handleResend = async () => {
|
||||||
if (cooldown > 0) return;
|
if (cooldown > 0) return;
|
||||||
setLoading(true);
|
|
||||||
|
setResending(true);
|
||||||
try {
|
try {
|
||||||
const resendParams: any = {
|
const { error } = await supabase.auth.resend({
|
||||||
type: type === 'signup' ? 'email' : 'recovery',
|
type: (type === 'recovery' ? 'recovery' : 'signup') as any,
|
||||||
email,
|
email,
|
||||||
};
|
});
|
||||||
const { error } = await supabase.auth.resend(resendParams);
|
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
|
|
||||||
|
showMessage('A new code has been sent', 'success');
|
||||||
setCooldown(60);
|
setCooldown(60);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showError(err.message);
|
showMessage(err.message || 'Failed to resend code');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setResending(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,94 +126,145 @@ const VerifyEmailPage: React.FC = () => {
|
|||||||
<IonContent
|
<IonContent
|
||||||
fullscreen
|
fullscreen
|
||||||
style={{
|
style={{
|
||||||
'--background': 'var(--color-bg)',
|
'--background':
|
||||||
|
'linear-gradient(160deg, rgba(199,210,254,0.52) 0%, #f0f4ff 58%, #f8fafc 100%)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ padding: 'calc(var(--ion-safe-area-top) + 40px) 20px' }}>
|
<div className="auth-shell">
|
||||||
<div style={{ marginBottom: '32px' }}>
|
<IonButton
|
||||||
<h1
|
fill="clear"
|
||||||
|
color="dark"
|
||||||
|
onClick={() => history.push('/auth')}
|
||||||
style={{
|
style={{
|
||||||
fontSize: '28px',
|
position: 'absolute',
|
||||||
fontWeight: 800,
|
top: 'calc(var(--ion-safe-area-top, 0px) + 8px)',
|
||||||
color: 'var(--color-text-primary)',
|
left: '8px',
|
||||||
margin: '0 0 8px',
|
'--padding-start': '8px',
|
||||||
|
'--padding-end': '8px',
|
||||||
|
zIndex: 10,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Check your email
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
width: '44px',
|
||||||
|
height: '44px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon icon={chevronBackOutline} />
|
||||||
|
</div>
|
||||||
|
</IonButton>
|
||||||
|
|
||||||
|
<div style={{ marginTop: '80px' }}>
|
||||||
|
<h1
|
||||||
|
className="bold"
|
||||||
|
style={{ fontSize: '24px', margin: '0 0 8px 0' }}
|
||||||
|
>
|
||||||
|
Verify your email
|
||||||
</h1>
|
</h1>
|
||||||
<p
|
<p
|
||||||
style={{
|
className="secondary-text"
|
||||||
fontSize: '15px',
|
style={{ margin: '0', fontSize: '14px' }}
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
margin: 0,
|
|
||||||
lineHeight: 1.5,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
We've sent a 6-digit verification code to{' '}
|
We've sent a 6-digit code to <span className="bold">{email}</span>
|
||||||
<span
|
|
||||||
style={{ fontWeight: 600, color: 'var(--color-text-primary)' }}
|
|
||||||
>
|
|
||||||
{email}
|
|
||||||
</span>
|
|
||||||
.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="auth-card">
|
||||||
|
<div
|
||||||
|
style={{ display: 'flex', gap: '8px', justifyContent: 'center' }}
|
||||||
|
>
|
||||||
|
{digits.map((digit, i) => (
|
||||||
|
<div
|
||||||
|
key={i}
|
||||||
|
style={{
|
||||||
|
width: '44px',
|
||||||
|
height: '52px',
|
||||||
|
background: '#e8edf8',
|
||||||
|
borderRadius: '12px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonInput
|
||||||
|
ref={(el) => {
|
||||||
|
inputRefs.current[i] = el!;
|
||||||
|
}}
|
||||||
|
value={digit}
|
||||||
|
onIonInput={(e) => handleDigitChange(i, e.detail.value!)}
|
||||||
|
onKeyDown={(e) => handleKeyDown(i, e)}
|
||||||
|
type="text"
|
||||||
|
inputMode="numeric"
|
||||||
|
style={{
|
||||||
|
textAlign: 'center',
|
||||||
|
fontSize: '22px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#111827',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{message && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
background: 'var(--color-surface)',
|
background:
|
||||||
padding: '24px',
|
messageType === 'error'
|
||||||
borderRadius: 'var(--radius-card)',
|
? 'var(--color-danger-soft)'
|
||||||
|
: 'var(--color-success-soft)',
|
||||||
|
color:
|
||||||
|
messageType === 'error'
|
||||||
|
? 'var(--ion-color-danger-shade)'
|
||||||
|
: 'var(--ion-color-success-shade)',
|
||||||
|
padding: '12px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
fontSize: '13px',
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<OtpInput value={code} onChange={setCode} disabled={loading} />
|
{message}
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(220, 38, 38, 0.08)',
|
|
||||||
color: 'var(--ion-color-danger)',
|
|
||||||
padding: '12px',
|
|
||||||
borderRadius: 'var(--radius-control)',
|
|
||||||
fontSize: '13px',
|
|
||||||
marginBottom: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<IonButton
|
<IonButton
|
||||||
expand="block"
|
expand="block"
|
||||||
disabled={loading || code.length !== 6}
|
className="bold"
|
||||||
onClick={handleVerify}
|
|
||||||
style={{
|
style={{
|
||||||
|
height: '52px',
|
||||||
'--border-radius': 'var(--radius-pill)',
|
'--border-radius': 'var(--radius-pill)',
|
||||||
height: '48px',
|
marginTop: '16px',
|
||||||
}}
|
}}
|
||||||
|
disabled={submitting}
|
||||||
|
onClick={handleVerify}
|
||||||
>
|
>
|
||||||
{loading ? <IonSpinner name="crescent" /> : 'Verify'}
|
{submitting ? <IonSpinner name="crescent" /> : 'Verify code'}
|
||||||
</IonButton>
|
</IonButton>
|
||||||
|
|
||||||
<button
|
<div style={{ textAlign: 'center', marginTop: '8px' }}>
|
||||||
onClick={handleResend}
|
<IonText
|
||||||
disabled={loading || cooldown > 0}
|
color={cooldown > 0 ? 'medium' : 'primary'}
|
||||||
|
className="semibold"
|
||||||
style={{
|
style={{
|
||||||
background: 'none',
|
fontSize: '13px',
|
||||||
border: 'none',
|
|
||||||
color:
|
|
||||||
cooldown > 0
|
|
||||||
? 'var(--color-text-tertiary)'
|
|
||||||
: 'var(--ion-color-primary)',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: 600,
|
|
||||||
marginTop: '20px',
|
|
||||||
cursor: cooldown > 0 ? 'default' : 'pointer',
|
cursor: cooldown > 0 ? 'default' : 'pointer',
|
||||||
}}
|
}}
|
||||||
|
onClick={handleResend}
|
||||||
>
|
>
|
||||||
{cooldown > 0 ? `Resend code in ${cooldown}s` : 'Resend code'}
|
{resending ? (
|
||||||
</button>
|
<IonSpinner name="dots" />
|
||||||
|
) : cooldown > 0 ? (
|
||||||
|
`Resend in ${cooldown}s`
|
||||||
|
) : (
|
||||||
|
'Resend code'
|
||||||
|
)}
|
||||||
|
</IonText>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ import { createClient } from '@supabase/supabase-js';
|
|||||||
import type { Database } from './database.types';
|
import type { Database } from './database.types';
|
||||||
|
|
||||||
export const supabase = createClient<Database>(
|
export const supabase = createClient<Database>(
|
||||||
'https://yunudlmsairdxxlhfyci.supabase.co',
|
'https://sxdbfylkgcfmsatqipli.supabase.co',
|
||||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1bnVkbG1zYWlyZHh4bGhmeWNpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODExNDk2OTUsImV4cCI6MjA5NjcyNTY5NX0.WRYh_r5YuruaGrgfAR6Tg_CrSI1CPyYgpvrJQVTbyUE',
|
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InN4ZGJmeWxrZ2NmbXNhdHFpcGxpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODExMTI5NjcsImV4cCI6MjA5NjY4ODk2N30.8ZvpjRBskCIH3FFnOkWsxZCOwNMX5txinffgXMDinKI',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,205 +1,291 @@
|
|||||||
/* InSpot exact theme: high-contrast black/white with Tinder Pink accents */
|
/* ShopKeep — Custom Palette & Shared Styles */
|
||||||
:root {
|
:root {
|
||||||
--ion-color-primary: #fe3c72;
|
/** ShopKeep Brand Palette **/
|
||||||
--ion-color-primary-rgb: 254, 60, 114;
|
--ion-color-primary: #6366f1;
|
||||||
|
--ion-color-primary-rgb: 99, 102, 241;
|
||||||
--ion-color-primary-contrast: #ffffff;
|
--ion-color-primary-contrast: #ffffff;
|
||||||
--ion-color-primary-contrast-rgb: 255, 255, 255;
|
--ion-color-primary-contrast-rgb: 255, 255, 255;
|
||||||
--ion-color-primary-shade: #e03564;
|
--ion-color-primary-shade: #5759d4;
|
||||||
--ion-color-primary-tint: #fe507f;
|
--ion-color-primary-tint: #7375f2;
|
||||||
|
|
||||||
--ion-color-secondary: #ef4a75;
|
--ion-color-secondary: #818cf8;
|
||||||
--ion-color-secondary-rgb: 239, 74, 117;
|
--ion-color-secondary-rgb: 129, 140, 248;
|
||||||
--ion-color-secondary-contrast: #ffffff;
|
--ion-color-secondary-contrast: #ffffff;
|
||||||
--ion-color-secondary-contrast-rgb: 255, 255, 255;
|
--ion-color-secondary-contrast-rgb: 255, 255, 255;
|
||||||
--ion-color-secondary-shade: #d24167;
|
--ion-color-secondary-shade: #727bda;
|
||||||
--ion-color-secondary-tint: #f15c83;
|
--ion-color-secondary-tint: #8e98f9;
|
||||||
|
|
||||||
--ion-color-tertiary: #9e9e9e;
|
--ion-color-tertiary: #c7d2fe;
|
||||||
--ion-color-tertiary-rgb: 158, 158, 158;
|
--ion-color-tertiary-rgb: 199, 210, 254;
|
||||||
--ion-color-tertiary-contrast: #000000;
|
--ion-color-tertiary-contrast: #111827;
|
||||||
--ion-color-tertiary-contrast-rgb: 0, 0, 0;
|
--ion-color-tertiary-contrast-rgb: 17, 24, 39;
|
||||||
--ion-color-tertiary-shade: #8b8b8b;
|
--ion-color-tertiary-shade: #afb9e0;
|
||||||
--ion-color-tertiary-tint: #a8a8a8;
|
--ion-color-tertiary-tint: #cdd7fe;
|
||||||
|
|
||||||
--ion-color-success: #22c55e;
|
--ion-color-success: #3aa67a;
|
||||||
--ion-color-success-rgb: 34, 197, 94;
|
--ion-color-success-rgb: 58, 166, 122;
|
||||||
--ion-color-success-contrast: #ffffff;
|
--ion-color-success-contrast: #ffffff;
|
||||||
--ion-color-success-contrast-rgb: 255, 255, 255;
|
--ion-color-success-contrast-rgb: 255, 255, 255;
|
||||||
--ion-color-success-shade: #1eae53;
|
--ion-color-success-shade: #33926b;
|
||||||
--ion-color-success-tint: #38cb6e;
|
--ion-color-success-tint: #4eb088;
|
||||||
|
|
||||||
--ion-color-warning: #ffcc00;
|
--ion-color-danger: #cf6679;
|
||||||
--ion-color-warning-rgb: 255, 204, 0;
|
--ion-color-danger-rgb: 207, 102, 121;
|
||||||
--ion-color-warning-contrast: #000000;
|
|
||||||
--ion-color-warning-contrast-rgb: 0, 0, 0;
|
|
||||||
--ion-color-warning-shade: #e0b400;
|
|
||||||
--ion-color-warning-tint: #ffd11a;
|
|
||||||
|
|
||||||
--ion-color-danger: #ff4444;
|
|
||||||
--ion-color-danger-rgb: 255, 68, 68;
|
|
||||||
--ion-color-danger-contrast: #ffffff;
|
--ion-color-danger-contrast: #ffffff;
|
||||||
--ion-color-danger-contrast-rgb: 255, 255, 255;
|
--ion-color-danger-contrast-rgb: 255, 255, 255;
|
||||||
--ion-color-danger-shade: #e03c3c;
|
--ion-color-danger-shade: #b65a6a;
|
||||||
--ion-color-danger-tint: #ff5757;
|
--ion-color-danger-tint: #d57587;
|
||||||
|
|
||||||
--ion-color-dark: #000000;
|
--ion-color-light: #f3f5fb;
|
||||||
--ion-color-dark-rgb: 0, 0, 0;
|
--ion-color-light-rgb: 243, 245, 251;
|
||||||
--ion-color-dark-contrast: #ffffff;
|
--ion-color-light-contrast: #111827;
|
||||||
--ion-color-dark-contrast-rgb: 255, 255, 255;
|
--ion-color-light-contrast-rgb: 17, 24, 39;
|
||||||
--ion-color-dark-shade: #000000;
|
--ion-color-light-shade: #d6d8dd;
|
||||||
--ion-color-dark-tint: #1a1a1a;
|
--ion-color-light-tint: #f4f6fb;
|
||||||
|
|
||||||
--ion-color-medium: #9e9e9e;
|
/** App Custom Tokens **/
|
||||||
--ion-color-medium-rgb: 158, 158, 158;
|
--color-bg: #f0f4ff;
|
||||||
--ion-color-medium-contrast: #000000;
|
--color-surface: #ffffff;
|
||||||
--ion-color-medium-contrast-rgb: 0, 0, 0;
|
--color-surface-secondary: #e8edf8;
|
||||||
--ion-color-medium-shade: #8b8b8b;
|
--color-text-primary: #111827;
|
||||||
--ion-color-medium-tint: #a8a8a8;
|
--color-text-secondary: rgba(17, 24, 39, 0.6);
|
||||||
|
--color-text-tertiary: rgba(17, 24, 39, 0.38);
|
||||||
--ion-color-light: #ffffff;
|
--color-accent-soft: rgba(99, 102, 241, 0.18);
|
||||||
--ion-color-light-rgb: 255, 255, 255;
|
--color-success-soft: rgba(58, 166, 122, 0.12);
|
||||||
--ion-color-light-contrast: #424242;
|
--color-danger-soft: rgba(207, 102, 121, 0.12);
|
||||||
--ion-color-light-contrast-rgb: 66, 66, 66;
|
|
||||||
--ion-color-light-shade: #e0e0e0;
|
|
||||||
--ion-color-light-tint: #ffffff;
|
|
||||||
|
|
||||||
--color-bg: #000000;
|
|
||||||
--color-bg-light: #ffffff;
|
|
||||||
--color-surface: rgba(44, 53, 57, 0.5);
|
|
||||||
--color-surface-solid: #151a1d;
|
|
||||||
--color-surface-raised: rgba(44, 53, 57, 0.72);
|
|
||||||
--color-input: rgba(44, 53, 57, 0.5);
|
|
||||||
--color-border: #333333;
|
|
||||||
--color-text-primary: #ffffff;
|
|
||||||
--color-text-secondary: #aaaaaa;
|
|
||||||
--color-text-tertiary: #9e9e9e;
|
|
||||||
--color-inactive: #9e9e9e;
|
|
||||||
--color-light-text-primary: #424242;
|
|
||||||
--color-light-text-secondary: #555555;
|
|
||||||
--color-light-text-tertiary: #888888;
|
|
||||||
--color-light-card: #dcdcdc;
|
|
||||||
--color-alert: #ff4444;
|
|
||||||
--color-alert-light: #ff0000;
|
|
||||||
--color-accent-soft: rgba(254, 60, 114, 0.18);
|
|
||||||
--color-accent-softer: rgba(254, 60, 114, 0.1);
|
|
||||||
|
|
||||||
|
/** Radii **/
|
||||||
--radius-pill: 999px;
|
--radius-pill: 999px;
|
||||||
--radius-card: 20px;
|
--radius-card: 24px;
|
||||||
--radius-control: 10px;
|
--radius-inner: 12px;
|
||||||
--shadow-card: none;
|
|
||||||
|
/** Typography **/
|
||||||
|
--font-tabular: 'SF Mono', 'Roboto Mono', Menlo, monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background: #000000;
|
background: var(--color-bg);
|
||||||
color: #ffffff;
|
color: var(--color-text-primary);
|
||||||
font-family:
|
font-family:
|
||||||
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
|
-apple-system, BlinkMacSystemFont, 'Inter', Roboto, Helvetica, Arial,
|
||||||
sans-serif;
|
sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ion-color-primary {
|
/** Shared Auth Styles **/
|
||||||
--ion-color-base: var(--ion-color-primary);
|
.auth-shell {
|
||||||
--ion-color-base-rgb: var(--ion-color-primary-rgb);
|
display: flex;
|
||||||
--ion-color-contrast: var(--ion-color-primary-contrast);
|
flex-direction: column;
|
||||||
--ion-color-contrast-rgb: var(--ion-color-primary-contrast-rgb);
|
gap: 24px;
|
||||||
--ion-color-shade: var(--ion-color-primary-shade);
|
padding: calc(var(--ion-safe-area-top, 0px) + 18px) 20px
|
||||||
--ion-color-tint: var(--ion-color-primary-tint);
|
calc(var(--ion-safe-area-bottom, 0px) + 28px);
|
||||||
|
min-height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ion-color-secondary {
|
.auth-card {
|
||||||
--ion-color-base: var(--ion-color-secondary);
|
background: var(--color-surface);
|
||||||
--ion-color-base-rgb: var(--ion-color-secondary-rgb);
|
border-radius: var(--radius-card);
|
||||||
--ion-color-contrast: var(--ion-color-secondary-contrast);
|
padding: 24px;
|
||||||
--ion-color-contrast-rgb: var(--ion-color-secondary-contrast-rgb);
|
display: flex;
|
||||||
--ion-color-shade: var(--ion-color-secondary-shade);
|
flex-direction: column;
|
||||||
--ion-color-tint: var(--ion-color-secondary-tint);
|
gap: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-content {
|
/** Shared Form Styles **/
|
||||||
--background: #000000;
|
.form-card {
|
||||||
--color: #ffffff;
|
background: var(--color-surface);
|
||||||
|
border-radius: var(--radius-card);
|
||||||
|
padding: 20px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-field {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrapper {
|
||||||
|
background: var(--color-surface-secondary);
|
||||||
|
border-radius: var(--radius-inner);
|
||||||
|
padding: 0 16px;
|
||||||
|
min-height: 52px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrapper ion-input,
|
||||||
|
.input-wrapper ion-textarea,
|
||||||
|
.input-wrapper ion-select {
|
||||||
|
--padding-start: 0;
|
||||||
|
--padding-end: 0;
|
||||||
|
--placeholder-color: var(--color-text-tertiary);
|
||||||
|
--placeholder-opacity: 1;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.money-input-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Widget Styles **/
|
||||||
|
.widget-card {
|
||||||
|
background: var(--color-surface);
|
||||||
|
border-radius: var(--radius-card);
|
||||||
|
padding: 20px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-pair-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-pair-row .widget-card {
|
||||||
|
flex: 1;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skeleton-text {
|
||||||
|
animation: skeleton-loading 1s linear infinite alternate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes skeleton-loading {
|
||||||
|
0% {
|
||||||
|
background-color: var(--color-surface-secondary);
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
background-color: var(--color-surface-secondary);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Icon Containers **/
|
||||||
|
.icon-container {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: var(--radius-inner);
|
||||||
|
background: var(--color-accent-soft);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--ion-color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-container ion-icon {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tab Bar Styling **/
|
||||||
ion-tab-bar {
|
ion-tab-bar {
|
||||||
--background: #101014;
|
--background: var(--color-surface);
|
||||||
--border: none;
|
--border-width: 0;
|
||||||
height: calc(64px + var(--ion-safe-area-bottom));
|
height: calc(64px + var(--ion-safe-area-bottom));
|
||||||
padding-bottom: var(--ion-safe-area-bottom);
|
padding-bottom: var(--ion-safe-area-bottom);
|
||||||
box-shadow: none;
|
border-top-left-radius: var(--radius-card);
|
||||||
|
border-top-right-radius: var(--radius-card);
|
||||||
|
box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.04);
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-tab-button {
|
ion-tab-button {
|
||||||
--background: #101014;
|
--color: var(--color-text-tertiary);
|
||||||
--color: #9e9e9e;
|
--color-selected: var(--ion-color-primary);
|
||||||
--color-selected: #fe3c72;
|
}
|
||||||
|
|
||||||
|
ion-tab-button ion-label {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-tab-button ion-icon {
|
ion-tab-button ion-icon {
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-tab-button ion-label {
|
/** Generic Utilities **/
|
||||||
font-size: 10px;
|
.tabular {
|
||||||
|
font-family: var(--font-tabular);
|
||||||
|
}
|
||||||
|
|
||||||
|
.semibold {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin-top: 4px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-header ion-toolbar {
|
.bold {
|
||||||
--background: #000000;
|
|
||||||
--border-width: 0;
|
|
||||||
--color: #ffffff;
|
|
||||||
padding: 0 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
ion-header ion-title {
|
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
font-size: 17px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-item {
|
.tertiary-text {
|
||||||
--background: transparent;
|
color: var(--color-text-tertiary);
|
||||||
--border-color: #333333;
|
|
||||||
--color: #ffffff;
|
|
||||||
--highlight-color-focused: #fe3c72;
|
|
||||||
}
|
|
||||||
|
|
||||||
ion-list-header {
|
|
||||||
--color: #9e9e9e;
|
|
||||||
font-size: 11px;
|
|
||||||
font-weight: 700;
|
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
|
font-size: 11px;
|
||||||
letter-spacing: 0.05em;
|
letter-spacing: 0.05em;
|
||||||
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-modal {
|
.secondary-text {
|
||||||
--background: #1b181f;
|
color: var(--color-text-secondary);
|
||||||
--border-radius: 20px 20px 0 0;
|
font-size: 13px;
|
||||||
--color: #ffffff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-modal::part(content) {
|
.pill-toggle {
|
||||||
background: #1b181f;
|
background: var(--color-surface-secondary);
|
||||||
border-radius: 20px 20px 0 0;
|
border-radius: var(--radius-pill);
|
||||||
|
display: flex;
|
||||||
|
padding: 4px;
|
||||||
|
gap: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-searchbar {
|
.pill-toggle-btn {
|
||||||
--background: rgba(44, 53, 57, 0.5);
|
flex: 1;
|
||||||
--border-radius: 999px;
|
border-radius: var(--radius-pill);
|
||||||
--box-shadow: none;
|
height: 36px;
|
||||||
--color: #ffffff;
|
border: none;
|
||||||
--placeholder-color: #aaaaaa;
|
font-size: 13px;
|
||||||
--icon-color: #ffffff;
|
font-weight: 600;
|
||||||
--clear-button-color: #9e9e9e;
|
color: var(--color-text-secondary);
|
||||||
padding-left: 0;
|
background: transparent;
|
||||||
padding-right: 0;
|
transition: all 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-button {
|
.pill-toggle-btn.active {
|
||||||
--background: #fe3c72;
|
background: var(--ion-color-primary);
|
||||||
--background-activated: #ef4a75;
|
color: #ffffff;
|
||||||
--background-focused: #ef4a75;
|
}
|
||||||
--background-hover: #ef4a75;
|
|
||||||
--color: #ffffff;
|
/** Page Spacing **/
|
||||||
--box-shadow: none;
|
.page-padding {
|
||||||
text-transform: none;
|
padding: 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin: 24px 20px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-header h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-header .see-all {
|
||||||
|
color: var(--ion-color-primary);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Custom Searchbar **/
|
||||||
|
.custom-searchbar {
|
||||||
|
--padding-start: 0;
|
||||||
|
--padding-end: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/**
|
||||||
|
* Date utilities for ShopKeep.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns today's date in YYYY-MM-DD format (local time).
|
||||||
|
*/
|
||||||
|
export const getTodayISO = (): string => {
|
||||||
|
const now = new Date();
|
||||||
|
const year = now.getFullYear();
|
||||||
|
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(now.getDate()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a date string (YYYY-MM-DD) or ISO string for display.
|
||||||
|
*/
|
||||||
|
export const formatDisplayDate = (
|
||||||
|
dateStr: string,
|
||||||
|
options: Intl.DateTimeFormatOptions = {
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
}
|
||||||
|
): string => {
|
||||||
|
if (!dateStr) return '';
|
||||||
|
const date = new Date(dateStr);
|
||||||
|
if (isNaN(date.getTime())) return dateStr;
|
||||||
|
return new Intl.DateTimeFormat('en-US', options).format(date);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a relative date string (Today, Yesterday, or formatted date).
|
||||||
|
*/
|
||||||
|
export const formatRelativeDate = (dateStr: string): string => {
|
||||||
|
const today = getTodayISO();
|
||||||
|
const date = new Date(dateStr);
|
||||||
|
const dateISO = date.toISOString().split('T')[0];
|
||||||
|
|
||||||
|
if (dateISO === today) return 'Today';
|
||||||
|
|
||||||
|
const yesterday = new Date();
|
||||||
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
|
const yesterdayISO = yesterday.toISOString().split('T')[0];
|
||||||
|
|
||||||
|
if (dateISO === yesterdayISO) return 'Yesterday';
|
||||||
|
|
||||||
|
return formatDisplayDate(dateStr);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group items by date.
|
||||||
|
*/
|
||||||
|
export const groupItemsByDate = <T extends { date: string }>(
|
||||||
|
items: T[]
|
||||||
|
): { date: string; items: T[] }[] => {
|
||||||
|
const groups: Record<string, T[]> = {};
|
||||||
|
|
||||||
|
items.forEach((item) => {
|
||||||
|
if (!groups[item.date]) {
|
||||||
|
groups[item.date] = [];
|
||||||
|
}
|
||||||
|
groups[item.date].push(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Object.keys(groups)
|
||||||
|
.sort((a, b) => b.localeCompare(a)) // Sort by date descending
|
||||||
|
.map((date) => ({
|
||||||
|
date,
|
||||||
|
items: groups[date],
|
||||||
|
}));
|
||||||
|
};
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
export const formatAge = (birthDate: string | null) => {
|
|
||||||
if (!birthDate) return null;
|
|
||||||
const today = new Date();
|
|
||||||
const birth = new Date(birthDate);
|
|
||||||
let age = today.getFullYear() - birth.getFullYear();
|
|
||||||
const m = today.getMonth() - birth.getMonth();
|
|
||||||
if (m < 0 || (m === 0 && today.getDate() < birth.getDate())) {
|
|
||||||
age--;
|
|
||||||
}
|
|
||||||
return age;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const formatDistance = (meters: number | null) => {
|
|
||||||
if (meters === null) return null;
|
|
||||||
const miles = meters * 0.000621371;
|
|
||||||
if (miles < 0.1) return 'Very close';
|
|
||||||
return `${miles.toFixed(1)} mi`;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const formatCompactNumber = (num: number) => {
|
|
||||||
return Intl.NumberFormat('en-US', {
|
|
||||||
notation: 'compact',
|
|
||||||
maximumFractionDigits: 1,
|
|
||||||
}).format(num);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const formatDate = (date: string | null) => {
|
|
||||||
if (!date) return null;
|
|
||||||
return new Date(date).toLocaleDateString('en-US', {
|
|
||||||
weekday: 'short',
|
|
||||||
day: 'numeric',
|
|
||||||
month: 'short',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const formatTime = (date: string | null) => {
|
|
||||||
if (!date) return null;
|
|
||||||
const d = new Date(date);
|
|
||||||
const now = new Date();
|
|
||||||
const diff = now.getTime() - d.getTime();
|
|
||||||
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
|
||||||
|
|
||||||
if (days === 0) {
|
|
||||||
return d.toLocaleTimeString('en-US', {
|
|
||||||
hour: 'numeric',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12: true,
|
|
||||||
});
|
|
||||||
} else if (days === 1) {
|
|
||||||
return 'Yesterday';
|
|
||||||
} else if (days < 7) {
|
|
||||||
return d.toLocaleDateString('en-US', { weekday: 'short' });
|
|
||||||
} else {
|
|
||||||
return d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const formatCurrency = (amount: number, currency = 'USD') => {
|
|
||||||
return new Intl.NumberFormat('en-US', {
|
|
||||||
style: 'currency',
|
|
||||||
currency,
|
|
||||||
}).format(amount);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* Money utilities for sanitizing, parsing, and formatting currency values.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitizes input string to allow only digits and one decimal point.
|
||||||
|
*/
|
||||||
|
export const sanitizeMoneyInput = (value: string): string => {
|
||||||
|
// Remove anything that isn't a digit or a period
|
||||||
|
let sanitized = value.replace(/[^0-9.]/g, '');
|
||||||
|
|
||||||
|
// Ensure only one period exists
|
||||||
|
const parts = sanitized.split('.');
|
||||||
|
if (parts.length > 2) {
|
||||||
|
sanitized = parts[0] + '.' + parts.slice(1).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit to 2 decimal places
|
||||||
|
if (parts.length === 2 && parts[1].length > 2) {
|
||||||
|
sanitized = parts[0] + '.' + parts[1].slice(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sanitized;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a sanitized string into a number.
|
||||||
|
*/
|
||||||
|
export const parseMoney = (value: string): number => {
|
||||||
|
const parsed = parseFloat(value);
|
||||||
|
return isNaN(parsed) ? 0 : parsed;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a number as currency.
|
||||||
|
*/
|
||||||
|
export const formatMoney = (
|
||||||
|
amount: number,
|
||||||
|
currency: string = 'USD',
|
||||||
|
locale: string = 'en-US'
|
||||||
|
): string => {
|
||||||
|
return new Intl.NumberFormat(locale, {
|
||||||
|
style: 'currency',
|
||||||
|
currency: currency,
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
}).format(amount);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the currency symbol for a given currency code.
|
||||||
|
*/
|
||||||
|
export const getCurrencySymbol = (
|
||||||
|
currency: string = 'USD',
|
||||||
|
locale: string = 'en-US'
|
||||||
|
): string => {
|
||||||
|
return (
|
||||||
|
new Intl.NumberFormat(locale, {
|
||||||
|
style: 'currency',
|
||||||
|
currency: currency,
|
||||||
|
})
|
||||||
|
.formatToParts(0)
|
||||||
|
.find((part) => part.type === 'currency')?.value || '$'
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
import { PushNotifications } from '@capacitor/push-notifications';
|
|
||||||
import type {
|
|
||||||
ActionPerformed,
|
|
||||||
PushNotificationSchema,
|
|
||||||
} from '@capacitor/push-notifications';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
|
|
||||||
export async function setupPushNotifications(userId: string, history: any) {
|
|
||||||
const handleNotificationTap = (notification: PushNotificationSchema) => {
|
|
||||||
if (notification.data?.deep_link) {
|
|
||||||
history.push(notification.data.deep_link);
|
|
||||||
} else if (notification.data?.type === 'message') {
|
|
||||||
history.push(`/chat/${notification.data.conversation_id}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const launch = await (PushNotifications as any).getLaunchNotification();
|
|
||||||
if (launch) handleNotificationTap(launch.notification);
|
|
||||||
|
|
||||||
const status = await PushNotifications.checkPermissions();
|
|
||||||
|
|
||||||
if (status.receive === 'granted') {
|
|
||||||
await PushNotifications.register();
|
|
||||||
} else if (status.receive === 'prompt') {
|
|
||||||
const result = await PushNotifications.requestPermissions();
|
|
||||||
if (result.receive === 'granted') await PushNotifications.register();
|
|
||||||
}
|
|
||||||
|
|
||||||
PushNotifications.addListener('registration', async (token) => {
|
|
||||||
await supabase
|
|
||||||
.from('profiles')
|
|
||||||
.update({ fcm_token: token.value })
|
|
||||||
.eq('id', userId);
|
|
||||||
});
|
|
||||||
|
|
||||||
PushNotifications.addListener('registrationError', (err) => {
|
|
||||||
console.error('Push registration error', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
PushNotifications.addListener(
|
|
||||||
'pushNotificationReceived',
|
|
||||||
async (notification: PushNotificationSchema) => {
|
|
||||||
console.log('Push received', notification);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
PushNotifications.addListener(
|
|
||||||
'pushNotificationActionPerformed',
|
|
||||||
(action: ActionPerformed) => {
|
|
||||||
handleNotificationTap(action.notification);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
await PushNotifications.removeAllDeliveredNotifications();
|
|
||||||
}
|
|
||||||