Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 52125c20dc |
@@ -4,10 +4,10 @@ android {
|
|||||||
namespace = "io.ionic.starter"
|
namespace = "io.ionic.starter"
|
||||||
compileSdk = rootProject.ext.compileSdkVersion
|
compileSdk = rootProject.ext.compileSdkVersion
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.qoutelink.app"
|
applicationId "com.afmeaglesnzw.app"
|
||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 3
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
manifestPlaceholders = [googleMapsApiKey: System.getenv("VITE_GOOGLE_MAPS_KEY") ?: ""]
|
manifestPlaceholders = [googleMapsApiKey: System.getenv("VITE_GOOGLE_MAPS_KEY") ?: ""]
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<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.qoutelink.app" />
|
<data android:scheme="com.afmeaglesnzw.app" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 9.0 KiB |
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 146 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 108 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 16 KiB |
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<color name="splashBackground">#FFFFFF</color>
|
|
||||||
</resources>
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Qoutelink</string>
|
<string name="app_name">AFM.EAGLESNZW</string>
|
||||||
<string name="title_activity_main">Qoutelink</string>
|
<string name="title_activity_main">AFM.EAGLESNZW</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>
|
||||||
|
|||||||
@@ -16,9 +16,7 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
|
<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
|
||||||
<item name="windowSplashScreenBackground">@color/splashBackground</item>
|
<item name="android:background">@drawable/splash</item>
|
||||||
<item name="windowSplashScreenAnimatedIcon">@drawable/splash_logo</item>
|
|
||||||
<item name="postSplashScreenTheme">@style/AppTheme.NoActionBar</item>
|
|
||||||
</style>
|
</style>
|
||||||
</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.qoutelink.app',
|
appId: 'com.afmeaglesnzw.app',
|
||||||
appName: 'Qoutelink',
|
appName: 'AFM.EAGLESNZW',
|
||||||
webDir: 'dist',
|
webDir: 'dist',
|
||||||
plugins: {
|
plugins: {
|
||||||
FirebaseAuthentication: {
|
FirebaseAuthentication: {
|
||||||
|
|||||||
@@ -299,7 +299,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
|
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 3;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
INFOPLIST_FILE = App/Info.plist;
|
INFOPLIST_FILE = App/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
@@ -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.qoutelink.app;
|
PRODUCT_BUNDLE_IDENTIFIER = com.afmeaglesnzw.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;
|
||||||
@@ -322,7 +322,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
|
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 3;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
INFOPLIST_FILE = App/Info.plist;
|
INFOPLIST_FILE = App/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
@@ -330,7 +330,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.qoutelink.app;
|
PRODUCT_BUNDLE_IDENTIFIER = com.afmeaglesnzw.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,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: 890 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 809 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 8.8 KiB |
@@ -1,13 +1,23 @@
|
|||||||
{
|
{
|
||||||
"images": [
|
"images" : [
|
||||||
{
|
{
|
||||||
"idiom": "universal",
|
"idiom" : "universal",
|
||||||
"filename": "splash.png",
|
"filename" : "splash-2732x2732-2.png",
|
||||||
"scale": "1x"
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"filename" : "splash-2732x2732-1.png",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"filename" : "splash-2732x2732.png",
|
||||||
|
"scale" : "3x"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"info": {
|
"info" : {
|
||||||
"author": "appsuite",
|
"version" : 1,
|
||||||
"version": 1
|
"author" : "xcode"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 480 KiB |
@@ -7,7 +7,7 @@
|
|||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>en</string>
|
<string>en</string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>Qoutelink</string>
|
<string>AFM.EAGLESNZW</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
@@ -47,20 +47,20 @@
|
|||||||
</array>
|
</array>
|
||||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSPhotoLibraryUsageDescription</key>
|
|
||||||
<string>We need access to your photo library so you can attach site photos and references to your requests.</string>
|
|
||||||
<key>NSCameraUsageDescription</key>
|
|
||||||
<string>We need access to your camera so you can take site photos for your requests.</string>
|
|
||||||
<key>CFBundleURLTypes</key>
|
<key>CFBundleURLTypes</key>
|
||||||
<array>
|
<array>
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleURLName</key>
|
<key>CFBundleURLName</key>
|
||||||
<string>com.qoutelink.app</string>
|
<string>com.afmeaglesnzw.app</string>
|
||||||
<key>CFBundleURLSchemes</key>
|
<key>CFBundleURLSchemes</key>
|
||||||
<array>
|
<array>
|
||||||
<string>com.qoutelink.app</string>
|
<string>com.afmeaglesnzw.app</string>
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
|
<string>This app needs access to your photo library.</string>
|
||||||
|
<key>NSCameraUsageDescription</key>
|
||||||
|
<string>This app needs camera access.</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -1,11 +1,22 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { IonApp } from '@ionic/react';
|
import { Redirect, Route } from 'react-router-dom';
|
||||||
|
import {
|
||||||
|
IonApp,
|
||||||
|
IonIcon,
|
||||||
|
IonLabel,
|
||||||
|
IonRouterOutlet,
|
||||||
|
IonTabBar,
|
||||||
|
IonTabButton,
|
||||||
|
IonTabs,
|
||||||
|
setupIonicReact,
|
||||||
|
} from '@ionic/react';
|
||||||
import { IonReactRouter } from '@ionic/react-router';
|
import { IonReactRouter } from '@ionic/react-router';
|
||||||
|
import {
|
||||||
import { AuthProvider } from './contexts/AuthContext';
|
homeOutline,
|
||||||
import { ProfileProvider, useProfile } from './contexts/ProfileContext';
|
calendarOutline,
|
||||||
import AppRoutes from './AppRoutes';
|
personOutline,
|
||||||
import { setStatusBarStyle, Style } from './utils/statusBar';
|
newspaperOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
|
||||||
/* 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';
|
||||||
@@ -26,28 +37,127 @@ import '@ionic/react/css/display.css';
|
|||||||
/* Theme variables */
|
/* Theme variables */
|
||||||
import './theme/variables.css';
|
import './theme/variables.css';
|
||||||
|
|
||||||
const AppShell: React.FC = () => {
|
import { AuthProvider, useAuth } from './contexts/AuthContext';
|
||||||
const { themeMode } = useProfile();
|
import ProtectedRoute from './components/ProtectedRoute';
|
||||||
|
|
||||||
useEffect(() => {
|
import Auth from './pages/Auth';
|
||||||
document.body.classList.toggle('dark', themeMode === 'dark');
|
import VerifyEmail from './pages/VerifyEmail';
|
||||||
setStatusBarStyle(themeMode === 'dark' ? Style.Dark : Style.Light);
|
import SetupProfile from './pages/SetupProfile';
|
||||||
}, [themeMode]);
|
import Home from './pages/Home';
|
||||||
|
import Events from './pages/Events';
|
||||||
|
import Profile from './pages/Profile';
|
||||||
|
import EventDetail from './pages/EventDetail';
|
||||||
|
import AdminEventForm from './pages/AdminEventForm';
|
||||||
|
import News from './pages/News';
|
||||||
|
import NewsDetail from './pages/NewsDetail';
|
||||||
|
import AdminNewsForm from './pages/AdminNewsForm';
|
||||||
|
|
||||||
return (
|
import { setStatusBarStyle, Style } from './utils/statusBar';
|
||||||
<IonReactRouter>
|
|
||||||
<AppRoutes />
|
setupIonicReact();
|
||||||
</IonReactRouter>
|
|
||||||
);
|
const SetupProfileRoute: React.FC = () => {
|
||||||
|
const { user } = useAuth();
|
||||||
|
if (!user) return <Redirect to="/auth" />;
|
||||||
|
return <SetupProfile />;
|
||||||
};
|
};
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
|
useEffect(() => {
|
||||||
|
setStatusBarStyle(Style.Dark);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IonApp>
|
<IonApp>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<ProfileProvider>
|
<IonReactRouter>
|
||||||
<AppShell />
|
<IonRouterOutlet>
|
||||||
</ProfileProvider>
|
{/* Unprotected Routes */}
|
||||||
|
<Route path="/auth" component={Auth} exact />
|
||||||
|
<Route path="/verify-email" component={VerifyEmail} exact />
|
||||||
|
|
||||||
|
{/* Profile Setup (requires user, but no profile yet) */}
|
||||||
|
<Route path="/setup-profile" component={SetupProfileRoute} exact />
|
||||||
|
|
||||||
|
{/* Non-tab Protected Routes */}
|
||||||
|
<ProtectedRoute
|
||||||
|
path="/event/:id([0-9a-fA-F-]{36})"
|
||||||
|
component={EventDetail}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
<ProtectedRoute
|
||||||
|
path="/admin/events/new"
|
||||||
|
component={AdminEventForm}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
<ProtectedRoute
|
||||||
|
path="/admin/events/:id([0-9a-fA-F-]{36})/edit"
|
||||||
|
component={AdminEventForm}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
<ProtectedRoute
|
||||||
|
path="/news/:id([0-9a-fA-F-]{36})"
|
||||||
|
component={NewsDetail}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
<ProtectedRoute
|
||||||
|
path="/admin/news/new"
|
||||||
|
component={AdminNewsForm}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
<ProtectedRoute
|
||||||
|
path="/admin/news/:id([0-9a-fA-F-]{36})"
|
||||||
|
component={AdminNewsForm}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Tabs */}
|
||||||
|
<ProtectedRoute
|
||||||
|
path={['/home', '/events', '/news', '/profile']}
|
||||||
|
component={() => (
|
||||||
|
<IonTabs>
|
||||||
|
<IonRouterOutlet>
|
||||||
|
<Route path="/home" component={Home} exact />
|
||||||
|
<Route path="/events" component={Events} exact />
|
||||||
|
<Route path="/news" component={News} exact />
|
||||||
|
<Route path="/profile" component={Profile} exact />
|
||||||
|
</IonRouterOutlet>
|
||||||
|
<IonTabBar
|
||||||
|
slot="bottom"
|
||||||
|
style={{
|
||||||
|
'--background': 'var(--color-surface)',
|
||||||
|
'--border': 'none',
|
||||||
|
color: 'var(--color-text-secondary)',
|
||||||
|
boxShadow: '0 -2px 10px rgba(47,34,29,0.05)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonTabButton tab="home" href="/home">
|
||||||
|
<IonIcon icon={homeOutline} />
|
||||||
|
<IonLabel>Home</IonLabel>
|
||||||
|
</IonTabButton>
|
||||||
|
<IonTabButton tab="events" href="/events">
|
||||||
|
<IonIcon icon={calendarOutline} />
|
||||||
|
<IonLabel>Events</IonLabel>
|
||||||
|
</IonTabButton>
|
||||||
|
<IonTabButton tab="news" href="/news">
|
||||||
|
<IonIcon icon={newspaperOutline} />
|
||||||
|
<IonLabel>News</IonLabel>
|
||||||
|
</IonTabButton>
|
||||||
|
<IonTabButton tab="profile" href="/profile">
|
||||||
|
<IonIcon icon={personOutline} />
|
||||||
|
<IonLabel>Profile</IonLabel>
|
||||||
|
</IonTabButton>
|
||||||
|
</IonTabBar>
|
||||||
|
</IonTabs>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Root Redirect */}
|
||||||
|
<Route exact path="/">
|
||||||
|
<Redirect to="/auth" />
|
||||||
|
</Route>
|
||||||
|
</IonRouterOutlet>
|
||||||
|
</IonReactRouter>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
</IonApp>
|
</IonApp>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Route, Redirect } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
IonRouterOutlet,
|
|
||||||
IonTabs,
|
|
||||||
IonTabBar,
|
|
||||||
IonTabButton,
|
|
||||||
IonIcon,
|
|
||||||
IonLabel,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
homeOutline,
|
|
||||||
documentTextOutline,
|
|
||||||
personOutline,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { useAuth } from './contexts/AuthContext';
|
|
||||||
|
|
||||||
import Auth from './pages/Auth';
|
|
||||||
import VerifyEmail from './pages/VerifyEmail';
|
|
||||||
import ForgotPassword from './pages/ForgotPassword';
|
|
||||||
import VerifyReset from './pages/VerifyReset';
|
|
||||||
import SetupProfile from './pages/SetupProfile';
|
|
||||||
import Home from './pages/Home';
|
|
||||||
import BuyerRequests from './pages/BuyerRequests';
|
|
||||||
import NewRfq from './pages/NewRfq';
|
|
||||||
import RfqDetail from './pages/RfqDetail';
|
|
||||||
import SupplierQuoteForm from './pages/SupplierQuoteForm';
|
|
||||||
import BuyerQuoteList from './pages/BuyerQuoteList';
|
|
||||||
import Profile from './pages/Profile';
|
|
||||||
import EditProfile from './pages/EditProfile';
|
|
||||||
import ProtectedRoute from './components/ProtectedRoute';
|
|
||||||
|
|
||||||
const AppRoutes: React.FC = () => {
|
|
||||||
const { user } = useAuth();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonRouterOutlet>
|
|
||||||
{/* Auth routes */}
|
|
||||||
<Route path="/auth" component={Auth} exact />
|
|
||||||
<Route path="/verify-email" component={VerifyEmail} exact />
|
|
||||||
<Route path="/forgot-password" component={ForgotPassword} exact />
|
|
||||||
<Route path="/verify-reset" component={VerifyReset} exact />
|
|
||||||
|
|
||||||
{/* Setup Profile (guarded manually by user presence, not ProtectedRoute to avoid loop) */}
|
|
||||||
<Route
|
|
||||||
path="/setup-profile"
|
|
||||||
exact
|
|
||||||
render={() => (!user ? <Redirect to="/auth" /> : <SetupProfile />)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Pushed routes without tab bar */}
|
|
||||||
<ProtectedRoute path="/rfq/new" component={NewRfq} exact />
|
|
||||||
<ProtectedRoute
|
|
||||||
path="/rfq/:id([0-9a-fA-F-]{36})"
|
|
||||||
component={RfqDetail}
|
|
||||||
exact
|
|
||||||
/>
|
|
||||||
<ProtectedRoute
|
|
||||||
path="/quote/:id([0-9a-fA-F-]{36})"
|
|
||||||
component={SupplierQuoteForm}
|
|
||||||
exact
|
|
||||||
/>
|
|
||||||
<ProtectedRoute
|
|
||||||
path="/quote-list/:id([0-9a-fA-F-]{36})"
|
|
||||||
component={BuyerQuoteList}
|
|
||||||
exact
|
|
||||||
/>
|
|
||||||
<ProtectedRoute path="/profile/edit" component={EditProfile} exact />
|
|
||||||
|
|
||||||
{/* Tabs */}
|
|
||||||
<ProtectedRoute
|
|
||||||
path={['/home', '/requests', '/profile']}
|
|
||||||
component={() => (
|
|
||||||
<IonTabs>
|
|
||||||
<IonRouterOutlet>
|
|
||||||
<Route path="/home" component={Home} exact />
|
|
||||||
<Route path="/requests" component={BuyerRequests} exact />
|
|
||||||
<Route path="/profile" component={Profile} exact />
|
|
||||||
</IonRouterOutlet>
|
|
||||||
|
|
||||||
<IonTabBar slot="bottom">
|
|
||||||
<IonTabButton tab="home" href="/home">
|
|
||||||
<IonIcon icon={homeOutline} />
|
|
||||||
<IonLabel>Home</IonLabel>
|
|
||||||
</IonTabButton>
|
|
||||||
<IonTabButton tab="requests" href="/requests">
|
|
||||||
<IonIcon icon={documentTextOutline} />
|
|
||||||
<IonLabel>Requests</IonLabel>
|
|
||||||
</IonTabButton>
|
|
||||||
<IonTabButton tab="profile" href="/profile">
|
|
||||||
<IonIcon icon={personOutline} />
|
|
||||||
<IonLabel>Profile</IonLabel>
|
|
||||||
</IonTabButton>
|
|
||||||
</IonTabBar>
|
|
||||||
</IonTabs>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Default Redirect */}
|
|
||||||
<Route exact path="/" render={() => <Redirect to="/home" />} />
|
|
||||||
</IonRouterOutlet>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AppRoutes;
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { IonIcon } from '@ionic/react';
|
|
||||||
|
|
||||||
interface DashboardMetricCardProps {
|
|
||||||
label: string;
|
|
||||||
value: string;
|
|
||||||
hint: string;
|
|
||||||
icon: string;
|
|
||||||
onClick?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const DashboardMetricCard: React.FC<DashboardMetricCardProps> = ({
|
|
||||||
label,
|
|
||||||
value,
|
|
||||||
hint,
|
|
||||||
icon,
|
|
||||||
onClick,
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
onClick={onClick}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
flex: '1',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '12px',
|
|
||||||
cursor: onClick ? 'pointer' : 'default',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'flex-start',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
textTransform: 'uppercase',
|
|
||||||
letterSpacing: '0.05em',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '36px',
|
|
||||||
height: '36px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
background: 'var(--color-brand-medium)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={icon}
|
|
||||||
style={{ color: 'var(--color-brand)', fontSize: '18px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '28px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
lineHeight: '1',
|
|
||||||
fontVariantNumeric: 'tabular-nums',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{value}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
marginTop: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{hint}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DashboardMetricCard;
|
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { ChurchEvent } from '../types';
|
||||||
|
|
||||||
|
interface EventListCardProps {
|
||||||
|
event: ChurchEvent;
|
||||||
|
onClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EventListCard: React.FC<EventListCardProps> = ({ event, onClick }) => {
|
||||||
|
const categoryName = event.event_categories?.name || 'Event';
|
||||||
|
const date = new Date(event.start_at);
|
||||||
|
const hasTime = date.getHours() !== 0 || date.getMinutes() !== 0;
|
||||||
|
|
||||||
|
const startTime = hasTime
|
||||||
|
? date.toLocaleTimeString([], {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
})
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const dateStr = date.toLocaleDateString(undefined, {
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
onClick={onClick}
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '18px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '12px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'var(--color-brand-soft)',
|
||||||
|
color: 'var(--color-brand)',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '4px 10px',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{dateStr}
|
||||||
|
{startTime ? ` • ${startTime}` : ''}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '500',
|
||||||
|
color: 'var(--color-text-secondary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{categoryName}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3
|
||||||
|
style={{
|
||||||
|
margin: '0 0 4px 0',
|
||||||
|
fontSize: '16px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{event.title}
|
||||||
|
</h3>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '13px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: 'var(--color-text-secondary)',
|
||||||
|
display: '-webkit-box',
|
||||||
|
WebkitLineClamp: 2,
|
||||||
|
WebkitBoxOrient: 'vertical',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{event.description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '13px',
|
||||||
|
fontWeight: '500',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{event.venue}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EventListCard;
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { ChurchEvent } from '../types';
|
||||||
|
import { IonIcon } from '@ionic/react';
|
||||||
|
import { calendarOutline } from 'ionicons/icons';
|
||||||
|
|
||||||
|
interface EventPreviewCardProps {
|
||||||
|
event: ChurchEvent;
|
||||||
|
onClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EventPreviewCard: React.FC<EventPreviewCardProps> = ({
|
||||||
|
event,
|
||||||
|
onClick,
|
||||||
|
}) => {
|
||||||
|
const categoryName = event.event_categories?.name || 'Event';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
onClick={onClick}
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
padding: '8px 0',
|
||||||
|
gap: '10px',
|
||||||
|
background: 'transparent',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '40px',
|
||||||
|
height: '40px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: 'var(--color-brand-soft)',
|
||||||
|
flexShrink: 0,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={calendarOutline}
|
||||||
|
style={{ color: 'var(--color-brand)', fontSize: '20px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ flex: 1, minWidth: 0 }}>
|
||||||
|
<h4
|
||||||
|
style={{
|
||||||
|
margin: '0 0 2px 0',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{event.title}
|
||||||
|
</h4>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: 'var(--color-text-secondary)',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(() => {
|
||||||
|
const date = new Date(event.start_at);
|
||||||
|
const hasTime = date.getHours() !== 0 || date.getMinutes() !== 0;
|
||||||
|
const timeStr = hasTime
|
||||||
|
? `${date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })} • `
|
||||||
|
: '';
|
||||||
|
return `${timeStr}${event.day_label}`;
|
||||||
|
})()}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'var(--color-brand-soft)',
|
||||||
|
color: 'var(--color-brand)',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '4px 10px',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{categoryName}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EventPreviewCard;
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { IonIcon } from '@ionic/react';
|
||||||
|
|
||||||
|
interface HomeStatCardProps {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
caption: string;
|
||||||
|
icon?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const HomeStatCard: React.FC<HomeStatCardProps> = ({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
caption,
|
||||||
|
icon,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '18px',
|
||||||
|
flex: 1,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '8px',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: 'var(--color-text-secondary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
{icon && (
|
||||||
|
<IonIcon
|
||||||
|
icon={icon}
|
||||||
|
style={{ color: 'var(--color-brand)', fontSize: '16px' }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '28px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
margin: '4px 0 0 0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{value}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: 'var(--color-text-secondary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{caption}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default HomeStatCard;
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
|
||||||
import { IonInput } from '@ionic/react';
|
|
||||||
|
|
||||||
interface OtpInputProps {
|
|
||||||
value: string;
|
|
||||||
onChange: (value: string) => void;
|
|
||||||
disabled?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const OtpInput: React.FC<OtpInputProps> = ({ value, onChange, disabled }) => {
|
|
||||||
const inputsRef = useRef<(HTMLInputElement | null)[]>([]);
|
|
||||||
|
|
||||||
// Convert current value string into an array of 6 chars
|
|
||||||
const digits = value.split('').concat(Array(6).fill('')).slice(0, 6);
|
|
||||||
|
|
||||||
const handleChange = (e: any, index: number) => {
|
|
||||||
let val = e.target.value;
|
|
||||||
// Allow only numeric
|
|
||||||
if (!/^[0-9]*$/.test(val)) return;
|
|
||||||
|
|
||||||
// Grab the last character if they typed multiple
|
|
||||||
val = val.substring(val.length - 1);
|
|
||||||
|
|
||||||
const newDigits = [...digits];
|
|
||||||
newDigits[index] = val;
|
|
||||||
onChange(newDigits.join(''));
|
|
||||||
|
|
||||||
// Move to next input if filled
|
|
||||||
if (val !== '' && index < 5) {
|
|
||||||
const nextInput = inputsRef.current[index + 1];
|
|
||||||
if (nextInput) nextInput.focus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleKeyDown = (
|
|
||||||
e: React.KeyboardEvent<HTMLInputElement>,
|
|
||||||
index: number
|
|
||||||
) => {
|
|
||||||
if (e.key === 'Backspace' && !digits[index] && index > 0) {
|
|
||||||
// Move to previous input on backspace if current is empty
|
|
||||||
const prevInput = inputsRef.current[index - 1];
|
|
||||||
if (prevInput) {
|
|
||||||
prevInput.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', gap: '8px', justifyContent: 'center' }}>
|
|
||||||
{digits.map((digit, index) => (
|
|
||||||
<input
|
|
||||||
key={index}
|
|
||||||
ref={(el) => {
|
|
||||||
inputsRef.current[index] = el;
|
|
||||||
}}
|
|
||||||
type="text"
|
|
||||||
inputMode="numeric"
|
|
||||||
pattern="[0-9]*"
|
|
||||||
maxLength={2}
|
|
||||||
value={digit}
|
|
||||||
onChange={(e) => handleChange(e, index)}
|
|
||||||
onKeyDown={(e) => handleKeyDown(e, index)}
|
|
||||||
disabled={disabled}
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
maxWidth: '48px',
|
|
||||||
height: '52px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
border: 'none',
|
|
||||||
background: '#f4f7f4',
|
|
||||||
color: '#0f1720',
|
|
||||||
textAlign: 'center',
|
|
||||||
fontSize: '24px',
|
|
||||||
fontWeight: '600',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default OtpInput;
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { IonInput } from '@ionic/react';
|
||||||
|
|
||||||
|
interface OtpInputRowProps {
|
||||||
|
digits: string[];
|
||||||
|
onChange: (index: number, value: string) => void;
|
||||||
|
onKeyDown: (
|
||||||
|
index: number,
|
||||||
|
e: React.KeyboardEvent<HTMLIonInputElement>
|
||||||
|
) => void;
|
||||||
|
inputRefs: React.RefObject<HTMLIonInputElement>[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const OtpInputRow: React.FC<OtpInputRowProps> = ({
|
||||||
|
digits,
|
||||||
|
onChange,
|
||||||
|
onKeyDown,
|
||||||
|
inputRefs,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: '10px',
|
||||||
|
justifyContent: 'center',
|
||||||
|
margin: '0 0 20px 0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{digits.map((digit, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '12px',
|
||||||
|
width: '48px',
|
||||||
|
height: '56px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
boxShadow: '0 1px 3px rgba(0,0,0,0.05)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonInput
|
||||||
|
ref={inputRefs[index]}
|
||||||
|
type="tel"
|
||||||
|
inputMode="numeric"
|
||||||
|
maxlength={1}
|
||||||
|
value={digit}
|
||||||
|
onIonInput={(e) =>
|
||||||
|
onChange(index, (e.target as HTMLIonInputElement).value as string)
|
||||||
|
}
|
||||||
|
onKeyDown={(e) => onKeyDown(index, e)}
|
||||||
|
style={{
|
||||||
|
fontSize: '24px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
textAlign: 'center',
|
||||||
|
'--padding-start': '0px',
|
||||||
|
'--padding-end': '0px',
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OtpInputRow;
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { IonIcon } from '@ionic/react';
|
|
||||||
|
|
||||||
interface ProfileInfoRowProps {
|
|
||||||
icon: string;
|
|
||||||
label: string;
|
|
||||||
value?: string;
|
|
||||||
onClick?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ProfileInfoRow: React.FC<ProfileInfoRowProps> = ({
|
|
||||||
icon,
|
|
||||||
label,
|
|
||||||
value,
|
|
||||||
onClick,
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
onClick={onClick}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
minHeight: '64px',
|
|
||||||
padding: '10px 20px',
|
|
||||||
cursor: onClick ? 'pointer' : 'default',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '14px',
|
|
||||||
minWidth: 0,
|
|
||||||
flex: 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '40px',
|
|
||||||
height: '40px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={icon}
|
|
||||||
style={{ color: 'var(--color-brand)', fontSize: '20px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '2px',
|
|
||||||
minWidth: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
textTransform: 'uppercase',
|
|
||||||
letterSpacing: '0.04em',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
{value && (
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{value}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ProfileInfoRow;
|
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React from 'react';
|
||||||
import { Route, Redirect, RouteProps } from 'react-router-dom';
|
import { Route, Redirect, RouteProps } from 'react-router-dom';
|
||||||
import { IonSpinner } from '@ionic/react';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
import { useProfile } from '../contexts/ProfileContext';
|
|
||||||
import { useProfileLoader } from '../hooks/useProfileLoader';
|
|
||||||
|
|
||||||
interface ProtectedRouteProps extends RouteProps {
|
interface ProtectedRouteProps extends RouteProps {
|
||||||
component: React.ComponentType<any>;
|
component: React.ComponentType<any>;
|
||||||
@@ -13,16 +10,7 @@ const ProtectedRoute: React.FC<ProtectedRouteProps> = ({
|
|||||||
component: Component,
|
component: Component,
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const { user } = useAuth();
|
const { user, profile } = useAuth();
|
||||||
const { status } = useProfile();
|
|
||||||
const { loadProfileAndNavigate } = useProfileLoader();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// If user is logged in but profile is still loading (e.g. cold start direct link)
|
|
||||||
if (user && status === 'loading') {
|
|
||||||
loadProfileAndNavigate();
|
|
||||||
}
|
|
||||||
}, [user, status, loadProfileAndNavigate]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Route
|
<Route
|
||||||
@@ -31,21 +19,10 @@ const ProtectedRoute: React.FC<ProtectedRouteProps> = ({
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
return <Redirect to="/auth" />;
|
return <Redirect to="/auth" />;
|
||||||
}
|
}
|
||||||
if (status === 'loading') {
|
if (profile !== undefined && profile === null) {
|
||||||
return (
|
return <Redirect to="/setup-profile" />;
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
height: '100vh',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSpinner name="crescent" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (status === 'missing') {
|
if (profile !== undefined && profile !== null && !profile.full_name) {
|
||||||
return <Redirect to="/setup-profile" />;
|
return <Redirect to="/setup-profile" />;
|
||||||
}
|
}
|
||||||
return <Component {...props} />;
|
return <Component {...props} />;
|
||||||
|
|||||||
@@ -1,121 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
interface QuotationCardProps {
|
|
||||||
supplierName: string;
|
|
||||||
priceLabel: string;
|
|
||||||
deliveryOption: string;
|
|
||||||
status: string;
|
|
||||||
onAccept: () => void;
|
|
||||||
onDecline: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QuotationCard: React.FC<QuotationCardProps> = ({
|
|
||||||
supplierName,
|
|
||||||
priceLabel,
|
|
||||||
deliveryOption,
|
|
||||||
status,
|
|
||||||
onAccept,
|
|
||||||
onDecline,
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '16px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
marginBottom: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{supplierName}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '30px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-brand-strong)',
|
|
||||||
fontVariantNumeric: 'tabular-nums',
|
|
||||||
marginBottom: '6px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{priceLabel}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
marginBottom: '18px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{deliveryOption}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{status === 'submitted' ? (
|
|
||||||
<div style={{ display: 'flex', gap: '12px' }}>
|
|
||||||
<button
|
|
||||||
onClick={onAccept}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-brand)',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '12px 16px',
|
|
||||||
border: 'none',
|
|
||||||
flex: 1,
|
|
||||||
fontWeight: '600',
|
|
||||||
fontSize: '14px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Accept
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={onDecline}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
color: 'var(--color-brand)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '12px 16px',
|
|
||||||
border: 'none',
|
|
||||||
flex: 1,
|
|
||||||
fontWeight: '600',
|
|
||||||
fontSize: '14px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Decline
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'inline-block',
|
|
||||||
background:
|
|
||||||
status === 'accepted'
|
|
||||||
? 'var(--color-success-soft)'
|
|
||||||
: 'rgba(23,33,43,0.10)',
|
|
||||||
color:
|
|
||||||
status === 'accepted' ? 'var(--color-success-text)' : '#4b5563',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '6px 12px',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
textTransform: 'capitalize',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{status}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default QuotationCard;
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
interface QuoteSummaryRowProps {
|
|
||||||
supplierName: string;
|
|
||||||
priceLabel: string;
|
|
||||||
deliveryOption: string;
|
|
||||||
status: string;
|
|
||||||
onClick?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QuoteSummaryRow: React.FC<QuoteSummaryRowProps> = ({
|
|
||||||
supplierName,
|
|
||||||
priceLabel,
|
|
||||||
deliveryOption,
|
|
||||||
status,
|
|
||||||
onClick,
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
onClick={onClick}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '4px',
|
|
||||||
padding: '12px 0',
|
|
||||||
borderBottom: '1px solid var(--color-border)',
|
|
||||||
cursor: onClick ? 'pointer' : 'default',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{supplierName}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-brand-strong)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{priceLabel}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{deliveryOption}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color:
|
|
||||||
status === 'accepted'
|
|
||||||
? 'var(--color-success-text)'
|
|
||||||
: 'var(--color-text-secondary)',
|
|
||||||
textTransform: 'capitalize',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{status}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default QuoteSummaryRow;
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
interface RecentActivityCardProps {
|
|
||||||
title: string;
|
|
||||||
subtitle: string;
|
|
||||||
meta: string;
|
|
||||||
onClick: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const RecentActivityCard: React.FC<RecentActivityCardProps> = ({
|
|
||||||
title,
|
|
||||||
subtitle,
|
|
||||||
meta,
|
|
||||||
onClick,
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
onClick={onClick}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-shell)',
|
|
||||||
borderRadius: '38px',
|
|
||||||
padding: '5px',
|
|
||||||
margin: '0 20px 12px',
|
|
||||||
boxShadow: 'var(--color-shadow-lg)',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '32px',
|
|
||||||
padding: '18px 20px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
boxShadow: 'var(--color-shadow-sm)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '4px',
|
|
||||||
minWidth: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '16px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{title}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{subtitle}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '18px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-brand-strong)',
|
|
||||||
textTransform: 'capitalize',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{meta}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RecentActivityCard;
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
interface RequestListCardProps {
|
|
||||||
title: string;
|
|
||||||
subtitle: string;
|
|
||||||
referenceNumber: string;
|
|
||||||
status: string;
|
|
||||||
trailingText?: string;
|
|
||||||
onClick: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const RequestListCard: React.FC<RequestListCardProps> = ({
|
|
||||||
title,
|
|
||||||
subtitle,
|
|
||||||
referenceNumber,
|
|
||||||
status,
|
|
||||||
trailingText,
|
|
||||||
onClick,
|
|
||||||
}) => {
|
|
||||||
let statusBg = 'rgba(23,33,43,0.10)';
|
|
||||||
let statusColor = '#4b5563';
|
|
||||||
|
|
||||||
if (status === 'open') {
|
|
||||||
statusBg = 'var(--color-success-soft)';
|
|
||||||
statusColor = 'var(--color-success-text)';
|
|
||||||
} else if (status === 'quoted') {
|
|
||||||
statusBg = 'var(--color-warning-soft)';
|
|
||||||
statusColor = 'var(--color-warning-text)';
|
|
||||||
} else if (status === 'closed') {
|
|
||||||
statusBg = 'rgba(23,33,43,0.10)';
|
|
||||||
statusColor = '#4b5563';
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
onClick={onClick}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '14px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'flex-start',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '4px',
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '16px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{title}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{subtitle}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{trailingText && (
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-brand-strong)',
|
|
||||||
marginLeft: '12px',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{trailingText}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
gap: '8px',
|
|
||||||
alignItems: 'center',
|
|
||||||
flexWrap: 'wrap',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-accent-soft)',
|
|
||||||
color: 'var(--color-warning-text)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '6px 12px',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{referenceNumber}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: statusBg,
|
|
||||||
color: statusColor,
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '6px 12px',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
textTransform: 'capitalize',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{status}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RequestListCard;
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { IonIcon } from '@ionic/react';
|
|
||||||
import { checkmarkCircle, ellipseOutline } from 'ionicons/icons';
|
|
||||||
|
|
||||||
export interface SupplierOption {
|
|
||||||
id: string;
|
|
||||||
full_name: string;
|
|
||||||
company_name: string | null;
|
|
||||||
city: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SupplierPickerRowProps {
|
|
||||||
supplier: SupplierOption;
|
|
||||||
selected: boolean;
|
|
||||||
onToggle: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SupplierPickerRow: React.FC<SupplierPickerRowProps> = ({
|
|
||||||
supplier,
|
|
||||||
selected,
|
|
||||||
onToggle,
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
onClick={onToggle}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
padding: '12px 0',
|
|
||||||
borderBottom: '1px solid #edf4ee',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={selected ? checkmarkCircle : ellipseOutline}
|
|
||||||
style={{
|
|
||||||
fontSize: '24px',
|
|
||||||
color: selected ? '#166534' : '#8a978f',
|
|
||||||
marginRight: '12px',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '2px',
|
|
||||||
flex: 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span style={{ fontSize: '15px', fontWeight: '600', color: '#0f1720' }}>
|
|
||||||
{supplier.company_name || supplier.full_name}
|
|
||||||
</span>
|
|
||||||
<span style={{ fontSize: '13px', fontWeight: '400', color: '#6c7a71' }}>
|
|
||||||
{supplier.company_name ? supplier.full_name : 'Independent'}
|
|
||||||
{supplier.city ? ` • ${supplier.city}` : ''}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SupplierPickerRow;
|
|
||||||
@@ -1,51 +1,137 @@
|
|||||||
import React, { createContext, useContext, useEffect, useState } from 'react';
|
import React, { createContext, useContext, useEffect, useState } from 'react';
|
||||||
import { User } from '@supabase/supabase-js';
|
import { User } from '@supabase/supabase-js';
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
|
import { IonSpinner } from '@ionic/react';
|
||||||
|
|
||||||
|
export interface Profile {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
full_name: string;
|
||||||
|
role: string;
|
||||||
|
ministry_group: string | null;
|
||||||
|
avatar_url: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
interface AuthContextType {
|
interface AuthContextType {
|
||||||
user: User | null;
|
user: User | null;
|
||||||
|
profile: Profile | null;
|
||||||
|
refreshProfile: () => Promise<void>;
|
||||||
signOut: () => Promise<void>;
|
signOut: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthContext = createContext<AuthContextType>({
|
const AuthContext = createContext<AuthContextType>({
|
||||||
user: null,
|
user: null,
|
||||||
|
profile: null,
|
||||||
|
refreshProfile: async () => {},
|
||||||
signOut: async () => {},
|
signOut: async () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useAuth = () => useContext(AuthContext);
|
const PROFILE_CACHE_KEY = 'church_app_profile_cache';
|
||||||
|
|
||||||
|
async function getCachedProfile(): Promise<Profile | null> {
|
||||||
|
const cached = localStorage.getItem(PROFILE_CACHE_KEY);
|
||||||
|
if (cached) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(cached);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function cacheProfile(profile: Profile) {
|
||||||
|
localStorage.setItem(PROFILE_CACHE_KEY, JSON.stringify(profile));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function clearCachedProfile() {
|
||||||
|
localStorage.removeItem(PROFILE_CACHE_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
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 [profile, setProfile] = useState<Profile | null>(null);
|
||||||
const [initializing, setInitializing] = useState(true);
|
const [initializing, setInitializing] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
const fetchProfile = async (userId: string) => {
|
||||||
supabase.auth.getSession().then(({ data }) => {
|
const cached = await getCachedProfile();
|
||||||
setUser(data.session?.user ?? null);
|
if (cached && cached.id === userId) {
|
||||||
setInitializing(false);
|
setProfile(cached);
|
||||||
});
|
}
|
||||||
|
const { data } = await supabase
|
||||||
const {
|
.from('profiles')
|
||||||
data: { subscription },
|
.select('*')
|
||||||
} = supabase.auth.onAuthStateChange((_event, session) => {
|
.eq('id', userId)
|
||||||
setUser(session?.user ?? null);
|
.single();
|
||||||
});
|
if (data) {
|
||||||
|
setProfile(data);
|
||||||
return () => subscription.unsubscribe();
|
await cacheProfile(data);
|
||||||
}, []);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const signOut = async () => {
|
const signOut = async () => {
|
||||||
await supabase.auth.signOut();
|
await supabase.auth.signOut();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// One-shot bootstrap
|
||||||
|
supabase.auth.getSession().then(async ({ data }) => {
|
||||||
|
const currentUser = data.session?.user ?? null;
|
||||||
|
setUser(currentUser);
|
||||||
|
if (currentUser) {
|
||||||
|
await fetchProfile(currentUser.id);
|
||||||
|
}
|
||||||
|
setInitializing(false); // only ever called once - IonReactRouter mounts after this
|
||||||
|
});
|
||||||
|
|
||||||
|
// Subsequent events: update state, never touch initializing
|
||||||
|
const {
|
||||||
|
data: { subscription },
|
||||||
|
} = supabase.auth.onAuthStateChange(async (_event, session) => {
|
||||||
|
const currentUser = session?.user ?? null;
|
||||||
|
setUser(currentUser);
|
||||||
|
if (currentUser) {
|
||||||
|
await fetchProfile(currentUser.id);
|
||||||
|
} else {
|
||||||
|
setProfile(null);
|
||||||
|
await clearCachedProfile();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => subscription.unsubscribe();
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (initializing) {
|
if (initializing) {
|
||||||
return null; // Or a simple spinner if preferred, but usually handled nicely
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
height: '100vh',
|
||||||
|
backgroundColor: '#f5f7f4',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSpinner name="crescent" color="primary" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthContext.Provider value={{ user, signOut }}>
|
<AuthContext.Provider
|
||||||
|
value={{
|
||||||
|
user,
|
||||||
|
profile,
|
||||||
|
refreshProfile: () =>
|
||||||
|
user ? fetchProfile(user.id) : Promise.resolve(),
|
||||||
|
signOut,
|
||||||
|
}}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</AuthContext.Provider>
|
</AuthContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useAuth = () => useContext(AuthContext);
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
import React, {
|
|
||||||
createContext,
|
|
||||||
useContext,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useState,
|
|
||||||
} from 'react';
|
|
||||||
import { Preferences } from '@capacitor/preferences';
|
|
||||||
import { Database } from '../database.types';
|
|
||||||
|
|
||||||
export type Profile = Database['public']['Tables']['profiles']['Row'];
|
|
||||||
export type ThemeMode = 'light' | 'dark';
|
|
||||||
|
|
||||||
interface ProfileContextType {
|
|
||||||
profile: Profile | null;
|
|
||||||
status: 'loading' | 'loaded' | 'missing';
|
|
||||||
themeMode: ThemeMode;
|
|
||||||
setProfile: (profile: Profile | null) => void;
|
|
||||||
setStatus: (status: 'loading' | 'loaded' | 'missing') => void;
|
|
||||||
setThemeMode: (mode: ThemeMode) => Promise<void>;
|
|
||||||
clearProfile: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ProfileContext = createContext<ProfileContextType>({
|
|
||||||
profile: null,
|
|
||||||
status: 'loading',
|
|
||||||
themeMode: 'light',
|
|
||||||
setProfile: () => {},
|
|
||||||
setStatus: () => {},
|
|
||||||
setThemeMode: async () => {},
|
|
||||||
clearProfile: () => {},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const useProfile = () => useContext(ProfileContext);
|
|
||||||
|
|
||||||
export const ProfileProvider: React.FC<{ children: React.ReactNode }> = ({
|
|
||||||
children,
|
|
||||||
}) => {
|
|
||||||
const [profile, setProfile] = useState<Profile | null>(null);
|
|
||||||
const [status, setStatus] = useState<'loading' | 'loaded' | 'missing'>(
|
|
||||||
'loading'
|
|
||||||
);
|
|
||||||
const [themeModeState, setThemeModeState] = useState<ThemeMode>('light');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const loadThemeMode = async () => {
|
|
||||||
const { value } = await Preferences.get({ key: 'theme_mode' });
|
|
||||||
const mode = value === 'dark' ? 'dark' : 'light';
|
|
||||||
setThemeModeState(mode);
|
|
||||||
};
|
|
||||||
|
|
||||||
loadThemeMode();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const setThemeMode = async (mode: ThemeMode) => {
|
|
||||||
setThemeModeState(mode);
|
|
||||||
await Preferences.set({ key: 'theme_mode', value: mode });
|
|
||||||
};
|
|
||||||
|
|
||||||
const clearProfile = () => {
|
|
||||||
setProfile(null);
|
|
||||||
setStatus('loading');
|
|
||||||
};
|
|
||||||
|
|
||||||
const value = useMemo(
|
|
||||||
() => ({
|
|
||||||
profile,
|
|
||||||
status,
|
|
||||||
themeMode: themeModeState,
|
|
||||||
setProfile,
|
|
||||||
setStatus,
|
|
||||||
setThemeMode,
|
|
||||||
clearProfile,
|
|
||||||
}),
|
|
||||||
[profile, status, themeModeState]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ProfileContext.Provider value={value}>{children}</ProfileContext.Provider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -14,205 +14,157 @@ export type Database = {
|
|||||||
}
|
}
|
||||||
public: {
|
public: {
|
||||||
Tables: {
|
Tables: {
|
||||||
|
event_categories: {
|
||||||
|
Row: {
|
||||||
|
accent_color: string | null
|
||||||
|
created_at: string
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
slug: string
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
accent_color?: string | null
|
||||||
|
created_at?: string
|
||||||
|
id?: string
|
||||||
|
name: string
|
||||||
|
slug: string
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
accent_color?: string | null
|
||||||
|
created_at?: string
|
||||||
|
id?: string
|
||||||
|
name?: string
|
||||||
|
slug?: string
|
||||||
|
}
|
||||||
|
Relationships: []
|
||||||
|
}
|
||||||
|
events: {
|
||||||
|
Row: {
|
||||||
|
audience: string
|
||||||
|
category_id: string | null
|
||||||
|
created_at: string
|
||||||
|
created_by: string | null
|
||||||
|
day_label: string
|
||||||
|
description: string
|
||||||
|
end_at: string | null
|
||||||
|
id: string
|
||||||
|
is_featured: boolean
|
||||||
|
start_at: string
|
||||||
|
title: string
|
||||||
|
updated_at: string
|
||||||
|
venue: string
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
audience?: string
|
||||||
|
category_id?: string | null
|
||||||
|
created_at?: string
|
||||||
|
created_by?: string | null
|
||||||
|
day_label: string
|
||||||
|
description?: string
|
||||||
|
end_at?: string | null
|
||||||
|
id?: string
|
||||||
|
is_featured?: boolean
|
||||||
|
start_at: string
|
||||||
|
title: string
|
||||||
|
updated_at?: string
|
||||||
|
venue: string
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
audience?: string
|
||||||
|
category_id?: string | null
|
||||||
|
created_at?: string
|
||||||
|
created_by?: string | null
|
||||||
|
day_label?: string
|
||||||
|
description?: string
|
||||||
|
end_at?: string | null
|
||||||
|
id?: string
|
||||||
|
is_featured?: boolean
|
||||||
|
start_at?: string
|
||||||
|
title?: string
|
||||||
|
updated_at?: string
|
||||||
|
venue?: string
|
||||||
|
}
|
||||||
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "events_category_id_fkey"
|
||||||
|
columns: ["category_id"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "event_categories"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
news: {
|
||||||
|
Row: {
|
||||||
|
content: string
|
||||||
|
created_at: string | null
|
||||||
|
created_by: string
|
||||||
|
id: string
|
||||||
|
image_url: string | null
|
||||||
|
title: string
|
||||||
|
updated_at: string | null
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
content: string
|
||||||
|
created_at?: string | null
|
||||||
|
created_by: string
|
||||||
|
id?: string
|
||||||
|
image_url?: string | null
|
||||||
|
title: string
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
content?: string
|
||||||
|
created_at?: string | null
|
||||||
|
created_by?: string
|
||||||
|
id?: string
|
||||||
|
image_url?: string | null
|
||||||
|
title?: string
|
||||||
|
updated_at?: string | null
|
||||||
|
}
|
||||||
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "news_created_by_fkey"
|
||||||
|
columns: ["created_by"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "profiles"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
profiles: {
|
profiles: {
|
||||||
Row: {
|
Row: {
|
||||||
avatar_url: string | null
|
avatar_url: string | null
|
||||||
city: string | null
|
|
||||||
company_name: string | null
|
|
||||||
created_at: string
|
created_at: string
|
||||||
full_name: string
|
email: string
|
||||||
|
full_name: string | null
|
||||||
id: string
|
id: string
|
||||||
phone: string | null
|
ministry_group: string | null
|
||||||
role: string
|
role: string
|
||||||
updated_at: string
|
updated_at: string
|
||||||
}
|
}
|
||||||
Insert: {
|
Insert: {
|
||||||
avatar_url?: string | null
|
avatar_url?: string | null
|
||||||
city?: string | null
|
|
||||||
company_name?: string | null
|
|
||||||
created_at?: string
|
created_at?: string
|
||||||
full_name: string
|
email: string
|
||||||
|
full_name?: string | null
|
||||||
id: string
|
id: string
|
||||||
phone?: string | null
|
ministry_group?: string | null
|
||||||
role: string
|
role?: string
|
||||||
updated_at?: string
|
updated_at?: string
|
||||||
}
|
}
|
||||||
Update: {
|
Update: {
|
||||||
avatar_url?: string | null
|
avatar_url?: string | null
|
||||||
city?: string | null
|
|
||||||
company_name?: string | null
|
|
||||||
created_at?: string
|
created_at?: string
|
||||||
full_name?: string
|
email?: string
|
||||||
|
full_name?: string | null
|
||||||
id?: string
|
id?: string
|
||||||
phone?: string | null
|
ministry_group?: string | null
|
||||||
role?: string
|
role?: string
|
||||||
updated_at?: string
|
updated_at?: string
|
||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
quotations: {
|
|
||||||
Row: {
|
|
||||||
created_at: string
|
|
||||||
currency_code: string
|
|
||||||
delivery_option: string
|
|
||||||
id: string
|
|
||||||
note: string | null
|
|
||||||
price_amount: number
|
|
||||||
rfq_id: string
|
|
||||||
status: string
|
|
||||||
supplier_id: string
|
|
||||||
updated_at: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
created_at?: string
|
|
||||||
currency_code?: string
|
|
||||||
delivery_option: string
|
|
||||||
id?: string
|
|
||||||
note?: string | null
|
|
||||||
price_amount: number
|
|
||||||
rfq_id: string
|
|
||||||
status?: string
|
|
||||||
supplier_id: string
|
|
||||||
updated_at?: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
created_at?: string
|
|
||||||
currency_code?: string
|
|
||||||
delivery_option?: string
|
|
||||||
id?: string
|
|
||||||
note?: string | null
|
|
||||||
price_amount?: number
|
|
||||||
rfq_id?: string
|
|
||||||
status?: string
|
|
||||||
supplier_id?: string
|
|
||||||
updated_at?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "quotations_rfq_id_fkey"
|
|
||||||
columns: ["rfq_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "rfqs"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
foreignKeyName: "quotations_supplier_id_fkey"
|
|
||||||
columns: ["supplier_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
rfq_images: {
|
|
||||||
Row: {
|
|
||||||
created_at: string
|
|
||||||
id: string
|
|
||||||
owner_id: string
|
|
||||||
rfq_id: string
|
|
||||||
storage_path: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
created_at?: string
|
|
||||||
id?: string
|
|
||||||
owner_id: string
|
|
||||||
rfq_id: string
|
|
||||||
storage_path: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
created_at?: string
|
|
||||||
id?: string
|
|
||||||
owner_id?: string
|
|
||||||
rfq_id?: string
|
|
||||||
storage_path?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "rfq_images_rfq_id_fkey"
|
|
||||||
columns: ["rfq_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "rfqs"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
rfq_recipients: {
|
|
||||||
Row: {
|
|
||||||
created_at: string
|
|
||||||
id: string
|
|
||||||
rfq_id: string
|
|
||||||
supplier_id: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
created_at?: string
|
|
||||||
id?: string
|
|
||||||
rfq_id: string
|
|
||||||
supplier_id: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
created_at?: string
|
|
||||||
id?: string
|
|
||||||
rfq_id?: string
|
|
||||||
supplier_id?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "rfq_recipients_rfq_id_fkey"
|
|
||||||
columns: ["rfq_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "rfqs"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
foreignKeyName: "rfq_recipients_supplier_id_fkey"
|
|
||||||
columns: ["supplier_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
rfqs: {
|
|
||||||
Row: {
|
|
||||||
buyer_id: string
|
|
||||||
created_at: string
|
|
||||||
id: string
|
|
||||||
reference_number: string
|
|
||||||
request_text: string
|
|
||||||
status: string
|
|
||||||
title: string
|
|
||||||
updated_at: string
|
|
||||||
}
|
|
||||||
Insert: {
|
|
||||||
buyer_id: string
|
|
||||||
created_at?: string
|
|
||||||
id?: string
|
|
||||||
reference_number: string
|
|
||||||
request_text: string
|
|
||||||
status?: string
|
|
||||||
title: string
|
|
||||||
updated_at?: string
|
|
||||||
}
|
|
||||||
Update: {
|
|
||||||
buyer_id?: string
|
|
||||||
created_at?: string
|
|
||||||
id?: string
|
|
||||||
reference_number?: string
|
|
||||||
request_text?: string
|
|
||||||
status?: string
|
|
||||||
title?: string
|
|
||||||
updated_at?: string
|
|
||||||
}
|
|
||||||
Relationships: [
|
|
||||||
{
|
|
||||||
foreignKeyName: "rfqs_buyer_id_fkey"
|
|
||||||
columns: ["buyer_id"]
|
|
||||||
isOneToOne: false
|
|
||||||
referencedRelation: "profiles"
|
|
||||||
referencedColumns: ["id"]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Views: {
|
Views: {
|
||||||
[_ in never]: never
|
[_ in never]: never
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { Preferences } from '@capacitor/preferences';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { useProfile, Profile } from '../contexts/ProfileContext';
|
|
||||||
|
|
||||||
export const useProfileLoader = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const { setProfile, setStatus } = useProfile();
|
|
||||||
|
|
||||||
const loadProfileAndNavigate = async (
|
|
||||||
setOverlayVisible?: (v: boolean) => void,
|
|
||||||
setOverlayError?: (v: boolean) => void
|
|
||||||
) => {
|
|
||||||
if (!user) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. Check cache
|
|
||||||
const { value } = await Preferences.get({ key: `profile_${user.id}` });
|
|
||||||
if (value) {
|
|
||||||
const cachedProfile = JSON.parse(value) as Profile;
|
|
||||||
setProfile(cachedProfile);
|
|
||||||
setStatus('loaded');
|
|
||||||
history.replace('/home');
|
|
||||||
|
|
||||||
// Silent refresh
|
|
||||||
const { data } = await supabase
|
|
||||||
.from('profiles')
|
|
||||||
.select('*')
|
|
||||||
.eq('id', user.id)
|
|
||||||
.single();
|
|
||||||
if (data) {
|
|
||||||
setProfile(data);
|
|
||||||
await Preferences.set({
|
|
||||||
key: `profile_${user.id}`,
|
|
||||||
value: JSON.stringify(data),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// If silent refresh finds no row, they somehow lost their profile (or deleted it)
|
|
||||||
// We can handle this by redirecting them next time, or immediately
|
|
||||||
setStatus('missing');
|
|
||||||
history.replace('/setup-profile');
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Cache miss, fetch from remote
|
|
||||||
if (setOverlayVisible) setOverlayVisible(true);
|
|
||||||
const { data, error } = await supabase
|
|
||||||
.from('profiles')
|
|
||||||
.select('*')
|
|
||||||
.eq('id', user.id)
|
|
||||||
.single();
|
|
||||||
|
|
||||||
if (error && error.code !== 'PGRST116') {
|
|
||||||
// PGRST116 means no rows found
|
|
||||||
console.error('Error fetching profile:', error);
|
|
||||||
if (setOverlayError) setOverlayError(true);
|
|
||||||
return; // Keep overlay visible so they see the error or can retry
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
// Row found
|
|
||||||
setProfile(data);
|
|
||||||
setStatus('loaded');
|
|
||||||
await Preferences.set({
|
|
||||||
key: `profile_${user.id}`,
|
|
||||||
value: JSON.stringify(data),
|
|
||||||
});
|
|
||||||
if (setOverlayVisible) setOverlayVisible(false);
|
|
||||||
history.replace('/home');
|
|
||||||
} else {
|
|
||||||
// No row found
|
|
||||||
setStatus('missing');
|
|
||||||
if (setOverlayVisible) setOverlayVisible(false);
|
|
||||||
history.replace('/setup-profile');
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Unexpected error loading profile:', err);
|
|
||||||
if (setOverlayError) setOverlayError(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return { loadProfileAndNavigate };
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,685 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
IonPage,
|
||||||
|
IonContent,
|
||||||
|
IonHeader,
|
||||||
|
IonToolbar,
|
||||||
|
IonTitle,
|
||||||
|
IonButtons,
|
||||||
|
IonButton,
|
||||||
|
IonIcon,
|
||||||
|
IonSpinner,
|
||||||
|
IonSelect,
|
||||||
|
IonSelectOption,
|
||||||
|
IonDatetime,
|
||||||
|
IonModal,
|
||||||
|
IonItem,
|
||||||
|
IonLabel,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import {
|
||||||
|
chevronBackOutline,
|
||||||
|
calendarOutline,
|
||||||
|
timeOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
import { EventCategory, ChurchEvent } from '../types';
|
||||||
|
|
||||||
|
const AdminEventForm: React.FC = () => {
|
||||||
|
const [title, setTitle] = useState('');
|
||||||
|
const [description, setDescription] = useState('');
|
||||||
|
const [categoryId, setCategoryId] = useState('');
|
||||||
|
const [audience, setAudience] = useState<'all' | 'youth' | 'children'>('all');
|
||||||
|
const [venue, setVenue] = useState('');
|
||||||
|
|
||||||
|
// Date states
|
||||||
|
const [startAt, setStartAt] = useState<string>(new Date().toISOString());
|
||||||
|
const [endAt, setEndAt] = useState<string>('');
|
||||||
|
|
||||||
|
const [isFeatured, setIsFeatured] = useState(false);
|
||||||
|
|
||||||
|
const [categories, setCategories] = useState<EventCategory[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const isEditMode = !!id;
|
||||||
|
|
||||||
|
const history = useHistory();
|
||||||
|
const { user, profile } = useAuth();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (profile && profile.role !== 'admin') {
|
||||||
|
history.replace('/home');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadData = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
// Load categories
|
||||||
|
const { data: catData, error: catError } = await supabase
|
||||||
|
.from('event_categories')
|
||||||
|
.select('*')
|
||||||
|
.order('name');
|
||||||
|
|
||||||
|
if (catError) {
|
||||||
|
setError(catError.message);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCategories(catData as EventCategory[]);
|
||||||
|
|
||||||
|
// If edit mode, load event
|
||||||
|
if (isEditMode) {
|
||||||
|
const { data: eventData, error: eventError } = await supabase
|
||||||
|
.from('events')
|
||||||
|
.select('*')
|
||||||
|
.eq('id', id)
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (eventError) {
|
||||||
|
setError(eventError.message);
|
||||||
|
} else {
|
||||||
|
const event = eventData as ChurchEvent;
|
||||||
|
setTitle(event.title);
|
||||||
|
setDescription(event.description);
|
||||||
|
setCategoryId(event.category_id);
|
||||||
|
setAudience(event.audience);
|
||||||
|
setVenue(event.venue);
|
||||||
|
setStartAt(event.start_at);
|
||||||
|
setEndAt(event.end_at || '');
|
||||||
|
setIsFeatured(event.is_featured);
|
||||||
|
}
|
||||||
|
} else if (catData && catData.length > 0) {
|
||||||
|
setCategoryId(catData[0].id); // default category
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (profile?.role === 'admin') {
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
}, [id, isEditMode, profile, history]);
|
||||||
|
|
||||||
|
const showError = (msg: string) => {
|
||||||
|
setError(msg);
|
||||||
|
setTimeout(() => setError(null), 4000);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDayLabel = (dateString: string) => {
|
||||||
|
const d = new Date(dateString);
|
||||||
|
return d.toLocaleDateString(undefined, { weekday: 'long' });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!title || !description || !categoryId || !venue || !startAt) {
|
||||||
|
showError('Please fill out all required fields');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!user || profile?.role !== 'admin') {
|
||||||
|
showError('Unauthorized');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSaving(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
const dayLabel = getDayLabel(startAt);
|
||||||
|
const eventPayload = {
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
category_id: categoryId,
|
||||||
|
audience,
|
||||||
|
venue,
|
||||||
|
start_at: startAt,
|
||||||
|
end_at: endAt || null,
|
||||||
|
day_label: dayLabel,
|
||||||
|
is_featured: isFeatured,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isEditMode) {
|
||||||
|
const { error: updateError } = await supabase
|
||||||
|
.from('events')
|
||||||
|
.update(eventPayload)
|
||||||
|
.eq('id', id);
|
||||||
|
|
||||||
|
if (updateError) {
|
||||||
|
showError(updateError.message);
|
||||||
|
setSaving(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const { error: insertError } = await supabase.from('events').insert({
|
||||||
|
...eventPayload,
|
||||||
|
created_by: user.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (insertError) {
|
||||||
|
showError(insertError.message);
|
||||||
|
setSaving(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setSaving(false);
|
||||||
|
history.goBack();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = async () => {
|
||||||
|
if (!isEditMode) return;
|
||||||
|
const confirmDelete = window.confirm(
|
||||||
|
'Are you sure you want to delete this event?'
|
||||||
|
);
|
||||||
|
if (!confirmDelete) return;
|
||||||
|
|
||||||
|
setSaving(true);
|
||||||
|
const { error: deleteError } = await supabase
|
||||||
|
.from('events')
|
||||||
|
.delete()
|
||||||
|
.eq('id', id);
|
||||||
|
|
||||||
|
if (deleteError) {
|
||||||
|
showError(deleteError.message);
|
||||||
|
setSaving(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
history.replace('/events');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage style={{ background: '#f5f7f4' }}>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton onClick={() => history.goBack()} disabled={saving}>
|
||||||
|
<IonIcon
|
||||||
|
icon={chevronBackOutline}
|
||||||
|
style={{ color: '#1f2937' }}
|
||||||
|
slot="icon-only"
|
||||||
|
/>
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
<IonTitle
|
||||||
|
style={{ fontSize: '18px', fontWeight: '700', color: '#1f2937' }}
|
||||||
|
>
|
||||||
|
{isEditMode ? 'Edit Event' : 'New Event'}
|
||||||
|
</IonTitle>
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
|
||||||
|
<IonContent
|
||||||
|
style={{
|
||||||
|
'--background': '#f5f7f4',
|
||||||
|
'--padding-start': '20px',
|
||||||
|
'--padding-end': '20px',
|
||||||
|
'--padding-top': '16px',
|
||||||
|
'--padding-bottom': '24px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
padding: '40px 0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSpinner name="crescent" color="primary" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '20px',
|
||||||
|
margin: '0 0 16px 0',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h2
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '18px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Event Details
|
||||||
|
</h2>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: '4px 0 0 0',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: '#6b7280',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Provide the schedule and venue info for members.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'rgba(163, 59, 50, 0.10)',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '12px 14px',
|
||||||
|
marginBottom: '16px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '13px',
|
||||||
|
fontWeight: '500',
|
||||||
|
color: '#a33b32',
|
||||||
|
lineHeight: '1.4',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<form
|
||||||
|
onSubmit={handleSave}
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '24px',
|
||||||
|
margin: '0 0 16px 0',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '16px',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* Title */}
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
marginBottom: '6px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Event Title
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="e.g. Sunday Service"
|
||||||
|
value={title}
|
||||||
|
onChange={(e) => setTitle(e.target.value)}
|
||||||
|
required
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
background: '#eef2ec',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '0 14px',
|
||||||
|
height: '48px',
|
||||||
|
fontSize: '15px',
|
||||||
|
color: '#1f2937',
|
||||||
|
outline: 'none',
|
||||||
|
boxSizing: 'border-box',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Category */}
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
marginBottom: '6px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Category
|
||||||
|
</label>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#eef2ec',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '0 14px',
|
||||||
|
height: '48px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSelect
|
||||||
|
value={categoryId}
|
||||||
|
onIonChange={(e) => setCategoryId(e.detail.value)}
|
||||||
|
interface="popover"
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
color: '#1f2937',
|
||||||
|
fontSize: '15px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{categories.map((cat) => (
|
||||||
|
<IonSelectOption key={cat.id} value={cat.id}>
|
||||||
|
{cat.name}
|
||||||
|
</IonSelectOption>
|
||||||
|
))}
|
||||||
|
</IonSelect>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Audience */}
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
marginBottom: '6px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Audience
|
||||||
|
</label>
|
||||||
|
<div style={{ display: 'flex', gap: '8px' }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setAudience('all')}
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
background: audience === 'all' ? '#2f6b4f' : '#eef2ec',
|
||||||
|
color: audience === 'all' ? '#ffffff' : '#4b5563',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '12px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
All Members
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setAudience('youth')}
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
background: audience === 'youth' ? '#2f6b4f' : '#eef2ec',
|
||||||
|
color: audience === 'youth' ? '#ffffff' : '#4b5563',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '12px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Youth Only
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setAudience('children')}
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
background:
|
||||||
|
audience === 'children' ? '#2f6b4f' : '#eef2ec',
|
||||||
|
color: audience === 'children' ? '#ffffff' : '#4b5563',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '12px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Children
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Venue */}
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
marginBottom: '6px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Venue
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="e.g. Main Auditorium"
|
||||||
|
value={venue}
|
||||||
|
onChange={(e) => setVenue(e.target.value)}
|
||||||
|
required
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
background: '#eef2ec',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '0 14px',
|
||||||
|
height: '48px',
|
||||||
|
fontSize: '15px',
|
||||||
|
color: '#1f2937',
|
||||||
|
outline: 'none',
|
||||||
|
boxSizing: 'border-box',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Dates */}
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
marginBottom: '6px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Start Time
|
||||||
|
</label>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#eef2ec',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '4px 14px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonDatetime
|
||||||
|
presentation="date-time"
|
||||||
|
value={startAt}
|
||||||
|
onIonChange={(e) => setStartAt(e.detail.value as string)}
|
||||||
|
style={{ background: 'transparent' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
marginBottom: '6px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
End Time (Optional)
|
||||||
|
</label>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#eef2ec',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '4px 14px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonDatetime
|
||||||
|
presentation="date-time"
|
||||||
|
value={endAt}
|
||||||
|
onIonChange={(e) =>
|
||||||
|
setEndAt((e.detail.value as string) || '')
|
||||||
|
}
|
||||||
|
showClearButton={true}
|
||||||
|
style={{ background: 'transparent' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Description */}
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
marginBottom: '6px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Description
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
placeholder="Describe the event..."
|
||||||
|
value={description}
|
||||||
|
onChange={(e) => setDescription(e.target.value)}
|
||||||
|
required
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
background: '#eef2ec',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '14px',
|
||||||
|
minHeight: '120px',
|
||||||
|
fontSize: '15px',
|
||||||
|
color: '#1f2937',
|
||||||
|
outline: 'none',
|
||||||
|
resize: 'vertical',
|
||||||
|
boxSizing: 'border-box',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Featured Toggle */}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
padding: '8px 0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Feature on Home Screen
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setIsFeatured(!isFeatured)}
|
||||||
|
style={{
|
||||||
|
width: '44px',
|
||||||
|
height: '24px',
|
||||||
|
background: isFeatured ? '#2f6b4f' : '#eef2ec',
|
||||||
|
borderRadius: '12px',
|
||||||
|
border: 'none',
|
||||||
|
position: 'relative',
|
||||||
|
cursor: 'pointer',
|
||||||
|
transition: '0.2s',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '20px',
|
||||||
|
height: '20px',
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '50%',
|
||||||
|
position: 'absolute',
|
||||||
|
top: '2px',
|
||||||
|
left: isFeatured ? '22px' : '2px',
|
||||||
|
transition: '0.2s',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={saving}
|
||||||
|
style={{
|
||||||
|
background: '#2f6b4f',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '16px',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#ffffff',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
marginTop: '8px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{saving ? (
|
||||||
|
<IonSpinner name="dots" color="light" />
|
||||||
|
) : isEditMode ? (
|
||||||
|
'Update Event'
|
||||||
|
) : (
|
||||||
|
'Create Event'
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{isEditMode && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleDelete}
|
||||||
|
disabled={saving}
|
||||||
|
style={{
|
||||||
|
background: 'rgba(163, 59, 50, 0.10)',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '16px',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#a33b32',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Delete Event
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AdminEventForm;
|
||||||
@@ -0,0 +1,330 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
IonPage,
|
||||||
|
IonContent,
|
||||||
|
IonHeader,
|
||||||
|
IonToolbar,
|
||||||
|
IonTitle,
|
||||||
|
IonButtons,
|
||||||
|
IonButton,
|
||||||
|
IonIcon,
|
||||||
|
IonSpinner,
|
||||||
|
IonItem,
|
||||||
|
IonLabel,
|
||||||
|
IonInput,
|
||||||
|
IonTextarea,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { chevronBackOutline, saveOutline, trashOutline } from 'ionicons/icons';
|
||||||
|
|
||||||
|
const AdminNewsForm: React.FC = () => {
|
||||||
|
const history = useHistory();
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const isEdit = !!id && id !== 'new';
|
||||||
|
const { user, profile } = useAuth();
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [initialLoading, setInitialLoading] = useState(isEdit);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const [title, setTitle] = useState('');
|
||||||
|
const [content, setContent] = useState('');
|
||||||
|
const [imageUrl, setImageUrl] = useState('');
|
||||||
|
|
||||||
|
const showError = (msg: string) => {
|
||||||
|
setError(msg);
|
||||||
|
setTimeout(() => setError(null), 4000);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (profile?.role !== 'admin') {
|
||||||
|
history.replace('/profile');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEdit) {
|
||||||
|
loadNewsItem();
|
||||||
|
}
|
||||||
|
}, [profile, isEdit]);
|
||||||
|
|
||||||
|
const loadNewsItem = async () => {
|
||||||
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('news')
|
||||||
|
.select('*')
|
||||||
|
.eq('id', id)
|
||||||
|
.single();
|
||||||
|
if (error) throw error;
|
||||||
|
if (data) {
|
||||||
|
setTitle(data.title);
|
||||||
|
setContent(data.content);
|
||||||
|
setImageUrl(data.image_url || '');
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
showError(err.message);
|
||||||
|
} finally {
|
||||||
|
setInitialLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
if (!title.trim() || !content.trim()) {
|
||||||
|
showError('Title and content are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
if (isEdit) {
|
||||||
|
const { error } = await supabase
|
||||||
|
.from('news')
|
||||||
|
.update({
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
image_url: imageUrl.trim() || null,
|
||||||
|
})
|
||||||
|
.eq('id', id);
|
||||||
|
if (error) throw error;
|
||||||
|
} else {
|
||||||
|
const { error } = await supabase.from('news').insert({
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
image_url: imageUrl.trim() || null,
|
||||||
|
created_by: user!.id,
|
||||||
|
});
|
||||||
|
if (error) throw error;
|
||||||
|
}
|
||||||
|
history.goBack();
|
||||||
|
} catch (err: any) {
|
||||||
|
showError(err.message);
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = async () => {
|
||||||
|
if (!window.confirm('Delete this news item?')) return;
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const { error } = await supabase.from('news').delete().eq('id', id);
|
||||||
|
if (error) throw error;
|
||||||
|
history.goBack();
|
||||||
|
} catch (err: any) {
|
||||||
|
showError(err.message);
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (initialLoading) {
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton onClick={() => history.goBack()}>
|
||||||
|
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
<IonContent style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
marginTop: '40px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSpinner name="crescent" />
|
||||||
|
</div>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton onClick={() => history.goBack()}>
|
||||||
|
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
<IonTitle style={{ fontWeight: '700', fontSize: '18px' }}>
|
||||||
|
{isEdit ? 'Edit News' : 'Create News'}
|
||||||
|
</IonTitle>
|
||||||
|
{isEdit && (
|
||||||
|
<IonButtons slot="end">
|
||||||
|
<IonButton onClick={handleDelete} color="danger">
|
||||||
|
<IonIcon icon={trashOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
)}
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
|
||||||
|
<IonContent style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<div style={{ padding: '20px', maxWidth: '600px', margin: '0 auto' }}>
|
||||||
|
{error && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#fee2e2',
|
||||||
|
color: '#991b1b',
|
||||||
|
padding: '12px',
|
||||||
|
borderRadius: '8px',
|
||||||
|
fontSize: '14px',
|
||||||
|
marginBottom: '20px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '20px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '16px',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#4b5563',
|
||||||
|
marginBottom: '8px',
|
||||||
|
textTransform: 'uppercase',
|
||||||
|
letterSpacing: '0.05em',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Title
|
||||||
|
</label>
|
||||||
|
<IonItem
|
||||||
|
lines="none"
|
||||||
|
style={{
|
||||||
|
'--background': '#f9faf9',
|
||||||
|
'--border-radius': '12px',
|
||||||
|
'--padding-start': '16px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonInput
|
||||||
|
value={title}
|
||||||
|
onIonChange={(e) => setTitle(e.detail.value!)}
|
||||||
|
placeholder="Enter news title"
|
||||||
|
style={{ fontWeight: '500' }}
|
||||||
|
/>
|
||||||
|
</IonItem>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#4b5563',
|
||||||
|
marginBottom: '8px',
|
||||||
|
textTransform: 'uppercase',
|
||||||
|
letterSpacing: '0.05em',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Image URL (Optional)
|
||||||
|
</label>
|
||||||
|
<IonItem
|
||||||
|
lines="none"
|
||||||
|
style={{
|
||||||
|
'--background': '#f9faf9',
|
||||||
|
'--border-radius': '12px',
|
||||||
|
'--padding-start': '16px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonInput
|
||||||
|
value={imageUrl}
|
||||||
|
onIonChange={(e) => setImageUrl(e.detail.value!)}
|
||||||
|
placeholder="https://example.com/image.jpg"
|
||||||
|
/>
|
||||||
|
</IonItem>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#4b5563',
|
||||||
|
marginBottom: '8px',
|
||||||
|
textTransform: 'uppercase',
|
||||||
|
letterSpacing: '0.05em',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Content
|
||||||
|
</label>
|
||||||
|
<IonItem
|
||||||
|
lines="none"
|
||||||
|
style={{
|
||||||
|
'--background': '#f9faf9',
|
||||||
|
'--border-radius': '12px',
|
||||||
|
'--padding-start': '16px',
|
||||||
|
alignItems: 'flex-start',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonTextarea
|
||||||
|
value={content}
|
||||||
|
onIonChange={(e) => setContent(e.detail.value!)}
|
||||||
|
placeholder="Write your news update here..."
|
||||||
|
autoGrow
|
||||||
|
style={{ minHeight: '150px' }}
|
||||||
|
/>
|
||||||
|
</IonItem>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={handleSave}
|
||||||
|
disabled={loading}
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
background: '#2f6b4f',
|
||||||
|
color: '#ffffff',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '16px',
|
||||||
|
fontSize: '16px',
|
||||||
|
fontWeight: '600',
|
||||||
|
marginTop: '24px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: '8px',
|
||||||
|
cursor: loading ? 'not-allowed' : 'pointer',
|
||||||
|
opacity: loading ? 0.7 : 1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<IonSpinner
|
||||||
|
name="crescent"
|
||||||
|
style={{ width: '24px', height: '24px' }}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<IonIcon icon={saveOutline} />
|
||||||
|
Save News
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AdminNewsForm;
|
||||||
@@ -1,111 +1,104 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import {
|
import {
|
||||||
IonPage,
|
IonPage,
|
||||||
IonContent,
|
IonContent,
|
||||||
IonSpinner,
|
IonSpinner,
|
||||||
IonIcon,
|
|
||||||
useIonViewWillEnter,
|
useIonViewWillEnter,
|
||||||
} from '@ionic/react';
|
} from '@ionic/react';
|
||||||
import { eyeOutline, eyeOffOutline } from 'ionicons/icons';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
import { useProfileLoader } from '../hooks/useProfileLoader';
|
|
||||||
|
|
||||||
const Auth: React.FC = () => {
|
const Auth: React.FC = () => {
|
||||||
const history = useHistory();
|
const [activeTab, setActiveTab] = useState<'login' | 'register'>('login');
|
||||||
const { user } = useAuth();
|
const [email, setEmail] = useState('');
|
||||||
const { loadProfileAndNavigate } = useProfileLoader();
|
const [password, setPassword] = useState('');
|
||||||
|
|
||||||
const [tab, setTab] = useState<'login' | 'register'>('login');
|
|
||||||
|
|
||||||
const [loginEmail, setLoginEmail] = useState('');
|
|
||||||
const [loginPassword, setLoginPassword] = useState('');
|
|
||||||
const [showLoginPassword, setShowLoginPassword] = useState(false);
|
|
||||||
|
|
||||||
const [registerEmail, setRegisterEmail] = useState('');
|
|
||||||
const [registerPassword, setRegisterPassword] = useState('');
|
|
||||||
const [confirmPassword, setConfirmPassword] = useState('');
|
const [confirmPassword, setConfirmPassword] = useState('');
|
||||||
const [showRegisterPassword, setShowRegisterPassword] = useState(false);
|
|
||||||
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const [overlayVisible, setOverlayVisible] = useState(false);
|
const history = useHistory();
|
||||||
const [overlayError, setOverlayError] = useState(false);
|
const { user, profile } = useAuth();
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
useIonViewWillEnter(() => {
|
||||||
setTab('login');
|
setActiveTab('login');
|
||||||
|
setError(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const loadProfileAndNavigate = () => {
|
||||||
|
if (!user) return;
|
||||||
|
if (profile !== undefined && profile === null) {
|
||||||
|
history.replace('/setup-profile');
|
||||||
|
} else if (profile !== undefined && profile !== null) {
|
||||||
|
history.replace('/home');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user) {
|
if (user) {
|
||||||
loadProfileAndNavigate(setOverlayVisible, setOverlayError);
|
loadProfileAndNavigate();
|
||||||
}
|
}
|
||||||
}, [user, loadProfileAndNavigate]);
|
}, [user, profile]);
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
const showError = (msg: string) => {
|
||||||
setError(msg);
|
setError(msg);
|
||||||
setTimeout(() => setError(''), 4000);
|
setTimeout(() => setError(null), 4000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSignIn = async (e: React.FormEvent) => {
|
const handleSignIn = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setError('');
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
const { error } = await supabase.auth.signInWithPassword({
|
const { error } = await supabase.auth.signInWithPassword({
|
||||||
email: loginEmail,
|
email,
|
||||||
password: loginPassword,
|
password,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
if (error.message.toLowerCase().includes('email not confirmed')) {
|
if (error.message.toLowerCase().includes('email not confirmed')) {
|
||||||
await supabase.auth.resend({ type: 'signup', email: loginEmail });
|
await supabase.auth.resend({ type: 'signup', email });
|
||||||
history.push('/verify-email', { email: loginEmail, resent: true });
|
history.push('/verify-email', { email, resent: true });
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
showError(error.message);
|
showError(error.message);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// keep loading true waiting for user effect
|
// Success: keep loading=true — useEffect above navigates when user arrives in context
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSignUp = async (e: React.FormEvent) => {
|
const handleSignUp = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (registerPassword !== confirmPassword) {
|
if (password !== confirmPassword) {
|
||||||
showError('Passwords do not match');
|
showError('Passwords do not match');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError('');
|
setError(null);
|
||||||
|
const { error } = await supabase.auth.signUp({ email, password });
|
||||||
const { error } = await supabase.auth.signUp({
|
|
||||||
email: registerEmail,
|
|
||||||
password: registerPassword,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
showError(error.message);
|
showError(error.message);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
history.push('/verify-email', { email });
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
history.push('/verify-email', { email: registerEmail });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleForgotPassword = () => {
|
const handleTabChange = (tab: 'login' | 'register') => {
|
||||||
history.push('/forgot-password');
|
setActiveTab(tab);
|
||||||
|
setError(null);
|
||||||
|
if (tab === 'login') {
|
||||||
|
setConfirmPassword('');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IonPage style={{ background: 'var(--color-bg)' }}>
|
<IonPage style={{ background: '#f6f1e8' }}>
|
||||||
<IonContent
|
<IonContent
|
||||||
style={{
|
style={{
|
||||||
'--background': 'var(--color-bg-gradient)',
|
'--background': 'linear-gradient(180deg, #f9f5ee 0%, #f3ede3 100%)',
|
||||||
'--padding-start': '0px',
|
'--padding-start': '0px',
|
||||||
'--padding-end': '0px',
|
'--padding-end': '0px',
|
||||||
'--padding-top': '0px',
|
'--padding-top': '0px',
|
||||||
@@ -119,455 +112,209 @@ const Auth: React.FC = () => {
|
|||||||
minHeight: '100%',
|
minHeight: '100%',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
justifyContent: 'center',
|
|
||||||
gap: '24px',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{/* Welcome header block */}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
margin: '0',
|
background: 'transparent',
|
||||||
|
borderRadius: '0px',
|
||||||
|
padding: '0px',
|
||||||
|
margin: '0 0 24px 0',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
gap: '14px',
|
gap: '8px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<h1
|
||||||
style={{
|
style={{
|
||||||
display: 'inline-flex',
|
margin: 0,
|
||||||
alignItems: 'center',
|
fontSize: '24px',
|
||||||
gap: '10px',
|
|
||||||
alignSelf: 'flex-start',
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
color: 'var(--color-brand)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '8px 14px',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
fontWeight: '700',
|
||||||
letterSpacing: '0.06em',
|
color: '#1f2937',
|
||||||
textTransform: 'uppercase',
|
lineHeight: '1.2',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
QuoteLink
|
EAGLES ASSEMBLY
|
||||||
</div>
|
</h1>
|
||||||
<div
|
<p
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
margin: 0,
|
||||||
flexDirection: 'column',
|
fontSize: '14px',
|
||||||
gap: '8px',
|
fontWeight: '400',
|
||||||
|
color: '#6b7280',
|
||||||
|
lineHeight: '1.5',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
Welcome back to our community app
|
||||||
style={{
|
</p>
|
||||||
fontSize: '18px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
lineHeight: '1.2',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Instant prices.{' '}
|
|
||||||
<span
|
|
||||||
style={{ color: 'var(--color-accent)', fontWeight: '700' }}
|
|
||||||
>
|
|
||||||
Smart decisions.
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '34px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
lineHeight: '1.02',
|
|
||||||
letterSpacing: '-0.03em',
|
|
||||||
maxWidth: '330px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Modern procurement for buyers and suppliers.
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
lineHeight: '1.6',
|
|
||||||
maxWidth: '320px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Send a request, compare real quotes, and move faster with a
|
|
||||||
clean professional workflow.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Auth mode pill switcher */}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
background: 'var(--color-surface)',
|
background: '#ffffff',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '4px',
|
||||||
|
margin: '0 0 20px 0',
|
||||||
|
display: 'flex',
|
||||||
|
gap: '4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
onClick={() => handleTabChange('login')}
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
background: activeTab === 'login' ? '#2f6b4f' : 'transparent',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '12px 18px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: activeTab === 'login' ? '#ffffff' : '#6b7280',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Login
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => handleTabChange('register')}
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
background:
|
||||||
|
activeTab === 'register' ? '#2f6b4f' : 'transparent',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '12px 18px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: activeTab === 'register' ? '#ffffff' : '#6b7280',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Register
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Form card */}
|
||||||
|
<form
|
||||||
|
onSubmit={activeTab === 'login' ? handleSignIn : handleSignUp}
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
borderRadius: '24px',
|
borderRadius: '24px',
|
||||||
padding: '24px',
|
padding: '24px',
|
||||||
margin: '0',
|
margin: '0 0 16px 0',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
gap: '20px',
|
gap: '16px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div>
|
<input
|
||||||
<div
|
type="email"
|
||||||
style={{
|
placeholder="Email address"
|
||||||
fontSize: '22px',
|
value={email}
|
||||||
fontWeight: '700',
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
color: 'var(--color-text-primary)',
|
required
|
||||||
lineHeight: '1.15',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{tab === 'login' ? 'Welcome back' : 'Create your account'}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
lineHeight: '1.55',
|
|
||||||
marginTop: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{tab === 'login'
|
|
||||||
? 'Sign in to manage requests and supplier quotations.'
|
|
||||||
: 'Join QuoteLink to start sending or responding to RFQs.'}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
background: '#eef2ec',
|
||||||
background: 'var(--color-surface-raised)',
|
border: 'none',
|
||||||
borderRadius: '999px',
|
borderRadius: '12px',
|
||||||
padding: '4px',
|
padding: '0 14px',
|
||||||
|
height: '48px',
|
||||||
|
fontSize: '15px',
|
||||||
|
color: '#1f2937',
|
||||||
|
outline: 'none',
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
<button
|
<input
|
||||||
onClick={() => setTab('login')}
|
type="password"
|
||||||
|
placeholder="Password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
required
|
||||||
|
style={{
|
||||||
|
background: '#eef2ec',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '0 14px',
|
||||||
|
height: '48px',
|
||||||
|
fontSize: '15px',
|
||||||
|
color: '#1f2937',
|
||||||
|
outline: 'none',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{activeTab === 'register' && (
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
placeholder="Confirm password"
|
||||||
|
value={confirmPassword}
|
||||||
|
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||||
|
required
|
||||||
style={{
|
style={{
|
||||||
flex: 1,
|
background: '#eef2ec',
|
||||||
background:
|
|
||||||
tab === 'login' ? 'var(--color-brand)' : 'transparent',
|
|
||||||
color:
|
|
||||||
tab === 'login' ? '#ffffff' : 'var(--color-brand-strong)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '12px 18px',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
border: 'none',
|
border: 'none',
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Log In
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={() => setTab('register')}
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
background:
|
|
||||||
tab === 'register' ? 'var(--color-brand)' : 'transparent',
|
|
||||||
color:
|
|
||||||
tab === 'register'
|
|
||||||
? '#ffffff'
|
|
||||||
: 'var(--color-brand-strong)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '12px 18px',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Register
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-danger-soft)',
|
|
||||||
borderRadius: '12px',
|
borderRadius: '12px',
|
||||||
padding: '12px 14px',
|
padding: '0 14px',
|
||||||
fontSize: '13px',
|
height: '48px',
|
||||||
fontWeight: '500',
|
|
||||||
color: 'var(--color-danger-text)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{tab === 'login' ? (
|
|
||||||
<form
|
|
||||||
onSubmit={handleSignIn}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="email"
|
|
||||||
placeholder="you@example.com"
|
|
||||||
value={loginEmail}
|
|
||||||
onChange={(e) => setLoginEmail(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<div style={{ position: 'relative' }}>
|
|
||||||
<input
|
|
||||||
type={showLoginPassword ? 'text' : 'password'}
|
|
||||||
placeholder="Password"
|
|
||||||
value={loginPassword}
|
|
||||||
onChange={(e) => setLoginPassword(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 40px 0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<IonIcon
|
|
||||||
icon={showLoginPassword ? eyeOffOutline : eyeOutline}
|
|
||||||
onClick={() => setShowLoginPassword(!showLoginPassword)}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
right: '14px',
|
|
||||||
top: '14px',
|
|
||||||
fontSize: '20px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={handleForgotPassword}
|
|
||||||
style={{
|
|
||||||
background: 'transparent',
|
|
||||||
border: 'none',
|
|
||||||
padding: '0',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-accent)',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Forgot password?
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={loading}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-brand)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: '#ffffff',
|
|
||||||
cursor: 'pointer',
|
|
||||||
marginTop: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'Sign In'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
) : (
|
|
||||||
<form
|
|
||||||
onSubmit={handleSignUp}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="email"
|
|
||||||
placeholder="you@example.com"
|
|
||||||
value={registerEmail}
|
|
||||||
onChange={(e) => setRegisterEmail(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<div style={{ position: 'relative' }}>
|
|
||||||
<input
|
|
||||||
type={showRegisterPassword ? 'text' : 'password'}
|
|
||||||
placeholder="Create a password"
|
|
||||||
value={registerPassword}
|
|
||||||
onChange={(e) => setRegisterPassword(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 40px 0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
minLength={6}
|
|
||||||
/>
|
|
||||||
<IonIcon
|
|
||||||
icon={showRegisterPassword ? eyeOffOutline : eyeOutline}
|
|
||||||
onClick={() =>
|
|
||||||
setShowRegisterPassword(!showRegisterPassword)
|
|
||||||
}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
right: '14px',
|
|
||||||
top: '14px',
|
|
||||||
fontSize: '20px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div style={{ position: 'relative' }}>
|
|
||||||
<input
|
|
||||||
type={showConfirmPassword ? 'text' : 'password'}
|
|
||||||
placeholder="Confirm password"
|
|
||||||
value={confirmPassword}
|
|
||||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 40px 0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
minLength={6}
|
|
||||||
/>
|
|
||||||
<IonIcon
|
|
||||||
icon={showConfirmPassword ? eyeOffOutline : eyeOutline}
|
|
||||||
onClick={() => setShowConfirmPassword(!showConfirmPassword)}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
right: '14px',
|
|
||||||
top: '14px',
|
|
||||||
fontSize: '20px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={loading}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-brand)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: '#ffffff',
|
|
||||||
cursor: 'pointer',
|
|
||||||
marginTop: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'Create Account'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{overlayVisible && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
background: 'rgba(18, 18, 18, 0.78)',
|
|
||||||
backdropFilter: 'blur(10px)',
|
|
||||||
WebkitBackdropFilter: 'blur(10px)',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
zIndex: 9999,
|
|
||||||
padding: '24px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{overlayError ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
color: 'var(--color-danger-text)',
|
|
||||||
fontSize: '15px',
|
fontSize: '15px',
|
||||||
fontWeight: '600',
|
color: '#1f2937',
|
||||||
textAlign: 'center',
|
outline: 'none',
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Error loading profile. Please restart the app.
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{
|
|
||||||
color: 'var(--color-brand)',
|
|
||||||
width: '28px',
|
|
||||||
height: '28px',
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
<button
|
||||||
)}
|
type="submit"
|
||||||
|
disabled={loading}
|
||||||
|
style={{
|
||||||
|
background: '#2f6b4f',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '16px',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#ffffff',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
marginTop: '8px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<IonSpinner name="dots" color="light" />
|
||||||
|
) : activeTab === 'login' ? (
|
||||||
|
'Sign In'
|
||||||
|
) : (
|
||||||
|
'Create Account'
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{/* Error area */}
|
||||||
|
{error && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'rgba(190, 60, 60, 0.10)',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '12px 14px',
|
||||||
|
margin: '0',
|
||||||
|
display: 'flex',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '13px',
|
||||||
|
fontWeight: '500',
|
||||||
|
color: '#a33b32',
|
||||||
|
lineHeight: '1.4',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,324 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import { useHistory, useParams } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonTitle,
|
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { chevronBackOutline, mailOpenOutline } from 'ionicons/icons';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import QuotationCard from '../components/QuotationCard';
|
|
||||||
|
|
||||||
const BuyerQuoteList: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { id } = useParams<{ id: string }>();
|
|
||||||
|
|
||||||
const [rfqSummary, setRfqSummary] = useState<{
|
|
||||||
title: string;
|
|
||||||
referenceNumber: string;
|
|
||||||
} | null>(null);
|
|
||||||
const [quotes, setQuotes] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
const [sortMode, setSortMode] = useState<'price' | 'supplier'>('price');
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
loadQuotes();
|
|
||||||
});
|
|
||||||
|
|
||||||
const loadQuotes = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
setError('');
|
|
||||||
try {
|
|
||||||
const { data: rfq, error: rfqErr } = await supabase
|
|
||||||
.from('rfqs')
|
|
||||||
.select('title, reference_number')
|
|
||||||
.eq('id', id)
|
|
||||||
.single();
|
|
||||||
if (rfqErr) throw rfqErr;
|
|
||||||
setRfqSummary({
|
|
||||||
title: rfq.title,
|
|
||||||
referenceNumber: rfq.reference_number,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data: qData, error: qErr } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.select(
|
|
||||||
'id, price_amount, delivery_option, status, supplier_id, profiles(full_name, company_name)'
|
|
||||||
)
|
|
||||||
.eq('rfq_id', id);
|
|
||||||
if (qErr) throw qErr;
|
|
||||||
|
|
||||||
const mapped = (qData || []).map((q) => ({
|
|
||||||
id: q.id,
|
|
||||||
priceAmount: q.price_amount,
|
|
||||||
deliveryOption: q.delivery_option,
|
|
||||||
status: q.status,
|
|
||||||
supplierName:
|
|
||||||
q.profiles?.company_name || q.profiles?.full_name || 'Supplier',
|
|
||||||
}));
|
|
||||||
|
|
||||||
setQuotes(mapped);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
setError('Failed to load quotations.');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getSortedQuotes = () => {
|
|
||||||
if (sortMode === 'price') {
|
|
||||||
return [...quotes].sort((a, b) => a.priceAmount - b.priceAmount);
|
|
||||||
} else {
|
|
||||||
return [...quotes].sort((a, b) =>
|
|
||||||
a.supplierName.localeCompare(b.supplierName)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleAcceptQuote = async (quoteId: string) => {
|
|
||||||
try {
|
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
// Update selected quotation to accepted
|
|
||||||
const { error: accErr } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.update({ status: 'accepted', updated_at: new Date().toISOString() })
|
|
||||||
.eq('id', quoteId);
|
|
||||||
if (accErr) throw accErr;
|
|
||||||
|
|
||||||
// Update sibling quotations to declined
|
|
||||||
const { error: decErr } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.update({ status: 'declined', updated_at: new Date().toISOString() })
|
|
||||||
.eq('rfq_id', id)
|
|
||||||
.neq('id', quoteId);
|
|
||||||
if (decErr) throw decErr;
|
|
||||||
|
|
||||||
// Close RFQ
|
|
||||||
const { error: rfqErr } = await supabase
|
|
||||||
.from('rfqs')
|
|
||||||
.update({ status: 'closed', updated_at: new Date().toISOString() })
|
|
||||||
.eq('id', id);
|
|
||||||
if (rfqErr) throw rfqErr;
|
|
||||||
|
|
||||||
await loadQuotes();
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
setError(err.message || 'Failed to accept quote.');
|
|
||||||
setLoading(false);
|
|
||||||
setTimeout(() => setError(''), 4000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDeclineQuote = async (quoteId: string) => {
|
|
||||||
try {
|
|
||||||
setLoading(true);
|
|
||||||
const { error } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.update({ status: 'declined', updated_at: new Date().toISOString() })
|
|
||||||
.eq('id', quoteId);
|
|
||||||
if (error) throw error;
|
|
||||||
|
|
||||||
await loadQuotes();
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
setError(err.message || 'Failed to decline quote.');
|
|
||||||
setLoading(false);
|
|
||||||
setTimeout(() => setError(''), 4000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const sortedQuotes = getSortedQuotes();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage style={{ background: '#f7faf7' }}>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar style={{ '--background': '#f7faf7' }}>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ color: '#14532d' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle
|
|
||||||
style={{ fontSize: '18px', fontWeight: '700', color: '#0f1720' }}
|
|
||||||
>
|
|
||||||
Compare Quotes
|
|
||||||
</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent
|
|
||||||
style={{
|
|
||||||
'--background': '#f7faf7',
|
|
||||||
'--padding-start': '20px',
|
|
||||||
'--padding-end': '20px',
|
|
||||||
'--padding-top': '20px',
|
|
||||||
'--padding-bottom': 'calc(28px + var(--ion-safe-area-bottom))',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading && quotes.length === 0 ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '40px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSpinner name="crescent" style={{ color: '#166534' }} />
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{rfqSummary && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: '#ffffff',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
margin: '0 0 12px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: '#b45309',
|
|
||||||
background: 'rgba(245,158,11,0.14)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '4px 10px',
|
|
||||||
width: 'max-content',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{rfqSummary.referenceNumber}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '16px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: '#0f1720',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{rfqSummary.title}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(239, 68, 68, 0.10)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '500',
|
|
||||||
color: '#b91c1c',
|
|
||||||
marginBottom: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div style={{ margin: '0 0 12px', display: 'flex', gap: '8px' }}>
|
|
||||||
<button
|
|
||||||
onClick={() => setSortMode('price')}
|
|
||||||
style={{
|
|
||||||
background: sortMode === 'price' ? '#166534' : '#ffffff',
|
|
||||||
color: sortMode === 'price' ? '#ffffff' : '#14532d',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '8px 16px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Sort by Price
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={() => setSortMode('supplier')}
|
|
||||||
style={{
|
|
||||||
background: sortMode === 'supplier' ? '#166534' : '#ffffff',
|
|
||||||
color: sortMode === 'supplier' ? '#ffffff' : '#14532d',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '8px 16px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Sort by Supplier
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{sortedQuotes.length > 0 ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{sortedQuotes.map((q) => (
|
|
||||||
<QuotationCard
|
|
||||||
key={q.id}
|
|
||||||
supplierName={q.supplierName}
|
|
||||||
priceLabel={`$${q.priceAmount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`}
|
|
||||||
deliveryOption={q.deliveryOption}
|
|
||||||
status={q.status}
|
|
||||||
onAccept={() => handleAcceptQuote(q.id)}
|
|
||||||
onDecline={() => handleDeclineQuote(q.id)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: '#ffffff',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '28px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
textAlign: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={mailOpenOutline}
|
|
||||||
style={{ fontSize: '48px', color: '#6c7a71' }}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#6c7a71',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
No quotations available yet.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default BuyerQuoteList;
|
|
||||||
@@ -1,343 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
IonIcon,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import {
|
|
||||||
addOutline,
|
|
||||||
searchOutline,
|
|
||||||
optionsOutline,
|
|
||||||
documentTextOutline,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useProfile } from '../contexts/ProfileContext';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import RequestListCard from '../components/RequestListCard';
|
|
||||||
|
|
||||||
interface RFQListItem {
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
referenceNumber: string;
|
|
||||||
status: string;
|
|
||||||
createdAt: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BuyerRequests: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const { profile } = useProfile();
|
|
||||||
|
|
||||||
const [items, setItems] = useState<RFQListItem[]>([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
|
|
||||||
const [searchText, setSearchText] = useState('');
|
|
||||||
const [activeStatus, setActiveStatus] = useState<
|
|
||||||
'all' | 'open' | 'quoted' | 'closed'
|
|
||||||
>('all');
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
loadRequests();
|
|
||||||
});
|
|
||||||
|
|
||||||
const loadRequests = async () => {
|
|
||||||
if (!user || !profile) return;
|
|
||||||
setLoading(true);
|
|
||||||
setError('');
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (profile.role === 'buyer') {
|
|
||||||
const { data, error: err } = await supabase
|
|
||||||
.from('rfqs')
|
|
||||||
.select('*')
|
|
||||||
.eq('buyer_id', user.id)
|
|
||||||
.order('created_at', { ascending: false });
|
|
||||||
if (err) throw err;
|
|
||||||
setItems(
|
|
||||||
data.map((d) => ({
|
|
||||||
id: d.id,
|
|
||||||
title: d.title,
|
|
||||||
referenceNumber: d.reference_number,
|
|
||||||
status: d.status,
|
|
||||||
createdAt: d.created_at,
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const { data, error: err } = await supabase
|
|
||||||
.from('rfq_recipients')
|
|
||||||
.select('id, rfqs!inner(*)')
|
|
||||||
.eq('supplier_id', user.id)
|
|
||||||
.order('created_at', { ascending: false });
|
|
||||||
if (err) throw err;
|
|
||||||
const mapped = (data || []).map((row: any) => ({
|
|
||||||
id: row.rfqs.id,
|
|
||||||
title: row.rfqs.title,
|
|
||||||
referenceNumber: row.rfqs.reference_number,
|
|
||||||
status: row.rfqs.status,
|
|
||||||
createdAt: row.rfqs.created_at,
|
|
||||||
}));
|
|
||||||
setItems(mapped);
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
setError('Failed to load requests.');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const filteredItems = items.filter((item) => {
|
|
||||||
const matchStatus = activeStatus === 'all' || item.status === activeStatus;
|
|
||||||
const searchLower = searchText.toLowerCase();
|
|
||||||
const matchSearch =
|
|
||||||
item.title.toLowerCase().includes(searchLower) ||
|
|
||||||
item.referenceNumber.toLowerCase().includes(searchLower);
|
|
||||||
return matchStatus && matchSearch;
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleResetFilters = () => {
|
|
||||||
setSearchText('');
|
|
||||||
setActiveStatus('all');
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!profile) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage style={{ background: 'var(--color-bg)' }}>
|
|
||||||
<IonContent
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg-gradient)',
|
|
||||||
'--padding-start': '0px',
|
|
||||||
'--padding-end': '0px',
|
|
||||||
'--padding-top': '0px',
|
|
||||||
'--padding-bottom': 'calc(96px + var(--ion-safe-area-bottom))',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
padding: 'calc(16px + var(--ion-safe-area-top, 0px)) 20px 12px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '3px' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '700',
|
|
||||||
letterSpacing: '0.08em',
|
|
||||||
textTransform: 'uppercase',
|
|
||||||
color: 'var(--color-brand)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.role === 'buyer' ? 'Buyer Workspace' : 'Supplier Inbox'}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '24px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.role === 'buyer' ? 'My Requests' : 'Assigned RFQs'}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{profile.role === 'buyer' && (
|
|
||||||
<div
|
|
||||||
onClick={() => history.push('/rfq/new')}
|
|
||||||
style={{
|
|
||||||
width: '40px',
|
|
||||||
height: '40px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
background: 'var(--color-brand)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
cursor: 'pointer',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={addOutline}
|
|
||||||
style={{ color: '#ffffff', fontSize: '24px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: '0 20px 12px',
|
|
||||||
background: 'rgba(239, 68, 68, 0.10)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '500',
|
|
||||||
color: '#b91c1c',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div style={{ margin: '0 20px 12px', display: 'flex', gap: '10px' }}>
|
|
||||||
<div style={{ flex: 1, position: 'relative' }}>
|
|
||||||
<IonIcon
|
|
||||||
icon={searchOutline}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
left: '14px',
|
|
||||||
top: '14px',
|
|
||||||
fontSize: '18px',
|
|
||||||
color: 'var(--color-text-tertiary)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="Search by title or reference..."
|
|
||||||
value={searchText}
|
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
border: 'none',
|
|
||||||
padding: '0 16px 0 40px',
|
|
||||||
height: '44px',
|
|
||||||
width: '100%',
|
|
||||||
fontSize: '14px',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onClick={handleResetFilters}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
border: 'none',
|
|
||||||
width: '44px',
|
|
||||||
height: '44px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
cursor: 'pointer',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={optionsOutline}
|
|
||||||
style={{ fontSize: '20px', color: 'var(--color-brand)' }}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: '0 20px 16px',
|
|
||||||
display: 'flex',
|
|
||||||
gap: '8px',
|
|
||||||
overflowX: 'auto',
|
|
||||||
paddingBottom: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{(['all', 'open', 'quoted', 'closed'] as const).map((status) => (
|
|
||||||
<button
|
|
||||||
key={status}
|
|
||||||
onClick={() => setActiveStatus(status)}
|
|
||||||
style={{
|
|
||||||
background:
|
|
||||||
activeStatus === status
|
|
||||||
? 'var(--color-brand)'
|
|
||||||
: 'var(--color-surface)',
|
|
||||||
color:
|
|
||||||
activeStatus === status
|
|
||||||
? '#ffffff'
|
|
||||||
: 'var(--color-brand-strong)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '8px 16px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
textTransform: 'capitalize',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{status}
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{loading ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: '0 20px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSpinner name="crescent" style={{ color: '#166534' }} />
|
|
||||||
</div>
|
|
||||||
) : filteredItems.length > 0 ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: '0 20px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{filteredItems.map((item) => (
|
|
||||||
<RequestListCard
|
|
||||||
key={item.id}
|
|
||||||
title={item.title}
|
|
||||||
subtitle={new Date(item.createdAt).toLocaleDateString()}
|
|
||||||
referenceNumber={item.referenceNumber}
|
|
||||||
status={item.status}
|
|
||||||
onClick={() => history.push(`/rfq/${item.id}`)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: '0 20px',
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '28px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
textAlign: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={documentTextOutline}
|
|
||||||
style={{ fontSize: '48px', color: 'var(--color-text-tertiary)' }}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
No requests found.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default BuyerRequests;
|
|
||||||
@@ -1,309 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonTitle,
|
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { chevronBackOutline } from 'ionicons/icons';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { useProfile } from '../contexts/ProfileContext';
|
|
||||||
import { Preferences } from '@capacitor/preferences';
|
|
||||||
|
|
||||||
const EditProfile: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const { profile, setProfile } = useProfile();
|
|
||||||
|
|
||||||
const [fullName, setFullName] = useState('');
|
|
||||||
const [companyName, setCompanyName] = useState('');
|
|
||||||
const [phone, setPhone] = useState('');
|
|
||||||
const [city, setCity] = useState('');
|
|
||||||
const [saving, setSaving] = useState(false);
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (profile) {
|
|
||||||
setFullName(profile.full_name || '');
|
|
||||||
setCompanyName(profile.company_name || '');
|
|
||||||
setPhone(profile.phone || '');
|
|
||||||
setCity(profile.city || '');
|
|
||||||
}
|
|
||||||
}, [profile]);
|
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
|
||||||
setError(msg);
|
|
||||||
setTimeout(() => setError(''), 4000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSaveProfile = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (!user || !profile) return;
|
|
||||||
if (!fullName) {
|
|
||||||
showError('Please enter your full name');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setSaving(true);
|
|
||||||
setError('');
|
|
||||||
|
|
||||||
const updates = {
|
|
||||||
full_name: fullName,
|
|
||||||
company_name: companyName || null,
|
|
||||||
phone: phone || null,
|
|
||||||
city: city || null,
|
|
||||||
updated_at: new Date().toISOString(),
|
|
||||||
};
|
|
||||||
|
|
||||||
const { error: updateError } = await supabase
|
|
||||||
.from('profiles')
|
|
||||||
.update(updates)
|
|
||||||
.eq('id', user.id);
|
|
||||||
|
|
||||||
if (updateError) {
|
|
||||||
showError(updateError.message);
|
|
||||||
setSaving(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedProfile = { ...profile, ...updates };
|
|
||||||
setProfile(updatedProfile);
|
|
||||||
await Preferences.set({
|
|
||||||
key: `profile_${user.id}`,
|
|
||||||
value: JSON.stringify(updatedProfile),
|
|
||||||
});
|
|
||||||
|
|
||||||
setSaving(false);
|
|
||||||
history.goBack();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage style={{ background: 'var(--color-bg)' }}>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar
|
|
||||||
style={{ '--background': 'var(--color-bg)' } as React.CSSProperties}
|
|
||||||
>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ color: 'var(--color-brand-strong)' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle
|
|
||||||
style={{
|
|
||||||
fontSize: '18px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Edit Profile
|
|
||||||
</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg)',
|
|
||||||
'--padding-start': '20px',
|
|
||||||
'--padding-end': '20px',
|
|
||||||
'--padding-top': '20px',
|
|
||||||
'--padding-bottom': 'calc(28px + var(--ion-safe-area-bottom))',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '24px',
|
|
||||||
margin: '0',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '18px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-danger-soft)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '500',
|
|
||||||
color: 'var(--color-danger-text)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<form
|
|
||||||
onSubmit={handleSaveProfile}
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '6px' }}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Full Name
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="e.g. John Doe"
|
|
||||||
value={fullName}
|
|
||||||
onChange={(e) => setFullName(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '6px' }}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Company Name
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="e.g. BuildRight Supplies"
|
|
||||||
value={companyName}
|
|
||||||
onChange={(e) => setCompanyName(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '6px' }}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
City
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="e.g. Lagos"
|
|
||||||
value={city}
|
|
||||||
onChange={(e) => setCity(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '6px' }}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Phone
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="tel"
|
|
||||||
placeholder="e.g. +234 800 000 0000"
|
|
||||||
value={phone}
|
|
||||||
onChange={(e) => setPhone(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={saving || !fullName}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-brand)',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
opacity: saving || !fullName ? 0.7 : 1,
|
|
||||||
marginTop: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{saving ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'Save Changes'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditProfile;
|
|
||||||
@@ -0,0 +1,380 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
IonPage,
|
||||||
|
IonContent,
|
||||||
|
IonHeader,
|
||||||
|
IonToolbar,
|
||||||
|
IonTitle,
|
||||||
|
IonButtons,
|
||||||
|
IonButton,
|
||||||
|
IonIcon,
|
||||||
|
IonSpinner,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import { ChurchEvent } from '../types';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import {
|
||||||
|
chevronBackOutline,
|
||||||
|
createOutline,
|
||||||
|
timeOutline,
|
||||||
|
locationOutline,
|
||||||
|
calendarOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
|
||||||
|
const EventDetail: React.FC = () => {
|
||||||
|
const [event, setEvent] = useState<ChurchEvent | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const history = useHistory();
|
||||||
|
const { profile } = useAuth();
|
||||||
|
|
||||||
|
const loadEvent = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
const { data, error: fetchError } = await supabase
|
||||||
|
.from('events')
|
||||||
|
.select('*, event_categories(*)')
|
||||||
|
.eq('id', id)
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (fetchError) {
|
||||||
|
setError(fetchError.message);
|
||||||
|
setEvent(null);
|
||||||
|
} else {
|
||||||
|
setEvent(data as ChurchEvent);
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadEvent();
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
const goToEdit = () => {
|
||||||
|
if (!event) return;
|
||||||
|
history.push(`/admin/events/${event.id}/edit`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isAdmin = profile?.role === 'admin';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage style={{ background: '#f5f7f4' }}>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton onClick={() => history.goBack()}>
|
||||||
|
<IonIcon
|
||||||
|
icon={chevronBackOutline}
|
||||||
|
style={{ color: '#1f2937' }}
|
||||||
|
slot="icon-only"
|
||||||
|
/>
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
<IonTitle
|
||||||
|
style={{ fontSize: '18px', fontWeight: '700', color: '#1f2937' }}
|
||||||
|
>
|
||||||
|
Event Detail
|
||||||
|
</IonTitle>
|
||||||
|
{isAdmin && (
|
||||||
|
<IonButtons slot="end">
|
||||||
|
<IonButton onClick={goToEdit}>
|
||||||
|
<IonIcon
|
||||||
|
icon={createOutline}
|
||||||
|
style={{ color: '#2f6b4f', fontSize: '20px' }}
|
||||||
|
slot="icon-only"
|
||||||
|
/>
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
)}
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
|
||||||
|
<IonContent
|
||||||
|
style={{
|
||||||
|
'--background': '#f5f7f4',
|
||||||
|
'--padding-start': '20px',
|
||||||
|
'--padding-end': '20px',
|
||||||
|
'--padding-top': '16px',
|
||||||
|
'--padding-bottom': '24px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
padding: '40px 0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSpinner name="crescent" color="primary" />
|
||||||
|
</div>
|
||||||
|
) : error || !event ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
padding: '12px',
|
||||||
|
background: 'rgba(190,60,60,0.1)',
|
||||||
|
borderRadius: '12px',
|
||||||
|
color: '#a33b32',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{error || 'Event not found'}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{/* Header Detail Card */}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '24px',
|
||||||
|
margin: '0 0 16px 0',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '10px',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ display: 'flex' }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'rgba(47, 107, 79, 0.10)',
|
||||||
|
color: '#2f6b4f',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '5px 12px',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{event.event_categories?.name || 'Event'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<h1
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '24px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{event.title}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Info Rows Card */}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '20px',
|
||||||
|
margin: '0 0 16px 0',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '14px',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* Date Row */}
|
||||||
|
<div
|
||||||
|
style={{ display: 'flex', alignItems: 'center', gap: '12px' }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '36px',
|
||||||
|
height: '36px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: 'rgba(47, 107, 79, 0.12)',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={calendarOutline}
|
||||||
|
style={{ color: '#2f6b4f', fontSize: '18px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#7a847f',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Date
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
marginTop: '2px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{new Date(event.start_at).toLocaleDateString(undefined, {
|
||||||
|
weekday: 'long',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Time Row */}
|
||||||
|
{(() => {
|
||||||
|
const date = new Date(event.start_at);
|
||||||
|
const hasTime =
|
||||||
|
date.getHours() !== 0 || date.getMinutes() !== 0;
|
||||||
|
if (!hasTime) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '36px',
|
||||||
|
height: '36px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: 'rgba(47, 107, 79, 0.12)',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={timeOutline}
|
||||||
|
style={{ color: '#2f6b4f', fontSize: '18px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#7a847f',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Time
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
marginTop: '2px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{date.toLocaleTimeString([], {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
})}
|
||||||
|
{event.end_at &&
|
||||||
|
` - ${new Date(event.end_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
|
||||||
|
{/* Location Row */}
|
||||||
|
<div
|
||||||
|
style={{ display: 'flex', alignItems: 'center', gap: '12px' }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '36px',
|
||||||
|
height: '36px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: 'rgba(47, 107, 79, 0.12)',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={locationOutline}
|
||||||
|
style={{ color: '#2f6b4f', fontSize: '18px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#7a847f',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Location
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
marginTop: '2px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{event.venue}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* About Card */}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '20px',
|
||||||
|
margin: '0 0 16px 0',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '10px',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h3
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '16px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
About
|
||||||
|
</h3>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: '#4b5563',
|
||||||
|
lineHeight: '1.6',
|
||||||
|
whiteSpace: 'pre-wrap',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{event.description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EventDetail;
|
||||||
@@ -0,0 +1,350 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import {
|
||||||
|
IonPage,
|
||||||
|
IonContent,
|
||||||
|
IonSpinner,
|
||||||
|
useIonViewWillEnter,
|
||||||
|
IonIcon,
|
||||||
|
IonRefresher,
|
||||||
|
IonRefresherContent,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import { ChurchEvent } from '../types';
|
||||||
|
import EventListCard from '../components/EventListCard';
|
||||||
|
import {
|
||||||
|
searchOutline,
|
||||||
|
filterOutline,
|
||||||
|
calendarClearOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
|
||||||
|
const Events: React.FC = () => {
|
||||||
|
const [allEvents, setAllEvents] = useState<ChurchEvent[]>([]);
|
||||||
|
const [events, setEvents] = useState<ChurchEvent[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
|
const [activeCategory, setActiveCategory] = useState<
|
||||||
|
'all' | 'weekly' | 'youth' | 'sunday-school'
|
||||||
|
>('all');
|
||||||
|
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const loadEvents = async (event?: any) => {
|
||||||
|
if (!event) setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
now.setDate(now.getDate() - 1);
|
||||||
|
const dateString = now.toISOString();
|
||||||
|
|
||||||
|
const { data, error: fetchError } = await supabase
|
||||||
|
.from('events')
|
||||||
|
.select('*, event_categories(*)')
|
||||||
|
.gte('start_at', dateString)
|
||||||
|
.order('start_at', { ascending: true });
|
||||||
|
|
||||||
|
if (fetchError) {
|
||||||
|
setError(fetchError.message);
|
||||||
|
setAllEvents([]);
|
||||||
|
setEvents([]);
|
||||||
|
} else {
|
||||||
|
const fetched = data as ChurchEvent[];
|
||||||
|
setAllEvents(fetched);
|
||||||
|
applyFilters(fetched, activeCategory, searchTerm);
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
if (event) {
|
||||||
|
event.detail.complete();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useIonViewWillEnter(() => {
|
||||||
|
loadEvents();
|
||||||
|
});
|
||||||
|
|
||||||
|
const applyFilters = (
|
||||||
|
source: ChurchEvent[],
|
||||||
|
category: 'all' | 'weekly' | 'youth' | 'sunday-school',
|
||||||
|
search: string
|
||||||
|
) => {
|
||||||
|
let filtered = [...source];
|
||||||
|
|
||||||
|
if (category === 'weekly') {
|
||||||
|
filtered = filtered.filter((e) => e.event_categories?.slug === 'weekly');
|
||||||
|
} else if (category === 'youth') {
|
||||||
|
filtered = filtered.filter(
|
||||||
|
(e) => e.event_categories?.slug === 'youth' || e.audience === 'youth'
|
||||||
|
);
|
||||||
|
} else if (category === 'sunday-school') {
|
||||||
|
filtered = filtered.filter(
|
||||||
|
(e) => e.event_categories?.slug === 'sunday-school'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (search.trim()) {
|
||||||
|
const term = search.toLowerCase();
|
||||||
|
filtered = filtered.filter(
|
||||||
|
(e) =>
|
||||||
|
e.title.toLowerCase().includes(term) ||
|
||||||
|
e.description.toLowerCase().includes(term) ||
|
||||||
|
e.venue.toLowerCase().includes(term)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setEvents(filtered);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCategoryChange = (
|
||||||
|
category: 'all' | 'weekly' | 'youth' | 'sunday-school'
|
||||||
|
) => {
|
||||||
|
setActiveCategory(category);
|
||||||
|
applyFilters(allEvents, category, searchTerm);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSearchChange = (val: string) => {
|
||||||
|
setSearchTerm(val);
|
||||||
|
applyFilters(allEvents, activeCategory, val);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openEvent = (id: string) => {
|
||||||
|
history.push(`/event/${id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage style={{ background: '#f5f7f4' }}>
|
||||||
|
<IonContent
|
||||||
|
style={{
|
||||||
|
'--background': '#f5f7f4',
|
||||||
|
'--padding-start': '0px',
|
||||||
|
'--padding-end': '0px',
|
||||||
|
'--padding-top': '0px',
|
||||||
|
'--padding-bottom': '24px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonRefresher slot="fixed" onIonRefresh={loadEvents}>
|
||||||
|
<IonRefresherContent />
|
||||||
|
</IonRefresher>
|
||||||
|
|
||||||
|
{/* Top Title Row */}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
padding: 'calc(16px + var(--ion-safe-area-top)) 20px 8px',
|
||||||
|
margin: '0',
|
||||||
|
background: 'transparent',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '6px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h1
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '24px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Events
|
||||||
|
</h1>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: '#6b7280',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Discover what's happening at church
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Search Row */}
|
||||||
|
<div style={{ display: 'flex', gap: '8px', margin: '0 20px 12px' }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
height: '44px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
padding: '0 16px',
|
||||||
|
gap: '10px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={searchOutline}
|
||||||
|
style={{ color: '#9aa3a0', fontSize: '18px', flexShrink: 0 }}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Search events..."
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => handleSearchChange(e.target.value)}
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
border: 'none',
|
||||||
|
background: 'transparent',
|
||||||
|
outline: 'none',
|
||||||
|
fontSize: '15px',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
onClick={() => handleCategoryChange('all')}
|
||||||
|
style={{
|
||||||
|
width: '44px',
|
||||||
|
height: '44px',
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '12px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={filterOutline}
|
||||||
|
style={{ color: '#2f6b4f', fontSize: '20px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Category Chips */}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
gap: '8px',
|
||||||
|
margin: '0 20px 12px',
|
||||||
|
overflowX: 'auto',
|
||||||
|
paddingBottom: '4px',
|
||||||
|
WebkitOverflowScrolling: 'touch',
|
||||||
|
scrollbarWidth: 'none',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{['all', 'weekly', 'youth', 'sunday-school'].map((cat) => (
|
||||||
|
<button
|
||||||
|
key={cat}
|
||||||
|
onClick={() => handleCategoryChange(cat as any)}
|
||||||
|
style={{
|
||||||
|
background: activeCategory === cat ? '#2f6b4f' : '#ffffff',
|
||||||
|
color: activeCategory === cat ? '#ffffff' : '#4b5563',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '8px 14px',
|
||||||
|
fontSize: '13px',
|
||||||
|
fontWeight: '600',
|
||||||
|
cursor: 'pointer',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
boxShadow:
|
||||||
|
activeCategory === cat
|
||||||
|
? 'none'
|
||||||
|
: '0 1px 2px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{cat === 'all'
|
||||||
|
? 'All Events'
|
||||||
|
: cat === 'sunday-school'
|
||||||
|
? 'Sunday School'
|
||||||
|
: cat.charAt(0).toUpperCase() + cat.slice(1)}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Main Content */}
|
||||||
|
{loading ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
padding: '40px 0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSpinner name="crescent" color="primary" />
|
||||||
|
</div>
|
||||||
|
) : error ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
margin: '0 20px',
|
||||||
|
padding: '12px',
|
||||||
|
background: 'rgba(190,60,60,0.1)',
|
||||||
|
borderRadius: '12px',
|
||||||
|
color: '#a33b32',
|
||||||
|
fontSize: '13px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
) : events.length > 0 ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '12px',
|
||||||
|
margin: '0 20px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{events.map((event) => (
|
||||||
|
<EventListCard
|
||||||
|
key={event.id}
|
||||||
|
event={event}
|
||||||
|
onClick={() => openEvent(event.id)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
padding: '60px 20px',
|
||||||
|
textAlign: 'center',
|
||||||
|
gap: '12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={calendarClearOutline}
|
||||||
|
style={{ fontSize: '44px', color: '#7a847f' }}
|
||||||
|
/>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: '#6b7280',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
No events match this filter.
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setSearchTerm('');
|
||||||
|
handleCategoryChange('all');
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
background: 'transparent',
|
||||||
|
border: 'none',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#2f6b4f',
|
||||||
|
cursor: 'pointer',
|
||||||
|
marginTop: '4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Show all events
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Events;
|
||||||
@@ -1,177 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonTitle,
|
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { chevronBackOutline } from 'ionicons/icons';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
|
|
||||||
const ForgotPassword: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const [email, setEmail] = useState('');
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
|
||||||
setError(msg);
|
|
||||||
setTimeout(() => setError(''), 4000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRequestReset = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
setLoading(true);
|
|
||||||
setError('');
|
|
||||||
|
|
||||||
const { error } = await supabase.auth.resetPasswordForEmail(email);
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
showError(error.message);
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
history.push('/verify-reset', { email });
|
|
||||||
setLoading(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage style={{ background: '#f7faf7' }}>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar style={{ '--background': '#f7faf7' }}>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ color: '#14532d' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle
|
|
||||||
style={{ fontSize: '18px', fontWeight: '700', color: '#0f1720' }}
|
|
||||||
>
|
|
||||||
Reset Password
|
|
||||||
</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent
|
|
||||||
style={{
|
|
||||||
'--background': '#f7faf7',
|
|
||||||
'--padding-start': '0px',
|
|
||||||
'--padding-end': '0px',
|
|
||||||
'--padding-top': '0px',
|
|
||||||
'--padding-bottom': '0px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: '#ffffff',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '24px',
|
|
||||||
margin: '20px 20px 0',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '18px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div>
|
|
||||||
<h2
|
|
||||||
style={{
|
|
||||||
fontSize: '22px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: '#0f1720',
|
|
||||||
margin: '0 0 8px 0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Forgot password?
|
|
||||||
</h2>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#5f6d63',
|
|
||||||
margin: '0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Enter your email address and we'll send you a 6-digit code to
|
|
||||||
reset your password.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(239, 68, 68, 0.10)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '500',
|
|
||||||
color: '#b91c1c',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<form
|
|
||||||
onSubmit={handleRequestReset}
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="email"
|
|
||||||
placeholder="you@example.com"
|
|
||||||
value={email}
|
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={loading || !email}
|
|
||||||
style={{
|
|
||||||
background: '#166534',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
opacity: loading || !email ? 0.7 : 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'Send Code'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ForgotPassword;
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import {
|
import {
|
||||||
IonPage,
|
IonPage,
|
||||||
IonContent,
|
IonContent,
|
||||||
@@ -7,176 +6,148 @@ import {
|
|||||||
useIonViewWillEnter,
|
useIonViewWillEnter,
|
||||||
IonIcon,
|
IonIcon,
|
||||||
} from '@ionic/react';
|
} from '@ionic/react';
|
||||||
import { documentTextOutline, addOutline, searchOutline } from 'ionicons/icons';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
import { useProfile } from '../contexts/ProfileContext';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
import DashboardMetricCard from '../components/DashboardMetricCard';
|
import { ChurchEvent } from '../types';
|
||||||
import RecentActivityCard from '../components/RecentActivityCard';
|
import EventPreviewCard from '../components/EventPreviewCard';
|
||||||
import { Database } from '../database.types';
|
import HomeStatCard from '../components/HomeStatCard';
|
||||||
|
import {
|
||||||
type RfqRow = Database['public']['Tables']['rfqs']['Row'];
|
calendarOutline,
|
||||||
|
peopleOutline,
|
||||||
|
newspaperOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
|
||||||
const Home: React.FC = () => {
|
const Home: React.FC = () => {
|
||||||
const history = useHistory();
|
const [featuredEvent, setFeaturedEvent] = useState<ChurchEvent | null>(null);
|
||||||
const { user } = useAuth();
|
const [upcomingEvents, setUpcomingEvents] = useState<ChurchEvent[]>([]);
|
||||||
const { profile } = useProfile();
|
const [latestNews, setLatestNews] = useState<any[]>([]);
|
||||||
|
const [weeklyCount, setWeeklyCount] = useState(0);
|
||||||
|
const [youthCount, setYouthCount] = useState(0);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const [rfqSummary, setRfqSummary] = useState({
|
const { profile } = useAuth();
|
||||||
open: 0,
|
const history = useHistory();
|
||||||
quoted: 0,
|
|
||||||
closed: 0,
|
const loadHomeData = async () => {
|
||||||
});
|
setLoading(true);
|
||||||
const [supplierSummary, setSupplierSummary] = useState({
|
setError(null);
|
||||||
assignedOpen: 0,
|
const now = new Date().toISOString();
|
||||||
myQuotes: 0,
|
|
||||||
accepted: 0,
|
const [{ data, error: fetchError }, { data: newsData, error: newsError }] =
|
||||||
});
|
await Promise.all([
|
||||||
const [recentItems, setRecentItems] = useState<any[]>([]);
|
supabase
|
||||||
|
.from('events')
|
||||||
|
.select('*, event_categories(*)')
|
||||||
|
.gte('start_at', now)
|
||||||
|
.order('start_at', { ascending: true })
|
||||||
|
.limit(20),
|
||||||
|
supabase
|
||||||
|
.from('news')
|
||||||
|
.select('*')
|
||||||
|
.order('created_at', { ascending: false })
|
||||||
|
.limit(3),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (newsData) {
|
||||||
|
setLatestNews(newsData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fetchError) {
|
||||||
|
setError(fetchError.message);
|
||||||
|
setFeaturedEvent(null);
|
||||||
|
setUpcomingEvents([]);
|
||||||
|
setWeeklyCount(0);
|
||||||
|
setYouthCount(0);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const allUpcoming = data as ChurchEvent[];
|
||||||
|
if (allUpcoming.length > 0) {
|
||||||
|
const featured = allUpcoming.find((e) => e.is_featured) || allUpcoming[0];
|
||||||
|
setFeaturedEvent(featured);
|
||||||
|
setUpcomingEvents(allUpcoming.slice(0, 4));
|
||||||
|
} else {
|
||||||
|
setFeaturedEvent(null);
|
||||||
|
setUpcomingEvents([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const weekly = allUpcoming.filter(
|
||||||
|
(e) => e.event_categories?.slug === 'weekly'
|
||||||
|
).length;
|
||||||
|
const youth = allUpcoming.filter(
|
||||||
|
(e) => e.audience === 'youth' || e.event_categories?.slug === 'youth'
|
||||||
|
).length;
|
||||||
|
|
||||||
|
setWeeklyCount(weekly);
|
||||||
|
setYouthCount(youth);
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
useIonViewWillEnter(() => {
|
||||||
loadDashboardData();
|
loadHomeData();
|
||||||
});
|
});
|
||||||
|
|
||||||
const loadDashboardData = async () => {
|
const openEventDetail = (id: string) => {
|
||||||
if (!user || !profile) return;
|
history.push(`/event/${id}`);
|
||||||
setLoading(true);
|
|
||||||
setError('');
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (profile.role === 'buyer') {
|
|
||||||
// Aggregate counts
|
|
||||||
const { data: allRfqs, error: countErr } = await supabase
|
|
||||||
.from('rfqs')
|
|
||||||
.select('id, status')
|
|
||||||
.eq('buyer_id', user.id);
|
|
||||||
|
|
||||||
if (countErr) throw countErr;
|
|
||||||
|
|
||||||
let open = 0,
|
|
||||||
quoted = 0,
|
|
||||||
closed = 0;
|
|
||||||
allRfqs?.forEach((r) => {
|
|
||||||
if (r.status === 'open') open++;
|
|
||||||
else if (r.status === 'quoted') quoted++;
|
|
||||||
else if (r.status === 'closed') closed++;
|
|
||||||
});
|
|
||||||
setRfqSummary({ open, quoted, closed });
|
|
||||||
|
|
||||||
// Recent items
|
|
||||||
const { data: recent, error: recentErr } = await supabase
|
|
||||||
.from('rfqs')
|
|
||||||
.select('*')
|
|
||||||
.eq('buyer_id', user.id)
|
|
||||||
.order('created_at', { ascending: false })
|
|
||||||
.limit(5);
|
|
||||||
if (recentErr) throw recentErr;
|
|
||||||
setRecentItems(recent || []);
|
|
||||||
} else {
|
|
||||||
// Supplier
|
|
||||||
const { data: allRecipients, error: recErr } = await supabase
|
|
||||||
.from('rfq_recipients')
|
|
||||||
.select('id, rfqs!inner(id, status)')
|
|
||||||
.eq('supplier_id', user.id);
|
|
||||||
if (recErr) throw recErr;
|
|
||||||
|
|
||||||
let assignedOpen = 0;
|
|
||||||
allRecipients?.forEach((r: any) => {
|
|
||||||
if (r.rfqs && r.rfqs.status === 'open') assignedOpen++;
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data: myQuotes, error: qErr } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.select('id, status')
|
|
||||||
.eq('supplier_id', user.id);
|
|
||||||
if (qErr) throw qErr;
|
|
||||||
|
|
||||||
let accepted = 0;
|
|
||||||
myQuotes?.forEach((q) => {
|
|
||||||
if (q.status === 'accepted') accepted++;
|
|
||||||
});
|
|
||||||
setSupplierSummary({
|
|
||||||
assignedOpen,
|
|
||||||
myQuotes: myQuotes?.length || 0,
|
|
||||||
accepted,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data: recent, error: recentErr } = await supabase
|
|
||||||
.from('rfq_recipients')
|
|
||||||
.select('id, rfqs!inner(*)')
|
|
||||||
.eq('supplier_id', user.id)
|
|
||||||
.order('created_at', { ascending: false })
|
|
||||||
.limit(5);
|
|
||||||
if (recentErr) throw recentErr;
|
|
||||||
|
|
||||||
// Map joined data
|
|
||||||
const mapped = (recent || []).map((r: any) => r.rfqs);
|
|
||||||
setRecentItems(mapped);
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
setError('Failed to load dashboard data.');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePrimaryAction = () => {
|
const goToEvents = () => {
|
||||||
if (profile?.role === 'buyer') {
|
history.push('/events');
|
||||||
history.push('/rfq/new');
|
|
||||||
} else {
|
|
||||||
history.push('/requests');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRecentItemTap = (item: RfqRow) => {
|
const initials = profile?.full_name
|
||||||
history.push(`/rfq/${item.id}`);
|
? profile.full_name
|
||||||
};
|
.split(' ')
|
||||||
|
.map((n) => n[0])
|
||||||
if (!profile) return null;
|
.join('')
|
||||||
|
.substring(0, 2)
|
||||||
|
.toUpperCase()
|
||||||
|
: 'U';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IonPage style={{ background: 'var(--color-bg)' }}>
|
<IonPage style={{ background: 'var(--color-bg)' }}>
|
||||||
<IonContent
|
<IonContent
|
||||||
style={{
|
style={{
|
||||||
'--background': 'var(--color-bg-gradient)',
|
'--background': 'linear-gradient(180deg, #f8f4ef 0%, #f3ece3 100%)',
|
||||||
'--padding-start': '0px',
|
'--padding-start': '0px',
|
||||||
'--padding-end': '0px',
|
'--padding-end': '0px',
|
||||||
'--padding-top': '0px',
|
'--padding-top': '0px',
|
||||||
'--padding-bottom': 'calc(96px + var(--ion-safe-area-bottom))',
|
'--padding-bottom': '24px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{/* Top Content Row */}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
padding: 'calc(16px + var(--ion-safe-area-top, 0px)) 20px 16px',
|
padding: 'calc(16px + var(--ion-safe-area-top)) 20px 12px',
|
||||||
|
margin: '0',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
gap: '12px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '3px' }}>
|
<div>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
fontSize: '13px',
|
fontSize: '12px',
|
||||||
fontWeight: '700',
|
fontWeight: '600',
|
||||||
letterSpacing: '0.08em',
|
color: 'var(--color-text-secondary)',
|
||||||
textTransform: 'uppercase',
|
textTransform: 'uppercase',
|
||||||
color: 'var(--color-brand)',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
QuoteLink
|
Welcome to
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
fontSize: '13px',
|
fontSize: '18px',
|
||||||
fontWeight: '400',
|
fontWeight: '700',
|
||||||
color: 'var(--color-text-tertiary)',
|
color: 'var(--color-text-primary)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Procurement made simpler
|
EAGLES ASSEMBLY
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -184,42 +155,59 @@ const Home: React.FC = () => {
|
|||||||
style={{
|
style={{
|
||||||
width: '40px',
|
width: '40px',
|
||||||
height: '40px',
|
height: '40px',
|
||||||
borderRadius: '999px',
|
borderRadius: '12px',
|
||||||
background: 'var(--color-brand-medium)',
|
background: 'var(--color-brand-soft)',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
cursor: 'pointer',
|
fontSize: '14px',
|
||||||
color: 'var(--color-brand)',
|
|
||||||
fontSize: '16px',
|
|
||||||
fontWeight: '700',
|
fontWeight: '700',
|
||||||
textTransform: 'uppercase',
|
color: 'var(--color-brand)',
|
||||||
flexShrink: 0,
|
cursor: 'pointer',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{profile.full_name.charAt(0)}
|
{initials}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Greeting Widget */}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
margin: '0 20px 18px',
|
background: 'var(--color-surface)',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '22px',
|
||||||
|
margin: '0 20px 12px',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
gap: '5px',
|
gap: '6px',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
fontSize: '26px',
|
display: 'flex',
|
||||||
fontWeight: '400',
|
alignItems: 'baseline',
|
||||||
color: 'var(--color-text-primary)',
|
gap: '6px',
|
||||||
lineHeight: '1.08',
|
flexWrap: 'wrap',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Good to see you,{' '}
|
<span
|
||||||
<span style={{ fontWeight: '700' }}>
|
style={{
|
||||||
{profile.full_name.split(' ')[0]}
|
fontSize: '22px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Hello,
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: '22px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{profile?.full_name?.split(' ')[0] || 'Friend'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -229,237 +217,370 @@ const Home: React.FC = () => {
|
|||||||
color: 'var(--color-text-secondary)',
|
color: 'var(--color-text-secondary)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{profile.role === 'buyer'
|
Here is what's happening at church this week.
|
||||||
? 'Track requests, review supplier pricing, and keep decisions moving.'
|
|
||||||
: 'Review assigned RFQs, send pricing fast, and stay on top of wins.'}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: '0 20px 12px',
|
|
||||||
background: 'var(--color-danger-soft)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '500',
|
|
||||||
color: 'var(--color-danger-text)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-brand-strong)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '22px',
|
|
||||||
margin: '0 20px 12px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '14px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
onClick={handlePrimaryAction}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'flex-start',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '4px' }}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'rgba(255,255,255,0.72)',
|
|
||||||
textTransform: 'uppercase',
|
|
||||||
letterSpacing: '0.05em',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.role === 'buyer' ? 'Active Requests' : 'Assigned RFQs'}
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '34px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#ffffff',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.role === 'buyer'
|
|
||||||
? rfqSummary.open + rfqSummary.quoted
|
|
||||||
: supplierSummary.assignedOpen}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '40px',
|
|
||||||
height: '40px',
|
|
||||||
borderRadius: '14px',
|
|
||||||
background: 'rgba(255,255,255,0.15)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={profile.role === 'buyer' ? addOutline : searchOutline}
|
|
||||||
style={{ color: '#ffffff', fontSize: '24px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-accent)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.role === 'buyer'
|
|
||||||
? 'Create new request →'
|
|
||||||
: 'Browse requests →'}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', gap: '12px', margin: '0 20px 24px' }}>
|
|
||||||
{profile.role === 'buyer' ? (
|
|
||||||
<>
|
|
||||||
<DashboardMetricCard
|
|
||||||
label="Received Quotes"
|
|
||||||
value={rfqSummary.quoted.toString()}
|
|
||||||
hint="Awaiting decision"
|
|
||||||
icon={documentTextOutline}
|
|
||||||
/>
|
|
||||||
<DashboardMetricCard
|
|
||||||
label="Completed"
|
|
||||||
value={rfqSummary.closed.toString()}
|
|
||||||
hint="Past requests"
|
|
||||||
icon={documentTextOutline}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<DashboardMetricCard
|
|
||||||
label="My Quotes"
|
|
||||||
value={supplierSummary.myQuotes.toString()}
|
|
||||||
hint="Submitted"
|
|
||||||
icon={documentTextOutline}
|
|
||||||
/>
|
|
||||||
<DashboardMetricCard
|
|
||||||
label="Accepted"
|
|
||||||
value={supplierSummary.accepted.toString()}
|
|
||||||
hint="Won bids"
|
|
||||||
icon={documentTextOutline}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: '16px 20px 8px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'flex-end',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Recent Activity
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
onClick={() => history.push('/requests')}
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: 'var(--color-brand)',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
See all
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
margin: '0 20px',
|
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
padding: '20px',
|
padding: '40px 0',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IonSpinner
|
<IonSpinner name="crescent" color="primary" />
|
||||||
name="crescent"
|
|
||||||
style={{ color: 'var(--color-brand)' }}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
) : recentItems.length > 0 ? (
|
|
||||||
recentItems.map((item) => (
|
|
||||||
<RecentActivityCard
|
|
||||||
key={item.id}
|
|
||||||
title={item.title}
|
|
||||||
subtitle={new Date(item.created_at).toLocaleDateString()}
|
|
||||||
meta={item.status}
|
|
||||||
onClick={() => handleRecentItemTap(item)}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
) : (
|
) : (
|
||||||
|
<>
|
||||||
|
{/* Feature Upcoming Event Widget */}
|
||||||
|
{featuredEvent && (
|
||||||
|
<div
|
||||||
|
onClick={() => openEventDetail(featuredEvent.id)}
|
||||||
|
style={{
|
||||||
|
background: 'var(--color-brand)',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '22px',
|
||||||
|
margin: '0 20px 12px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '10px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '11px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: 'rgba(255,255,255,0.70)',
|
||||||
|
textTransform: 'uppercase',
|
||||||
|
letterSpacing: '0.5px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Next Up
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '24px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#ffffff',
|
||||||
|
lineHeight: '1.2',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{featuredEvent.title}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '13px',
|
||||||
|
fontWeight: '500',
|
||||||
|
color: 'rgba(255,255,255,0.85)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{new Date(featuredEvent.start_at).toLocaleTimeString([], {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
})}{' '}
|
||||||
|
• {featuredEvent.day_label}
|
||||||
|
</div>
|
||||||
|
<div style={{ marginTop: '4px' }}>
|
||||||
|
<button
|
||||||
|
style={{
|
||||||
|
background: 'rgba(255,255,255,0.16)',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '10px 16px',
|
||||||
|
fontSize: '13px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#ffffff',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
View Details
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Latest News Row (Horizontal Scroll) */}
|
||||||
|
{latestNews.length > 0 && (
|
||||||
|
<div style={{ marginBottom: '24px' }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
padding: '0 20px 12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '16px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Latest News
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
onClick={() => history.push('/news')}
|
||||||
|
style={{
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: 'var(--color-brand)',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
See all
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
overflowX: 'auto',
|
||||||
|
scrollSnapType: 'x mandatory',
|
||||||
|
padding: '0 20px',
|
||||||
|
gap: '12px',
|
||||||
|
scrollbarWidth: 'none',
|
||||||
|
msOverflowStyle: 'none',
|
||||||
|
}}
|
||||||
|
className="hide-scrollbar"
|
||||||
|
>
|
||||||
|
{latestNews.map((news) => (
|
||||||
|
<div
|
||||||
|
key={news.id}
|
||||||
|
onClick={() => history.push(`/news/${news.id}`)}
|
||||||
|
style={{
|
||||||
|
minWidth: '260px',
|
||||||
|
maxWidth: '260px',
|
||||||
|
background: 'var(--color-surface)',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '16px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '12px',
|
||||||
|
scrollSnapAlign: 'start',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{news.image_url ? (
|
||||||
|
<img
|
||||||
|
src={news.image_url}
|
||||||
|
alt=""
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
height: '120px',
|
||||||
|
objectFit: 'cover',
|
||||||
|
borderRadius: '16px',
|
||||||
|
background: 'var(--color-surface-raised)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
height: '120px',
|
||||||
|
borderRadius: '16px',
|
||||||
|
background: 'var(--color-brand-soft)',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={newspaperOutline}
|
||||||
|
style={{
|
||||||
|
color: 'var(--color-brand)',
|
||||||
|
fontSize: '32px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: 'var(--color-text-tertiary)',
|
||||||
|
marginBottom: '4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{new Date(news.created_at).toLocaleDateString(
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
lineHeight: '1.3',
|
||||||
|
display: '-webkit-box',
|
||||||
|
WebkitLineClamp: 2,
|
||||||
|
WebkitBoxOrient: 'vertical',
|
||||||
|
overflow: 'hidden',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{news.title}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<div style={{ minWidth: '8px' }}></div>
|
||||||
|
</div>
|
||||||
|
<style>{`
|
||||||
|
.hide-scrollbar::-webkit-scrollbar { display: none; }
|
||||||
|
`}</style>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Two Stat Widgets */}
|
||||||
|
<div
|
||||||
|
style={{ display: 'flex', gap: '12px', margin: '0 20px 12px' }}
|
||||||
|
>
|
||||||
|
<HomeStatCard
|
||||||
|
label="Weekly"
|
||||||
|
value={weeklyCount.toString()}
|
||||||
|
caption="Upcoming events"
|
||||||
|
icon={calendarOutline}
|
||||||
|
/>
|
||||||
|
<HomeStatCard
|
||||||
|
label="Youth"
|
||||||
|
value={youthCount.toString()}
|
||||||
|
caption="Activities planned"
|
||||||
|
icon={peopleOutline}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Upcoming This Week List */}
|
||||||
|
{upcomingEvents.length > 0 ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#fcf8f0',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '20px',
|
||||||
|
margin: '0 20px 16px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '14px',
|
||||||
|
boxShadow: '0 2px 8px rgba(123, 45, 38, 0.05)',
|
||||||
|
border: '1px solid rgba(176, 122, 58, 0.1)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '16px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: 'var(--color-text-primary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Upcoming Schedule
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
onClick={goToEvents}
|
||||||
|
style={{
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: 'var(--color-brand)',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
See all
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{upcomingEvents.map((event) => (
|
||||||
|
<EventPreviewCard
|
||||||
|
key={event.id}
|
||||||
|
event={event}
|
||||||
|
onClick={() => openEventDetail(event.id)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'var(--color-surface)',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '32px 20px',
|
||||||
|
margin: '0 20px 16px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '12px',
|
||||||
|
textAlign: 'center',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={calendarOutline}
|
||||||
|
style={{
|
||||||
|
fontSize: '40px',
|
||||||
|
color: 'var(--color-text-tertiary)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: 'var(--color-text-secondary)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
No church events have been posted yet.
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={goToEvents}
|
||||||
|
style={{
|
||||||
|
background: 'var(--color-brand-soft)',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '10px 16px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: 'var(--color-brand)',
|
||||||
|
cursor: 'pointer',
|
||||||
|
marginTop: '4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Go to events
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{error && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
margin: '0 20px',
|
margin: '0 20px',
|
||||||
background: 'var(--color-surface)',
|
padding: '12px',
|
||||||
borderRadius: '24px',
|
background: 'rgba(190,60,60,0.1)',
|
||||||
padding: '28px',
|
borderRadius: '12px',
|
||||||
display: 'flex',
|
color: '#a33b32',
|
||||||
flexDirection: 'column',
|
fontSize: '13px',
|
||||||
alignItems: 'center',
|
|
||||||
textAlign: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IonIcon
|
{error}
|
||||||
icon={documentTextOutline}
|
|
||||||
style={{ fontSize: '48px', color: 'var(--color-text-tertiary)' }}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
No recent activity yet.
|
|
||||||
</div>
|
|
||||||
{profile.role === 'buyer' && (
|
|
||||||
<button
|
|
||||||
onClick={handlePrimaryAction}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-brand)',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '10px 20px',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
marginTop: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Create Request
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</IonContent>
|
</IonContent>
|
||||||
|
|||||||
@@ -1,491 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonTitle,
|
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { chevronBackOutline, cameraOutline, closeCircle } from 'ionicons/icons';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import SupplierPickerRow, {
|
|
||||||
SupplierOption,
|
|
||||||
} from '../components/SupplierPickerRow';
|
|
||||||
|
|
||||||
const NewRfq: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
|
|
||||||
const [title, setTitle] = useState('');
|
|
||||||
const [requestText, setRequestText] = useState('');
|
|
||||||
|
|
||||||
const [supplierOptions, setSupplierOptions] = useState<SupplierOption[]>([]);
|
|
||||||
const [selectedSupplierIds, setSelectedSupplierIds] = useState<string[]>([]);
|
|
||||||
const [loadingSuppliers, setLoadingSuppliers] = useState(true);
|
|
||||||
|
|
||||||
const [imageFile, setImageFile] = useState<File | null>(null);
|
|
||||||
const [imagePreviewUrl, setImagePreviewUrl] = useState<string | null>(null);
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadSuppliers();
|
|
||||||
return () => {
|
|
||||||
cleanupPreview();
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const loadSuppliers = async () => {
|
|
||||||
setLoadingSuppliers(true);
|
|
||||||
const { data, error: err } = await supabase
|
|
||||||
.from('profiles')
|
|
||||||
.select('id, full_name, company_name, city')
|
|
||||||
.eq('role', 'supplier')
|
|
||||||
.order('company_name', { ascending: true })
|
|
||||||
.order('full_name', { ascending: true });
|
|
||||||
|
|
||||||
if (!err && data) {
|
|
||||||
setSupplierOptions(data);
|
|
||||||
}
|
|
||||||
setLoadingSuppliers(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const cleanupPreview = () => {
|
|
||||||
if (imagePreviewUrl) {
|
|
||||||
URL.revokeObjectURL(imagePreviewUrl);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
if (e.target.files && e.target.files.length > 0) {
|
|
||||||
const file = e.target.files[0];
|
|
||||||
setImageFile(file);
|
|
||||||
cleanupPreview();
|
|
||||||
setImagePreviewUrl(URL.createObjectURL(file));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggleSupplier = (id: string) => {
|
|
||||||
if (selectedSupplierIds.includes(id)) {
|
|
||||||
setSelectedSupplierIds(selectedSupplierIds.filter((s) => s !== id));
|
|
||||||
} else {
|
|
||||||
if (selectedSupplierIds.length >= 5) {
|
|
||||||
showError('Select up to 5 suppliers');
|
|
||||||
} else {
|
|
||||||
setSelectedSupplierIds([...selectedSupplierIds, id]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
|
||||||
setError(msg);
|
|
||||||
setTimeout(() => setError(''), 4000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCreateRfq = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (!user) return;
|
|
||||||
if (!requestText.trim()) {
|
|
||||||
showError('Please describe your request.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (selectedSupplierIds.length === 0) {
|
|
||||||
showError('Please select at least 1 supplier.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(true);
|
|
||||||
setError('');
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 1. Get Reference Number
|
|
||||||
const { data: refData, error: refError } =
|
|
||||||
await supabase.functions.invoke('create-rfq-reference', {
|
|
||||||
body: {},
|
|
||||||
});
|
|
||||||
if (refError || !refData?.referenceNumber) {
|
|
||||||
throw new Error('Failed to generate reference number.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const referenceNumber = refData.referenceNumber;
|
|
||||||
const derivedTitle =
|
|
||||||
title.trim() || requestText.trim().substring(0, 30) + '...';
|
|
||||||
|
|
||||||
// 2. Insert RFQ
|
|
||||||
const { data: rfq, error: rfqError } = await supabase
|
|
||||||
.from('rfqs')
|
|
||||||
.insert({
|
|
||||||
buyer_id: user.id,
|
|
||||||
reference_number: referenceNumber,
|
|
||||||
title: derivedTitle,
|
|
||||||
request_text: requestText.trim(),
|
|
||||||
status: 'open',
|
|
||||||
})
|
|
||||||
.select('id')
|
|
||||||
.single();
|
|
||||||
|
|
||||||
if (rfqError) throw rfqError;
|
|
||||||
|
|
||||||
// 3. Upload Image if present
|
|
||||||
if (imageFile) {
|
|
||||||
const filePath = `${user.id}/${rfq.id}/${Date.now()}-${imageFile.name}`;
|
|
||||||
const { error: uploadError } = await supabase.storage
|
|
||||||
.from('rfq-images')
|
|
||||||
.upload(filePath, imageFile);
|
|
||||||
|
|
||||||
if (uploadError) throw uploadError;
|
|
||||||
|
|
||||||
const { error: imgMetaError } = await supabase
|
|
||||||
.from('rfq_images')
|
|
||||||
.insert({
|
|
||||||
rfq_id: rfq.id,
|
|
||||||
owner_id: user.id,
|
|
||||||
storage_path: filePath,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (imgMetaError) throw imgMetaError;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Insert Recipients
|
|
||||||
const recipientsToInsert = selectedSupplierIds.map((sid) => ({
|
|
||||||
rfq_id: rfq.id,
|
|
||||||
supplier_id: sid,
|
|
||||||
}));
|
|
||||||
const { error: recError } = await supabase
|
|
||||||
.from('rfq_recipients')
|
|
||||||
.insert(recipientsToInsert);
|
|
||||||
|
|
||||||
if (recError) throw recError;
|
|
||||||
|
|
||||||
// 5. Navigate
|
|
||||||
history.replace(`/rfq/${rfq.id}`);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
showError(err.message || 'Failed to create RFQ.');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage style={{ background: '#f7faf7' }}>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar style={{ '--background': '#f7faf7' }}>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ color: '#14532d' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle
|
|
||||||
style={{ fontSize: '18px', fontWeight: '700', color: '#0f1720' }}
|
|
||||||
>
|
|
||||||
New Request
|
|
||||||
</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent
|
|
||||||
style={{
|
|
||||||
'--background': '#f7faf7',
|
|
||||||
'--padding-start': '20px',
|
|
||||||
'--padding-end': '20px',
|
|
||||||
'--padding-top': '20px',
|
|
||||||
'--padding-bottom': 'calc(28px + var(--ion-safe-area-bottom))',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ margin: '0 0 16px', background: 'transparent' }}>
|
|
||||||
<h1
|
|
||||||
style={{
|
|
||||||
fontSize: '26px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: '#0f1720',
|
|
||||||
margin: '0 0 4px 0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Request Quote
|
|
||||||
</h1>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#5f6d63',
|
|
||||||
margin: '0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Describe what you need and select suppliers.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(239, 68, 68, 0.10)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '500',
|
|
||||||
color: '#b91c1c',
|
|
||||||
marginBottom: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<form
|
|
||||||
onSubmit={handleCreateRfq}
|
|
||||||
style={{
|
|
||||||
background: '#ffffff',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '24px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '18px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="Title (e.g. 100 Bricks + Cement)"
|
|
||||||
value={title}
|
|
||||||
onChange={(e) => setTitle(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<textarea
|
|
||||||
placeholder="Describe your request..."
|
|
||||||
value={requestText}
|
|
||||||
onChange={(e) => setRequestText(e.target.value)}
|
|
||||||
rows={4}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '14px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
resize: 'vertical',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
|
|
||||||
<label
|
|
||||||
style={{ fontSize: '13px', fontWeight: '600', color: '#0f1720' }}
|
|
||||||
>
|
|
||||||
Site Photo or Reference (Optional)
|
|
||||||
</label>
|
|
||||||
{imagePreviewUrl ? (
|
|
||||||
<div style={{ position: 'relative', width: 'max-content' }}>
|
|
||||||
<img
|
|
||||||
src={imagePreviewUrl}
|
|
||||||
alt="Preview"
|
|
||||||
style={{
|
|
||||||
width: '88px',
|
|
||||||
height: '88px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
objectFit: 'cover',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<IonIcon
|
|
||||||
icon={closeCircle}
|
|
||||||
onClick={() => {
|
|
||||||
setImageFile(null);
|
|
||||||
setImagePreviewUrl(null);
|
|
||||||
}}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: '-8px',
|
|
||||||
right: '-8px',
|
|
||||||
fontSize: '24px',
|
|
||||||
color: '#b91c1c',
|
|
||||||
cursor: 'pointer',
|
|
||||||
background: '#fff',
|
|
||||||
borderRadius: '50%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
background: '#edf4ee',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '18px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '16px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '48px',
|
|
||||||
height: '48px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
background: 'rgba(22,101,52,0.12)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={cameraOutline}
|
|
||||||
style={{ color: '#166534', fontSize: '24px' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: '#166534',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Add a photo
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#6c7a71',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Tap to browse
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
accept="image/*"
|
|
||||||
onChange={handleFileChange}
|
|
||||||
style={{ display: 'none' }}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'flex-end',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: '#0f1720',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Select Suppliers (Up to 5)
|
|
||||||
</label>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#6c7a71',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{selectedSupplierIds.length}/5 selected
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: '#f9fbf9',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '14px',
|
|
||||||
maxHeight: '200px',
|
|
||||||
overflowY: 'auto',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loadingSuppliers ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '10px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSpinner name="crescent" style={{ color: '#166534' }} />
|
|
||||||
</div>
|
|
||||||
) : supplierOptions.length > 0 ? (
|
|
||||||
supplierOptions.map((supplier) => (
|
|
||||||
<SupplierPickerRow
|
|
||||||
key={supplier.id}
|
|
||||||
supplier={supplier}
|
|
||||||
selected={selectedSupplierIds.includes(supplier.id)}
|
|
||||||
onToggle={() => toggleSupplier(supplier.id)}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
color: '#6c7a71',
|
|
||||||
textAlign: 'center',
|
|
||||||
padding: '10px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
No suppliers found.
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={loading || selectedSupplierIds.length === 0}
|
|
||||||
style={{
|
|
||||||
background: '#166534',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
opacity: loading || selectedSupplierIds.length === 0 ? 0.7 : 1,
|
|
||||||
marginTop: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'Send Request'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default NewRfq;
|
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import {
|
||||||
|
IonPage,
|
||||||
|
IonContent,
|
||||||
|
IonHeader,
|
||||||
|
IonToolbar,
|
||||||
|
IonTitle,
|
||||||
|
IonSpinner,
|
||||||
|
useIonViewWillEnter,
|
||||||
|
IonRefresher,
|
||||||
|
IonRefresherContent,
|
||||||
|
IonButtons,
|
||||||
|
IonButton,
|
||||||
|
IonIcon,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { NewsItem } from '../types';
|
||||||
|
import { addOutline, newspaperOutline } from 'ionicons/icons';
|
||||||
|
|
||||||
|
const News: React.FC = () => {
|
||||||
|
const history = useHistory();
|
||||||
|
const { profile } = useAuth();
|
||||||
|
const [news, setNews] = useState<NewsItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
const fetchNews = async () => {
|
||||||
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('news')
|
||||||
|
.select('*')
|
||||||
|
.order('created_at', { ascending: false });
|
||||||
|
|
||||||
|
if (error) throw error;
|
||||||
|
setNews(data || []);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching news:', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useIonViewWillEnter(() => {
|
||||||
|
fetchNews();
|
||||||
|
});
|
||||||
|
|
||||||
|
const doRefresh = async (event: any) => {
|
||||||
|
await fetchNews();
|
||||||
|
event.detail.complete();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<IonTitle
|
||||||
|
style={{ fontWeight: '700', fontSize: '24px', color: '#1f2937' }}
|
||||||
|
>
|
||||||
|
News
|
||||||
|
</IonTitle>
|
||||||
|
{profile?.role === 'admin' && (
|
||||||
|
<IonButtons slot="end">
|
||||||
|
<IonButton onClick={() => history.push('/admin/news/new')}>
|
||||||
|
<IonIcon icon={addOutline} style={{ color: '#2f6b4f' }} />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
)}
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
|
||||||
|
<IonContent style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<IonRefresher slot="fixed" onIonRefresh={doRefresh}>
|
||||||
|
<IonRefresherContent />
|
||||||
|
</IonRefresher>
|
||||||
|
|
||||||
|
<div style={{ padding: '0 20px 20px' }}>
|
||||||
|
{loading ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
marginTop: '40px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSpinner name="crescent" />
|
||||||
|
</div>
|
||||||
|
) : news.length === 0 ? (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
textAlign: 'center',
|
||||||
|
padding: '60px 20px',
|
||||||
|
color: '#6b7280',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={newspaperOutline}
|
||||||
|
style={{
|
||||||
|
fontSize: '48px',
|
||||||
|
color: '#cbd5e1',
|
||||||
|
marginBottom: '16px',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<p style={{ margin: 0, fontSize: '16px', fontWeight: '500' }}>
|
||||||
|
No news yet.
|
||||||
|
</p>
|
||||||
|
{profile?.role === 'admin' && (
|
||||||
|
<button
|
||||||
|
onClick={() => history.push('/admin/news/new')}
|
||||||
|
style={{
|
||||||
|
background: '#2f6b4f',
|
||||||
|
color: '#fff',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '10px 20px',
|
||||||
|
fontWeight: '600',
|
||||||
|
marginTop: '20px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Create Post
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '16px',
|
||||||
|
paddingTop: '8px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{news.map((item) => (
|
||||||
|
<div
|
||||||
|
key={item.id}
|
||||||
|
onClick={() => history.push(`/news/${item.id}`)}
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '16px',
|
||||||
|
display: 'flex',
|
||||||
|
gap: '16px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.image_url ? (
|
||||||
|
<img
|
||||||
|
src={item.image_url}
|
||||||
|
alt=""
|
||||||
|
style={{
|
||||||
|
width: '80px',
|
||||||
|
height: '80px',
|
||||||
|
borderRadius: '16px',
|
||||||
|
objectFit: 'cover',
|
||||||
|
flexShrink: 0,
|
||||||
|
background: '#f1f5f9',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '80px',
|
||||||
|
height: '80px',
|
||||||
|
borderRadius: '16px',
|
||||||
|
background: 'rgba(47, 107, 79, 0.1)',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={newspaperOutline}
|
||||||
|
style={{ color: '#2f6b4f', fontSize: '28px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 0,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '6px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#9ca3af',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{new Date(item.created_at).toLocaleDateString(undefined, {
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '16px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
lineHeight: '1.3',
|
||||||
|
display: '-webkit-box',
|
||||||
|
WebkitLineClamp: 2,
|
||||||
|
WebkitBoxOrient: 'vertical',
|
||||||
|
overflow: 'hidden',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.title}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default News;
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import {
|
||||||
|
IonPage,
|
||||||
|
IonContent,
|
||||||
|
IonHeader,
|
||||||
|
IonToolbar,
|
||||||
|
IonButtons,
|
||||||
|
IonButton,
|
||||||
|
IonIcon,
|
||||||
|
IonSpinner,
|
||||||
|
useIonViewWillEnter,
|
||||||
|
} from '@ionic/react';
|
||||||
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
|
import { supabase } from '../supabase';
|
||||||
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
|
import { NewsItem } from '../types';
|
||||||
|
import { chevronBackOutline, createOutline } from 'ionicons/icons';
|
||||||
|
|
||||||
|
const NewsDetail: React.FC = () => {
|
||||||
|
const history = useHistory();
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const { profile } = useAuth();
|
||||||
|
const [news, setNews] = useState<NewsItem | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
useIonViewWillEnter(() => {
|
||||||
|
fetchNewsItem();
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchNewsItem = async () => {
|
||||||
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('news')
|
||||||
|
.select('*')
|
||||||
|
.eq('id', id)
|
||||||
|
.single();
|
||||||
|
if (error) throw error;
|
||||||
|
setNews(data);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching news:', err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton onClick={() => history.goBack()}>
|
||||||
|
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
<IonContent style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
marginTop: '40px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSpinner name="crescent" />
|
||||||
|
</div>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!news) {
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton onClick={() => history.goBack()}>
|
||||||
|
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
<IonContent style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<div
|
||||||
|
style={{ textAlign: 'center', marginTop: '60px', color: '#6b7280' }}
|
||||||
|
>
|
||||||
|
News item not found.
|
||||||
|
</div>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader className="ion-no-border">
|
||||||
|
<IonToolbar style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonButton onClick={() => history.goBack()}>
|
||||||
|
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
{profile?.role === 'admin' && (
|
||||||
|
<IonButtons slot="end">
|
||||||
|
<IonButton onClick={() => history.push(`/admin/news/${news.id}`)}>
|
||||||
|
<IonIcon
|
||||||
|
icon={createOutline}
|
||||||
|
slot="icon-only"
|
||||||
|
style={{ color: '#2f6b4f' }}
|
||||||
|
/>
|
||||||
|
</IonButton>
|
||||||
|
</IonButtons>
|
||||||
|
)}
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
|
||||||
|
<IonContent style={{ '--background': '#f5f7f4' }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
padding: '0 20px 40px',
|
||||||
|
maxWidth: '600px',
|
||||||
|
margin: '0 auto',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{news.image_url && (
|
||||||
|
<div style={{ marginBottom: '24px' }}>
|
||||||
|
<img
|
||||||
|
src={news.image_url}
|
||||||
|
alt=""
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
height: '240px',
|
||||||
|
objectFit: 'cover',
|
||||||
|
borderRadius: '24px',
|
||||||
|
background: '#eef2ec',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#2f6b4f',
|
||||||
|
marginBottom: '12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{new Date(news.created_at).toLocaleDateString(undefined, {
|
||||||
|
weekday: 'long',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h1
|
||||||
|
style={{
|
||||||
|
margin: '0 0 24px',
|
||||||
|
fontSize: '28px',
|
||||||
|
fontWeight: '800',
|
||||||
|
color: '#1f2937',
|
||||||
|
lineHeight: '1.2',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{news.title}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '16px',
|
||||||
|
color: '#4b5563',
|
||||||
|
lineHeight: '1.6',
|
||||||
|
whiteSpace: 'pre-wrap',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{news.content}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NewsDetail;
|
||||||
@@ -1,387 +1,518 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
|
import { IonPage, IonContent, IonIcon, IonSpinner } from '@ionic/react';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { IonPage, IonContent, IonSpinner, IonIcon } from '@ionic/react';
|
import { supabase } from '../supabase';
|
||||||
import {
|
|
||||||
createOutline,
|
|
||||||
personOutline,
|
|
||||||
businessOutline,
|
|
||||||
locationOutline,
|
|
||||||
callOutline,
|
|
||||||
moonOutline,
|
|
||||||
sunnyOutline,
|
|
||||||
} from 'ionicons/icons';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
import { useProfile } from '../contexts/ProfileContext';
|
import {
|
||||||
import { Preferences } from '@capacitor/preferences';
|
cameraOutline,
|
||||||
import ProfileInfoRow from '../components/ProfileInfoRow';
|
personOutline,
|
||||||
|
chevronForwardOutline,
|
||||||
|
settingsOutline,
|
||||||
|
helpCircleOutline,
|
||||||
|
} from 'ionicons/icons';
|
||||||
|
|
||||||
const Profile: React.FC = () => {
|
const Profile: React.FC = () => {
|
||||||
const history = useHistory();
|
|
||||||
const { signOut } = useAuth();
|
|
||||||
const { profile, clearProfile, themeMode, setThemeMode } = useProfile();
|
|
||||||
|
|
||||||
const [signingOut, setSigningOut] = useState(false);
|
const [signingOut, setSigningOut] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [uploadingAvatar, setUploadingAvatar] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
const { user, profile, refreshProfile } = useAuth();
|
||||||
setError(msg);
|
const history = useHistory();
|
||||||
setTimeout(() => setError(''), 4000);
|
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||||
};
|
|
||||||
|
|
||||||
const handleSignOut = async () => {
|
const handleSignOut = async () => {
|
||||||
setSigningOut(true);
|
setSigningOut(true);
|
||||||
try {
|
setError(null);
|
||||||
if (profile) {
|
const { error: signOutError } = await supabase.auth.signOut();
|
||||||
await Preferences.remove({ key: `profile_${profile.id}` });
|
if (signOutError) {
|
||||||
}
|
setError(signOutError.message);
|
||||||
await signOut();
|
|
||||||
clearProfile();
|
|
||||||
history.replace('/auth');
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
showError('Failed to sign out.');
|
|
||||||
} finally {
|
|
||||||
setSigningOut(false);
|
setSigningOut(false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
history.replace('/auth');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditProfile = () => {
|
const goToCreateEvent = () => {
|
||||||
history.push('/profile/edit');
|
history.push('/admin/events/new');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleThemeToggle = async () => {
|
const initials = profile?.full_name
|
||||||
await setThemeMode(themeMode === 'dark' ? 'light' : 'dark');
|
? profile.full_name
|
||||||
|
.split(' ')
|
||||||
|
.map((n) => n[0])
|
||||||
|
.join('')
|
||||||
|
.substring(0, 2)
|
||||||
|
.toUpperCase()
|
||||||
|
: 'U';
|
||||||
|
|
||||||
|
const isAdmin = profile?.role === 'admin';
|
||||||
|
const avatarUrl = profile?.avatar_url
|
||||||
|
? `${supabase.storage.from('avatars').getPublicUrl(profile.avatar_url).data.publicUrl}?t=${Date.now()}`
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const showError = (message: string) => {
|
||||||
|
setError(message);
|
||||||
|
setTimeout(() => setError(null), 4000);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!profile) return null;
|
const handleAvatarSelect = async (
|
||||||
|
event: React.ChangeEvent<HTMLInputElement>
|
||||||
|
) => {
|
||||||
|
const file = event.target.files?.[0];
|
||||||
|
if (!file || !user) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setUploadingAvatar(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
const extension = file.name.split('.').pop()?.toLowerCase() || 'jpg';
|
||||||
|
const filePath = `${user.id}/avatar-${Date.now()}.${extension}`;
|
||||||
|
|
||||||
|
const { error: uploadError } = await supabase.storage
|
||||||
|
.from('avatars')
|
||||||
|
.upload(filePath, file);
|
||||||
|
|
||||||
|
if (uploadError) {
|
||||||
|
showError(uploadError.message);
|
||||||
|
setUploadingAvatar(false);
|
||||||
|
event.target.value = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error: profileError } = await supabase
|
||||||
|
.from('profiles')
|
||||||
|
.update({ avatar_url: filePath, updated_at: new Date().toISOString() })
|
||||||
|
.eq('id', user.id);
|
||||||
|
|
||||||
|
if (profileError) {
|
||||||
|
showError(profileError.message);
|
||||||
|
setUploadingAvatar(false);
|
||||||
|
event.target.value = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await refreshProfile();
|
||||||
|
setUploadingAvatar(false);
|
||||||
|
event.target.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IonPage style={{ background: 'var(--color-bg)' }}>
|
<IonPage style={{ background: '#f5f7f4' }}>
|
||||||
<IonContent
|
<IonContent
|
||||||
style={{
|
style={{
|
||||||
'--background': 'var(--color-bg-gradient)',
|
'--background': '#f5f7f4',
|
||||||
'--padding-start': '0px',
|
'--padding-start': '0px',
|
||||||
'--padding-end': '0px',
|
'--padding-end': '0px',
|
||||||
'--padding-top': '0px',
|
'--padding-top': '0px',
|
||||||
'--padding-bottom': 'calc(96px + var(--ion-safe-area-bottom))',
|
'--padding-bottom': '24px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{/* Top Title Row */}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
padding: 'calc(16px + var(--ion-safe-area-top, 0px)) 20px 16px',
|
padding: 'calc(16px + var(--ion-safe-area-top)) 20px 8px',
|
||||||
|
margin: '0',
|
||||||
|
background: 'transparent',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
justifyContent: 'space-between',
|
flexDirection: 'column',
|
||||||
alignItems: 'center',
|
gap: '6px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '3px' }}>
|
<h1
|
||||||
<div
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '24px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Profile
|
||||||
|
</h1>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: '#6b7280',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Manage your account
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Profile Summary Card */}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '20px',
|
||||||
|
margin: '0 20px 12px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'relative',
|
||||||
|
width: '52px',
|
||||||
|
height: '52px',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
onClick={() => fileInputRef.current?.click()}
|
||||||
|
disabled={uploadingAvatar}
|
||||||
style={{
|
style={{
|
||||||
fontSize: '24px',
|
width: '52px',
|
||||||
|
height: '52px',
|
||||||
|
borderRadius: '16px',
|
||||||
|
background: 'rgba(47, 107, 79, 0.12)',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
fontSize: '18px',
|
||||||
fontWeight: '700',
|
fontWeight: '700',
|
||||||
color: 'var(--color-text-primary)',
|
color: '#2f6b4f',
|
||||||
|
flexShrink: 0,
|
||||||
|
border: 'none',
|
||||||
|
padding: 0,
|
||||||
|
overflow: 'hidden',
|
||||||
|
cursor: uploadingAvatar ? 'default' : 'pointer',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Profile
|
{avatarUrl ? (
|
||||||
|
<img
|
||||||
|
src={avatarUrl}
|
||||||
|
alt={profile?.full_name || 'Profile'}
|
||||||
|
style={{ width: '100%', height: '100%', objectFit: 'cover' }}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
initials
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => fileInputRef.current?.click()}
|
||||||
|
disabled={uploadingAvatar}
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
right: '-4px',
|
||||||
|
bottom: '-4px',
|
||||||
|
width: '24px',
|
||||||
|
height: '24px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
border: 'none',
|
||||||
|
background: '#2f6b4f',
|
||||||
|
color: '#ffffff',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
cursor: uploadingAvatar ? 'default' : 'pointer',
|
||||||
|
padding: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{uploadingAvatar ? (
|
||||||
|
<IonSpinner
|
||||||
|
name="crescent"
|
||||||
|
color="light"
|
||||||
|
style={{ width: '14px', height: '14px' }}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<IonIcon icon={cameraOutline} style={{ fontSize: '13px' }} />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
ref={fileInputRef}
|
||||||
|
type="file"
|
||||||
|
accept="image/jpeg,image/png,image/webp"
|
||||||
|
onChange={handleAvatarSelect}
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 0,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '4px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: '18px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{profile?.full_name || 'Member'}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
fontWeight: '400',
|
fontWeight: '400',
|
||||||
color: 'var(--color-text-tertiary)',
|
color: '#6b7280',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Professional account details
|
{profile?.email || ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
{profile?.ministry_group && (
|
||||||
onClick={handleEditProfile}
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#eef2ec',
|
||||||
|
color: '#4b5563',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '4px 10px',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: '600',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{profile.ministry_group}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Settings / Action List Card */}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '8px 18px',
|
||||||
|
margin: '0 20px 12px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
boxShadow: '0 2px 4px rgba(0,0,0,0.02)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
style={{
|
style={{
|
||||||
width: '40px',
|
minHeight: '56px',
|
||||||
height: '40px',
|
display: 'flex',
|
||||||
borderRadius: '12px',
|
alignItems: 'center',
|
||||||
background: 'transparent',
|
gap: '12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '36px',
|
||||||
|
height: '36px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: '#eef2ec',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={personOutline}
|
||||||
|
style={{ color: '#2f6b4f', fontSize: '18px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Personal Info
|
||||||
|
</div>
|
||||||
|
<IonIcon
|
||||||
|
icon={chevronForwardOutline}
|
||||||
|
style={{ color: '#9aa3a0', fontSize: '18px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
minHeight: '56px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '36px',
|
||||||
|
height: '36px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: '#eef2ec',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={settingsOutline}
|
||||||
|
style={{ color: '#2f6b4f', fontSize: '18px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Account Settings
|
||||||
|
</div>
|
||||||
|
<IonIcon
|
||||||
|
icon={chevronForwardOutline}
|
||||||
|
style={{ color: '#9aa3a0', fontSize: '18px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
minHeight: '56px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '36px',
|
||||||
|
height: '36px',
|
||||||
|
borderRadius: '12px',
|
||||||
|
background: '#eef2ec',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={helpCircleOutline}
|
||||||
|
style={{ color: '#2f6b4f', fontSize: '18px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Help & Support
|
||||||
|
</div>
|
||||||
|
<IonIcon
|
||||||
|
icon={chevronForwardOutline}
|
||||||
|
style={{ color: '#9aa3a0', fontSize: '18px' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Admin Shortcut Card */}
|
||||||
|
{isAdmin && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'rgba(47, 107, 79, 0.08)',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '18px',
|
||||||
|
margin: '0 20px 12px',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{ fontSize: '14px', fontWeight: '600', color: '#2f6b4f' }}
|
||||||
|
>
|
||||||
|
Admin Tools
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={goToCreateEvent}
|
||||||
|
style={{
|
||||||
|
background: '#2f6b4f',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '14px 16px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#ffffff',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Create New Event
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => history.push('/admin/news/new')}
|
||||||
|
style={{
|
||||||
|
background: 'rgba(47, 107, 79, 0.1)',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '14px 16px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#2f6b4f',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
width: '100%',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Manage News
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Sign Out Button */}
|
||||||
|
<div style={{ margin: '0 20px 24px 20px' }}>
|
||||||
|
<button
|
||||||
|
onClick={handleSignOut}
|
||||||
|
disabled={signingOut}
|
||||||
|
style={{
|
||||||
|
background: '#a33b32',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '16px',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#ffffff',
|
||||||
|
cursor: 'pointer',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
cursor: 'pointer',
|
width: '100%',
|
||||||
border: 'none',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IonIcon
|
{signingOut ? <IonSpinner name="dots" color="light" /> : 'Sign Out'}
|
||||||
icon={createOutline}
|
|
||||||
style={{ color: 'var(--color-brand)', fontSize: '24px' }}
|
|
||||||
/>
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
margin: '0 20px 12px',
|
margin: '0 20px',
|
||||||
background: 'var(--color-danger-soft)',
|
padding: '12px',
|
||||||
|
background: 'rgba(190,60,60,0.1)',
|
||||||
borderRadius: '12px',
|
borderRadius: '12px',
|
||||||
padding: '12px 14px',
|
color: '#a33b32',
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
fontWeight: '500',
|
|
||||||
color: 'var(--color-danger-text)',
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '24px',
|
|
||||||
margin: '0 20px 12px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: '16px' }}>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '72px',
|
|
||||||
height: '72px',
|
|
||||||
borderRadius: '999px',
|
|
||||||
background: 'var(--color-brand-medium)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
flexShrink: 0,
|
|
||||||
fontSize: '32px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-brand)',
|
|
||||||
textTransform: 'uppercase',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.full_name.charAt(0)}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '4px' }}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '22px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.full_name}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-accent-soft)',
|
|
||||||
color: 'var(--color-accent-strong)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '6px 12px',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
width: 'max-content',
|
|
||||||
textTransform: 'capitalize',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.role}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Member since {new Date(profile.created_at).toLocaleDateString()}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
margin: '0 20px 12px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '4px' }}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Appearance
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Switch between light and dark mode
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onClick={handleThemeToggle}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
border: 'none',
|
|
||||||
padding: '6px',
|
|
||||||
width: '120px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '48px',
|
|
||||||
height: '36px',
|
|
||||||
borderRadius: '999px',
|
|
||||||
background:
|
|
||||||
themeMode === 'light'
|
|
||||||
? 'var(--color-brand)'
|
|
||||||
: 'transparent',
|
|
||||||
color:
|
|
||||||
themeMode === 'light'
|
|
||||||
? '#ffffff'
|
|
||||||
: 'var(--color-text-secondary)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
gap: '6px',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
transition: 'all 0.2s ease',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon icon={sunnyOutline} style={{ fontSize: '16px' }} />
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '48px',
|
|
||||||
height: '36px',
|
|
||||||
borderRadius: '999px',
|
|
||||||
background:
|
|
||||||
themeMode === 'dark' ? 'var(--color-brand)' : 'transparent',
|
|
||||||
color:
|
|
||||||
themeMode === 'dark'
|
|
||||||
? '#ffffff'
|
|
||||||
: 'var(--color-text-secondary)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
gap: '6px',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
transition: 'all 0.2s ease',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon icon={moonOutline} style={{ fontSize: '16px' }} />
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '8px 0',
|
|
||||||
margin: '0 20px 12px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ProfileInfoRow
|
|
||||||
icon={personOutline}
|
|
||||||
label="Name"
|
|
||||||
value={profile.full_name}
|
|
||||||
onClick={handleEditProfile}
|
|
||||||
/>
|
|
||||||
{profile.company_name && (
|
|
||||||
<ProfileInfoRow
|
|
||||||
icon={businessOutline}
|
|
||||||
label="Company"
|
|
||||||
value={profile.company_name}
|
|
||||||
onClick={handleEditProfile}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{profile.city && (
|
|
||||||
<ProfileInfoRow
|
|
||||||
icon={locationOutline}
|
|
||||||
label="Location"
|
|
||||||
value={profile.city}
|
|
||||||
onClick={handleEditProfile}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{profile.phone && (
|
|
||||||
<ProfileInfoRow
|
|
||||||
icon={callOutline}
|
|
||||||
label="Phone"
|
|
||||||
value={profile.phone}
|
|
||||||
onClick={handleEditProfile}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
margin: '0 20px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
onClick={handleSignOut}
|
|
||||||
disabled={signingOut}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-brand-strong)',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
opacity: signingOut ? 0.7 : 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{signingOut ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'Sign Out'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,456 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import { useHistory, useParams } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonTitle,
|
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
|
||||||
useIonViewWillEnter,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { chevronBackOutline, pricetagOutline } from 'ionicons/icons';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
import { useProfile } from '../contexts/ProfileContext';
|
|
||||||
import QuoteSummaryRow from '../components/QuoteSummaryRow';
|
|
||||||
|
|
||||||
const RfqDetail: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { id } = useParams<{ id: string }>();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const { profile } = useProfile();
|
|
||||||
|
|
||||||
const [rfq, setRfq] = useState<any>(null);
|
|
||||||
const [images, setImages] = useState<string[]>([]);
|
|
||||||
const [quotes, setQuotes] = useState<any[]>([]);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
const [supplierInvited, setSupplierInvited] = useState(false);
|
|
||||||
|
|
||||||
useIonViewWillEnter(() => {
|
|
||||||
loadRfqDetail();
|
|
||||||
});
|
|
||||||
|
|
||||||
const loadRfqDetail = async () => {
|
|
||||||
if (!user || !profile) return;
|
|
||||||
setLoading(true);
|
|
||||||
setError('');
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check supplier visibility first if supplier
|
|
||||||
if (profile.role === 'supplier') {
|
|
||||||
const { data: rec, error: recErr } = await supabase
|
|
||||||
.from('rfq_recipients')
|
|
||||||
.select('id')
|
|
||||||
.eq('rfq_id', id)
|
|
||||||
.eq('supplier_id', user.id)
|
|
||||||
.single();
|
|
||||||
if (recErr || !rec) {
|
|
||||||
throw new Error('Not invited to this RFQ');
|
|
||||||
}
|
|
||||||
setSupplierInvited(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load RFQ
|
|
||||||
const { data: rfqData, error: rfqErr } = await supabase
|
|
||||||
.from('rfqs')
|
|
||||||
.select('*')
|
|
||||||
.eq('id', id)
|
|
||||||
.single();
|
|
||||||
if (rfqErr) throw rfqErr;
|
|
||||||
setRfq(rfqData);
|
|
||||||
|
|
||||||
// Load Images
|
|
||||||
const { data: imgData } = await supabase
|
|
||||||
.from('rfq_images')
|
|
||||||
.select('storage_path')
|
|
||||||
.eq('rfq_id', id);
|
|
||||||
|
|
||||||
if (imgData && imgData.length > 0) {
|
|
||||||
const urls = imgData.map((img) => {
|
|
||||||
const { data } = supabase.storage
|
|
||||||
.from('rfq-images')
|
|
||||||
.getPublicUrl(img.storage_path);
|
|
||||||
return data.publicUrl;
|
|
||||||
});
|
|
||||||
setImages(urls);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load Quotes
|
|
||||||
if (profile.role === 'buyer') {
|
|
||||||
const { data: qData, error: qErr } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.select(
|
|
||||||
'id, price_amount, delivery_option, status, profiles(full_name, company_name)'
|
|
||||||
)
|
|
||||||
.eq('rfq_id', id);
|
|
||||||
if (qErr) throw qErr;
|
|
||||||
setQuotes(qData || []);
|
|
||||||
} else {
|
|
||||||
const { data: qData, error: qErr } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.select('id, price_amount, delivery_option, status')
|
|
||||||
.eq('rfq_id', id)
|
|
||||||
.eq('supplier_id', user.id);
|
|
||||||
if (qErr) throw qErr;
|
|
||||||
setQuotes(qData || []);
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
setError(err.message || 'Failed to load RFQ details');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePrimaryAction = () => {
|
|
||||||
if (profile?.role === 'buyer') {
|
|
||||||
history.push(`/quote-list/${id}`);
|
|
||||||
} else {
|
|
||||||
if (quotes.length > 0) {
|
|
||||||
history.push(`/quote/${quotes[0].id}`, { mode: 'edit' });
|
|
||||||
} else {
|
|
||||||
history.push(`/quote/${id}`, { mode: 'create' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getStatusColor = (status: string) => {
|
|
||||||
if (status === 'open') {
|
|
||||||
return {
|
|
||||||
bg: 'var(--color-success-soft)',
|
|
||||||
text: 'var(--color-success-text)',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (status === 'quoted') {
|
|
||||||
return {
|
|
||||||
bg: 'var(--color-warning-soft)',
|
|
||||||
text: 'var(--color-warning-text)',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
bg: 'var(--color-surface-raised)',
|
|
||||||
text: 'var(--color-text-secondary)',
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!profile) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage style={{ background: 'var(--color-bg)' }}>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar
|
|
||||||
style={{ '--background': 'var(--color-bg)' } as React.CSSProperties}
|
|
||||||
>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={
|
|
||||||
{
|
|
||||||
'--color': 'var(--color-brand-strong)',
|
|
||||||
} as React.CSSProperties
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle
|
|
||||||
style={{
|
|
||||||
fontSize: '18px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Request Details
|
|
||||||
</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent
|
|
||||||
style={{
|
|
||||||
'--background': 'var(--color-bg-gradient)',
|
|
||||||
'--padding-start': '20px',
|
|
||||||
'--padding-end': '20px',
|
|
||||||
'--padding-top': '20px',
|
|
||||||
'--padding-bottom': 'calc(120px + var(--ion-safe-area-bottom))',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '40px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: 'var(--color-brand)' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : error ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(239, 68, 68, 0.10)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '500',
|
|
||||||
color: '#b91c1c',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
rfq && (
|
|
||||||
<>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
margin: '0 0 12px 0',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '10px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-accent-soft)',
|
|
||||||
color: 'var(--color-warning-text)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '6px 12px',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{rfq.reference_number}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: getStatusColor(rfq.status).bg,
|
|
||||||
color: getStatusColor(rfq.status).text,
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '6px 12px',
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
textTransform: 'capitalize',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{rfq.status}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '22px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{rfq.title}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Posted {new Date(rfq.created_at).toLocaleDateString()}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
margin: '0 0 12px 0',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Request Details
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
lineHeight: '1.6',
|
|
||||||
whiteSpace: 'pre-wrap',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{rfq.request_text}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{images.length > 0 && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
margin: '0 0 12px 0',
|
|
||||||
display: 'flex',
|
|
||||||
gap: '10px',
|
|
||||||
overflowX: 'auto',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{images.map((url, i) => (
|
|
||||||
<img
|
|
||||||
key={i}
|
|
||||||
src={url}
|
|
||||||
alt="Reference"
|
|
||||||
style={{
|
|
||||||
width: '120px',
|
|
||||||
height: '120px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
objectFit: 'cover',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
marginBottom: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: 'var(--color-text-primary)',
|
|
||||||
marginBottom: '16px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.role === 'buyer' ? 'Quotations' : 'Your Quote'}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{quotes.length > 0 ? (
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
|
||||||
{quotes.map((q) => (
|
|
||||||
<QuoteSummaryRow
|
|
||||||
key={q.id}
|
|
||||||
supplierName={
|
|
||||||
profile.role === 'buyer'
|
|
||||||
? q.profiles?.company_name ||
|
|
||||||
q.profiles?.full_name ||
|
|
||||||
'Supplier'
|
|
||||||
: 'My Quote'
|
|
||||||
}
|
|
||||||
priceLabel={`$${q.price_amount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`}
|
|
||||||
deliveryOption={q.delivery_option}
|
|
||||||
status={q.status}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: '40px',
|
|
||||||
height: '40px',
|
|
||||||
borderRadius: '12px',
|
|
||||||
background: 'var(--color-surface-raised)',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon
|
|
||||||
icon={pricetagOutline}
|
|
||||||
style={{
|
|
||||||
color: 'var(--color-brand)',
|
|
||||||
fontSize: '20px',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
color: 'var(--color-text-secondary)',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.role === 'buyer'
|
|
||||||
? 'No quotes received yet.'
|
|
||||||
: "You haven't submitted a quote yet."}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
</IonContent>
|
|
||||||
|
|
||||||
{!loading && !error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'fixed',
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
padding: '16px 20px calc(16px + var(--ion-safe-area-bottom, 0px))',
|
|
||||||
background: 'var(--color-surface)',
|
|
||||||
borderTop: '1px solid var(--color-border)',
|
|
||||||
display: 'flex',
|
|
||||||
zIndex: 10,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
onClick={handlePrimaryAction}
|
|
||||||
style={{
|
|
||||||
background: 'var(--color-brand)',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
width: '100%',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{profile.role === 'buyer'
|
|
||||||
? 'View Quotations'
|
|
||||||
: quotes.length > 0
|
|
||||||
? 'Update Quote'
|
|
||||||
: 'Submit Quote'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RfqDetail;
|
|
||||||
@@ -1,70 +1,55 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import {
|
import {
|
||||||
IonPage,
|
IonPage,
|
||||||
|
IonContent,
|
||||||
IonHeader,
|
IonHeader,
|
||||||
IonToolbar,
|
IonToolbar,
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonTitle,
|
IonTitle,
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
IonSpinner,
|
||||||
|
IonSelect,
|
||||||
|
IonSelectOption,
|
||||||
|
IonIcon,
|
||||||
} from '@ionic/react';
|
} from '@ionic/react';
|
||||||
import { chevronBackOutline } from 'ionicons/icons';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
import { useAuth } from '../contexts/AuthContext';
|
||||||
import { useProfile } from '../contexts/ProfileContext';
|
import { personAddOutline } from 'ionicons/icons';
|
||||||
import { Preferences } from '@capacitor/preferences';
|
|
||||||
|
|
||||||
const SetupProfile: React.FC = () => {
|
const SetupProfile: React.FC = () => {
|
||||||
const history = useHistory();
|
|
||||||
const { user } = useAuth();
|
|
||||||
const { setProfile, setStatus } = useProfile();
|
|
||||||
|
|
||||||
const [role, setRole] = useState<'buyer' | 'supplier' | ''>('');
|
|
||||||
const [fullName, setFullName] = useState('');
|
const [fullName, setFullName] = useState('');
|
||||||
const [companyName, setCompanyName] = useState('');
|
const [ministryGroup, setMinistryGroup] = useState('');
|
||||||
const [phone, setPhone] = useState('');
|
|
||||||
const [city, setCity] = useState('');
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const history = useHistory();
|
||||||
|
const { user, refreshProfile } = useAuth();
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
const showError = (msg: string) => {
|
||||||
setError(msg);
|
setError(msg);
|
||||||
setTimeout(() => setError(''), 4000);
|
setTimeout(() => setError(null), 4000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProfileSetup = async (e: React.FormEvent) => {
|
const handleProfileSetup = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!user) return;
|
if (!fullName.trim()) {
|
||||||
if (!role) {
|
showError('Please enter your name');
|
||||||
showError('Please select a role');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!fullName) {
|
if (!user) {
|
||||||
showError('Please enter your full name');
|
showError('No user session found. Please log in again.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError('');
|
setError(null);
|
||||||
|
|
||||||
const newProfile = {
|
const { error: insertError } = await supabase.from('profiles').insert({
|
||||||
id: user.id,
|
id: user.id,
|
||||||
role: role as 'buyer' | 'supplier',
|
email: user.email ?? '',
|
||||||
full_name: fullName,
|
full_name: fullName.trim(),
|
||||||
company_name: companyName || null,
|
role: 'member',
|
||||||
phone: phone || null,
|
ministry_group: ministryGroup || null,
|
||||||
city: city || null,
|
});
|
||||||
avatar_url: null,
|
|
||||||
created_at: new Date().toISOString(),
|
|
||||||
updated_at: new Date().toISOString(),
|
|
||||||
};
|
|
||||||
|
|
||||||
const { error: insertError } = await supabase
|
|
||||||
.from('profiles')
|
|
||||||
.insert(newProfile);
|
|
||||||
|
|
||||||
if (insertError) {
|
if (insertError) {
|
||||||
showError(insertError.message);
|
showError(insertError.message);
|
||||||
@@ -72,31 +57,17 @@ const SetupProfile: React.FC = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Preferences.set({
|
await refreshProfile();
|
||||||
key: `profile_${user.id}`,
|
|
||||||
value: JSON.stringify(newProfile),
|
|
||||||
});
|
|
||||||
setProfile(newProfile);
|
|
||||||
setStatus('loaded');
|
|
||||||
|
|
||||||
setLoading(false);
|
|
||||||
history.replace('/home');
|
history.replace('/home');
|
||||||
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IonPage style={{ background: '#eef4ef' }}>
|
<IonPage style={{ background: '#f5f7f4' }}>
|
||||||
<IonHeader className="ion-no-border">
|
<IonHeader className="ion-no-border">
|
||||||
<IonToolbar style={{ '--background': 'transparent' }}>
|
<IonToolbar style={{ '--background': '#f5f7f4' }}>
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ color: '#14532d' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle
|
<IonTitle
|
||||||
style={{ fontSize: '18px', fontWeight: '700', color: '#0f1720' }}
|
style={{ fontSize: '18px', fontWeight: '700', color: '#1f2937' }}
|
||||||
>
|
>
|
||||||
Setup Profile
|
Setup Profile
|
||||||
</IonTitle>
|
</IonTitle>
|
||||||
@@ -105,231 +76,172 @@ const SetupProfile: React.FC = () => {
|
|||||||
|
|
||||||
<IonContent
|
<IonContent
|
||||||
style={{
|
style={{
|
||||||
'--background': 'linear-gradient(180deg, #eef4ef 0%, #f8fbf8 100%)',
|
'--background': '#f5f7f4',
|
||||||
'--padding-start': '20px',
|
'--padding-start': '20px',
|
||||||
'--padding-end': '20px',
|
'--padding-end': '20px',
|
||||||
'--padding-top': '20px',
|
'--padding-top': '16px',
|
||||||
'--padding-bottom': 'calc(28px + var(--ion-safe-area-bottom))',
|
'--padding-bottom': '20px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'transparent',
|
|
||||||
margin: '0 0 16px 0',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h1
|
|
||||||
style={{
|
|
||||||
fontSize: '26px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: '#0f1720',
|
|
||||||
margin: '0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Welcome!
|
|
||||||
</h1>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#5f6d63',
|
|
||||||
margin: '0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Complete your profile to get started.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
background: '#ffffff',
|
background: '#ffffff',
|
||||||
borderRadius: '24px',
|
borderRadius: '24px',
|
||||||
padding: '24px',
|
padding: '24px',
|
||||||
|
margin: '0 0 16px 0',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
gap: '20px',
|
gap: '12px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{error && (
|
<div
|
||||||
<div
|
style={{
|
||||||
|
background: 'rgba(47, 107, 79, 0.12)',
|
||||||
|
borderRadius: '12px',
|
||||||
|
width: '44px',
|
||||||
|
height: '44px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={personAddOutline}
|
||||||
|
style={{ fontSize: '20px', color: '#2f6b4f' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<h2
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '20px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Welcome to EAGLES ASSEMBLY
|
||||||
|
</h2>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: '#6b7280',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Please let us know who you are so we can personalize your
|
||||||
|
experience.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
onSubmit={handleProfileSetup}
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '24px',
|
||||||
|
margin: '0 0 16px 0',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '16px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Full Name (e.g. John Doe)"
|
||||||
|
value={fullName}
|
||||||
|
onChange={(e) => setFullName(e.target.value)}
|
||||||
|
required
|
||||||
|
style={{
|
||||||
|
background: '#eef2ec',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '0 14px',
|
||||||
|
height: '48px',
|
||||||
|
fontSize: '15px',
|
||||||
|
color: '#1f2937',
|
||||||
|
outline: 'none',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#eef2ec',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '0 14px',
|
||||||
|
height: '48px',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSelect
|
||||||
|
value={ministryGroup}
|
||||||
|
placeholder="Select Ministry Group (Optional)"
|
||||||
|
onIonChange={(e) => setMinistryGroup(e.detail.value)}
|
||||||
|
interface="popover"
|
||||||
style={{
|
style={{
|
||||||
background: 'rgba(239, 68, 68, 0.10)',
|
width: '100%',
|
||||||
borderRadius: '12px',
|
color: '#1f2937',
|
||||||
padding: '12px 14px',
|
fontSize: '15px',
|
||||||
|
'--placeholder-color': '#9aa3a0',
|
||||||
|
'--placeholder-opacity': '1',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonSelectOption value="Youth">Youth</IonSelectOption>
|
||||||
|
<IonSelectOption value="Choir">Choir</IonSelectOption>
|
||||||
|
<IonSelectOption value="Ushering">Ushering</IonSelectOption>
|
||||||
|
<IonSelectOption value="Media">Media</IonSelectOption>
|
||||||
|
</IonSelect>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={loading}
|
||||||
|
style={{
|
||||||
|
background: '#2f6b4f',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '16px',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#ffffff',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
marginTop: '8px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<IonSpinner name="dots" color="light" />
|
||||||
|
) : (
|
||||||
|
'Complete Setup'
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'rgba(190, 60, 60, 0.10)',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '12px 14px',
|
||||||
|
margin: '0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
fontWeight: '500',
|
fontWeight: '500',
|
||||||
color: '#b91c1c',
|
color: '#a33b32',
|
||||||
|
lineHeight: '1.4',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</p>
|
||||||
)}
|
</div>
|
||||||
|
)}
|
||||||
<form
|
|
||||||
onSubmit={handleProfileSetup}
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: '#0f1720',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
I want to...
|
|
||||||
</label>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
background: '#edf4ee',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setRole('buyer')}
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
background: role === 'buyer' ? '#166534' : 'transparent',
|
|
||||||
color: role === 'buyer' ? '#ffffff' : '#14532d',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '12px 18px',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Buy Materials
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setRole('supplier')}
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
background: role === 'supplier' ? '#166534' : 'transparent',
|
|
||||||
color: role === 'supplier' ? '#ffffff' : '#14532d',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '12px 18px',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Sell Materials
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="Full Name"
|
|
||||||
value={fullName}
|
|
||||||
onChange={(e) => setFullName(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="Company Name (Optional)"
|
|
||||||
value={companyName}
|
|
||||||
onChange={(e) => setCompanyName(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="City (Optional)"
|
|
||||||
value={city}
|
|
||||||
onChange={(e) => setCity(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="tel"
|
|
||||||
placeholder="Phone (Optional)"
|
|
||||||
value={phone}
|
|
||||||
onChange={(e) => setPhone(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={loading || !role || !fullName}
|
|
||||||
style={{
|
|
||||||
background: '#166534',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
opacity: loading || !role || !fullName ? 0.7 : 1,
|
|
||||||
marginTop: '4px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'Complete Setup'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,434 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import { useHistory, useParams, useLocation } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonTitle,
|
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { chevronBackOutline } from 'ionicons/icons';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useAuth } from '../contexts/AuthContext';
|
|
||||||
|
|
||||||
interface LocationState {
|
|
||||||
mode?: 'create' | 'edit';
|
|
||||||
}
|
|
||||||
|
|
||||||
const SupplierQuoteForm: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const { id } = useParams<{ id: string }>(); // in create mode: id is rfq_id; in edit mode: id is quotation_id
|
|
||||||
const location = useLocation<LocationState>();
|
|
||||||
const mode = location.state?.mode || 'create';
|
|
||||||
|
|
||||||
const { user } = useAuth();
|
|
||||||
|
|
||||||
const [rfqSummary, setRfqSummary] = useState<{
|
|
||||||
id: string;
|
|
||||||
referenceNumber: string;
|
|
||||||
title: string;
|
|
||||||
} | null>(null);
|
|
||||||
const [priceDisplay, setPriceDisplay] = useState('');
|
|
||||||
const [deliveryOption, setDeliveryOption] = useState('');
|
|
||||||
const [note, setNote] = useState('');
|
|
||||||
const [existingQuotationId, setExistingQuotationId] = useState<string | null>(
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [saving, setSaving] = useState(false);
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadQuoteFormData();
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [id, mode]);
|
|
||||||
|
|
||||||
const loadQuoteFormData = async () => {
|
|
||||||
if (!user) return;
|
|
||||||
setLoading(true);
|
|
||||||
setError('');
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (mode === 'edit') {
|
|
||||||
// id is quotation_id
|
|
||||||
const { data: quote, error: qErr } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.select('*, rfqs(id, reference_number, title)')
|
|
||||||
.eq('id', id)
|
|
||||||
.single();
|
|
||||||
if (qErr) throw qErr;
|
|
||||||
|
|
||||||
setExistingQuotationId(quote.id);
|
|
||||||
setPriceDisplay(quote.price_amount.toString());
|
|
||||||
setDeliveryOption(quote.delivery_option);
|
|
||||||
setNote(quote.note || '');
|
|
||||||
setRfqSummary({
|
|
||||||
id: quote.rfqs.id,
|
|
||||||
referenceNumber: quote.rfqs.reference_number,
|
|
||||||
title: quote.rfqs.title,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// id is rfq_id
|
|
||||||
const { data: rfq, error: rfqErr } = await supabase
|
|
||||||
.from('rfqs')
|
|
||||||
.select('id, reference_number, title')
|
|
||||||
.eq('id', id)
|
|
||||||
.single();
|
|
||||||
if (rfqErr) throw rfqErr;
|
|
||||||
setRfqSummary({
|
|
||||||
id: rfq.id,
|
|
||||||
referenceNumber: rfq.reference_number,
|
|
||||||
title: rfq.title,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if there is already a quote (just in case they navigated strangely)
|
|
||||||
const { data: quote } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.select('*')
|
|
||||||
.eq('rfq_id', id)
|
|
||||||
.eq('supplier_id', user.id)
|
|
||||||
.maybeSingle();
|
|
||||||
|
|
||||||
if (quote) {
|
|
||||||
setExistingQuotationId(quote.id);
|
|
||||||
setPriceDisplay(quote.price_amount.toString());
|
|
||||||
setDeliveryOption(quote.delivery_option);
|
|
||||||
setNote(quote.note || '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
setError('Failed to load form data.');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const sanitizePriceInput = (val: string) => {
|
|
||||||
let sanitized = val.replace(/[^0-9.]/g, '');
|
|
||||||
const parts = sanitized.split('.');
|
|
||||||
if (parts.length > 2) {
|
|
||||||
sanitized = parts[0] + '.' + parts.slice(1).join('');
|
|
||||||
}
|
|
||||||
if (parts.length === 2 && parts[1].length > 2) {
|
|
||||||
sanitized = parts[0] + '.' + parts[1].substring(0, 2);
|
|
||||||
}
|
|
||||||
setPriceDisplay(sanitized);
|
|
||||||
};
|
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
|
||||||
setError(msg);
|
|
||||||
setTimeout(() => setError(''), 4000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSaveQuote = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (!user || !rfqSummary) return;
|
|
||||||
|
|
||||||
const amount = parseFloat(priceDisplay);
|
|
||||||
if (isNaN(amount) || amount < 0) {
|
|
||||||
showError('Please enter a valid amount.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!deliveryOption.trim()) {
|
|
||||||
showError('Please enter a delivery option.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setSaving(true);
|
|
||||||
setError('');
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (existingQuotationId) {
|
|
||||||
const { error: updErr } = await supabase
|
|
||||||
.from('quotations')
|
|
||||||
.update({
|
|
||||||
price_amount: amount,
|
|
||||||
delivery_option: deliveryOption.trim(),
|
|
||||||
note: note.trim() || null,
|
|
||||||
updated_at: new Date().toISOString(),
|
|
||||||
})
|
|
||||||
.eq('id', existingQuotationId);
|
|
||||||
if (updErr) throw updErr;
|
|
||||||
} else {
|
|
||||||
const { error: insErr } = await supabase.from('quotations').insert({
|
|
||||||
rfq_id: rfqSummary.id,
|
|
||||||
supplier_id: user.id,
|
|
||||||
price_amount: amount,
|
|
||||||
currency_code: 'USD',
|
|
||||||
delivery_option: deliveryOption.trim(),
|
|
||||||
note: note.trim() || null,
|
|
||||||
status: 'submitted',
|
|
||||||
});
|
|
||||||
if (insErr) throw insErr;
|
|
||||||
}
|
|
||||||
|
|
||||||
history.replace(`/rfq/${rfqSummary.id}`);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
showError(err.message || 'Failed to save quotation.');
|
|
||||||
setSaving(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage style={{ background: '#f7faf7' }}>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar style={{ '--background': '#f7faf7' }}>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ color: '#14532d' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle
|
|
||||||
style={{ fontSize: '18px', fontWeight: '700', color: '#0f1720' }}
|
|
||||||
>
|
|
||||||
{existingQuotationId ? 'Update Quote' : 'Submit Quote'}
|
|
||||||
</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent
|
|
||||||
style={{
|
|
||||||
'--background': '#f7faf7',
|
|
||||||
'--padding-start': '20px',
|
|
||||||
'--padding-end': '20px',
|
|
||||||
'--padding-top': '20px',
|
|
||||||
'--padding-bottom': 'calc(28px + var(--ion-safe-area-bottom))',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '40px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonSpinner name="crescent" style={{ color: '#166534' }} />
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{rfqSummary && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: '#ffffff',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '20px',
|
|
||||||
margin: '0 0 12px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '12px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: '#b45309',
|
|
||||||
background: 'rgba(245,158,11,0.14)',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '4px 10px',
|
|
||||||
width: 'max-content',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{rfqSummary.referenceNumber}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '16px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: '#0f1720',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{rfqSummary.title}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(239, 68, 68, 0.10)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '500',
|
|
||||||
color: '#b91c1c',
|
|
||||||
marginBottom: '12px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<form
|
|
||||||
onSubmit={handleSaveQuote}
|
|
||||||
style={{
|
|
||||||
background: '#ffffff',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '24px',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '18px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '6px' }}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: '#0f1720',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Total Price (USD)
|
|
||||||
</label>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'relative',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
left: '14px',
|
|
||||||
fontSize: '15px',
|
|
||||||
color: '#0f1720',
|
|
||||||
fontWeight: '600',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
$
|
|
||||||
</span>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
inputMode="decimal"
|
|
||||||
placeholder="0.00"
|
|
||||||
value={priceDisplay}
|
|
||||||
onChange={(e) => sanitizePriceInput(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px 0 32px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '6px' }}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: '#0f1720',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Delivery Option
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="e.g. Free delivery in 2 days"
|
|
||||||
value={deliveryOption}
|
|
||||||
onChange={(e) => setDeliveryOption(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '6px' }}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
style={{
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: '#0f1720',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Note for Buyer (Optional)
|
|
||||||
</label>
|
|
||||||
<textarea
|
|
||||||
placeholder="Add any conditions or details..."
|
|
||||||
value={note}
|
|
||||||
onChange={(e) => setNote(e.target.value)}
|
|
||||||
rows={4}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '14px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
resize: 'vertical',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={saving || !priceDisplay || !deliveryOption}
|
|
||||||
style={{
|
|
||||||
background: '#166534',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
opacity: saving || !priceDisplay || !deliveryOption ? 0.7 : 1,
|
|
||||||
marginTop: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{saving ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : existingQuotationId ? (
|
|
||||||
'Update Quote'
|
|
||||||
) : (
|
|
||||||
'Submit Quote'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SupplierQuoteForm;
|
|
||||||
@@ -1,32 +1,39 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import { useHistory, useLocation } from 'react-router-dom';
|
|
||||||
import { IonPage, IonContent, IonSpinner, IonIcon } from '@ionic/react';
|
import { IonPage, IonContent, IonSpinner, IonIcon } from '@ionic/react';
|
||||||
import { arrowBackOutline, checkmarkCircle } from 'ionicons/icons';
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
import { supabase } from '../supabase';
|
import { supabase } from '../supabase';
|
||||||
import OtpInput from '../components/OtpInput';
|
import OtpInputRow from '../components/OtpInputRow';
|
||||||
|
import { checkmarkCircleOutline } from 'ionicons/icons';
|
||||||
interface LocationState {
|
|
||||||
email?: string;
|
|
||||||
resent?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const VerifyEmail: React.FC = () => {
|
const VerifyEmail: React.FC = () => {
|
||||||
|
const [digits, setDigits] = useState<string[]>(Array(6).fill(''));
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [cooldown, setCooldown] = useState(0);
|
||||||
|
const [verified, setVerified] = useState(false);
|
||||||
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const location = useLocation<LocationState>();
|
const location = useLocation<{ email?: string; resent?: boolean }>();
|
||||||
const email = location.state?.email || '';
|
const email = location.state?.email || '';
|
||||||
const resent = location.state?.resent || false;
|
const resent = location.state?.resent || false;
|
||||||
|
|
||||||
const [code, setCode] = useState('');
|
const inputRefs = [
|
||||||
const [loading, setLoading] = useState(false);
|
useRef<HTMLIonInputElement>(null),
|
||||||
const [error, setError] = useState('');
|
useRef<HTMLIonInputElement>(null),
|
||||||
const [cooldown, setCooldown] = useState(resent ? 60 : 0);
|
useRef<HTMLIonInputElement>(null),
|
||||||
const [verified, setVerified] = useState(false);
|
useRef<HTMLIonInputElement>(null),
|
||||||
|
useRef<HTMLIonInputElement>(null),
|
||||||
|
useRef<HTMLIonInputElement>(null),
|
||||||
|
];
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!email) {
|
if (!email) {
|
||||||
history.replace('/auth');
|
history.replace('/auth');
|
||||||
}
|
}
|
||||||
}, [email, history]);
|
if (resent) {
|
||||||
|
setCooldown(60);
|
||||||
|
}
|
||||||
|
}, [email, resent, history]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (cooldown > 0) {
|
if (cooldown > 0) {
|
||||||
@@ -35,63 +42,74 @@ const VerifyEmail: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [cooldown]);
|
}, [cooldown]);
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
const handleDigitChange = (index: number, value: string) => {
|
||||||
setError(msg);
|
const sanitized = value.replace(/[^0-9]/g, '').slice(-1);
|
||||||
setTimeout(() => setError(''), 4000);
|
const newDigits = [...digits];
|
||||||
|
newDigits[index] = sanitized;
|
||||||
|
setDigits(newDigits);
|
||||||
|
|
||||||
|
if (sanitized && index < 5) {
|
||||||
|
inputRefs[index + 1].current?.setFocus();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleVerifyOtp = async (e: React.FormEvent) => {
|
const handleKeyDown = (
|
||||||
e.preventDefault();
|
index: number,
|
||||||
|
e: React.KeyboardEvent<HTMLIonInputElement>
|
||||||
|
) => {
|
||||||
|
if (e.key === 'Backspace') {
|
||||||
|
if (!digits[index] && index > 0) {
|
||||||
|
inputRefs[index - 1].current?.setFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleVerifyOtp = async () => {
|
||||||
|
const code = digits.join('');
|
||||||
if (code.length !== 6) {
|
if (code.length !== 6) {
|
||||||
showError('Please enter the 6-digit code');
|
setError('Please enter all 6 digits');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError('');
|
setError(null);
|
||||||
|
|
||||||
const { error } = await supabase.auth.verifyOtp({
|
const { error } = await supabase.auth.verifyOtp({
|
||||||
email,
|
email,
|
||||||
token: code,
|
token: code,
|
||||||
type: 'email',
|
type: 'email',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
showError(error.message);
|
setError(error.message);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setVerified(true);
|
setVerified(true);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleResend = async () => {
|
const handleResend = async () => {
|
||||||
if (cooldown > 0) return;
|
if (cooldown > 0) return;
|
||||||
|
setLoading(true);
|
||||||
const { error } = await supabase.auth.resend({
|
setError(null);
|
||||||
type: 'signup',
|
const { error } = await supabase.auth.resend({ type: 'signup', email });
|
||||||
email,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
showError(error.message);
|
setError(error.message);
|
||||||
} else {
|
setLoading(false);
|
||||||
setCooldown(60);
|
return;
|
||||||
}
|
}
|
||||||
|
setCooldown(60);
|
||||||
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBackToSignIn = () => {
|
const goBackToAuth = () => {
|
||||||
history.replace('/auth');
|
history.replace('/auth');
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!email) return null;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IonPage style={{ background: '#f7faf7' }}>
|
<IonPage style={{ background: '#f6f1e8' }}>
|
||||||
<IonContent
|
<IonContent
|
||||||
style={{
|
style={{
|
||||||
'--background': '#f7faf7',
|
'--background': 'linear-gradient(180deg, #f9f5ee 0%, #f3ede3 100%)',
|
||||||
'--padding-start': '0px',
|
'--padding-start': '0px',
|
||||||
'--padding-end': '0px',
|
'--padding-end': '0px',
|
||||||
'--padding-top': '0px',
|
'--padding-top': '0px',
|
||||||
@@ -110,193 +128,165 @@ const VerifyEmail: React.FC = () => {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
background: 'transparent',
|
background: 'transparent',
|
||||||
padding: '0',
|
borderRadius: '0px',
|
||||||
margin: '0 0 20px 0',
|
padding: '0px',
|
||||||
display: 'flex',
|
margin: '0 0 24px 0',
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{
|
|
||||||
background: 'transparent',
|
|
||||||
border: 'none',
|
|
||||||
padding: '0',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
cursor: 'pointer',
|
|
||||||
color: '#14532d',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IonIcon icon={arrowBackOutline} style={{ fontSize: '24px' }} />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: '#ffffff',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '24px',
|
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
gap: '20px',
|
gap: '8px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{verified ? (
|
<h1
|
||||||
<div
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '24px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Check your email
|
||||||
|
</h1>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: '#6b7280',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
We sent a 6-digit code to {email}.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!verified ? (
|
||||||
|
<>
|
||||||
|
<OtpInputRow
|
||||||
|
digits={digits}
|
||||||
|
onChange={handleDigitChange}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
inputRefs={inputRefs}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={handleVerifyOtp}
|
||||||
|
disabled={loading}
|
||||||
style={{
|
style={{
|
||||||
|
background: '#2f6b4f',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '16px',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#ffffff',
|
||||||
|
cursor: 'pointer',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '20px',
|
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
textAlign: 'center',
|
justifyContent: 'center',
|
||||||
padding: '20px 0',
|
margin: '0 0 16px 0',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<IonIcon
|
{loading ? <IonSpinner name="dots" color="light" /> : 'Verify'}
|
||||||
icon={checkmarkCircle}
|
</button>
|
||||||
style={{ fontSize: '64px', color: '#166534' }}
|
|
||||||
/>
|
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(22,101,52,0.10)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '14px',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
color: '#14532d',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Email confirmed. You can now sign in.
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button
|
<button
|
||||||
onClick={handleBackToSignIn}
|
onClick={handleResend}
|
||||||
|
disabled={cooldown > 0 || loading}
|
||||||
style={{
|
style={{
|
||||||
background: '#166534',
|
background: 'transparent',
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
border: 'none',
|
||||||
width: '100%',
|
borderRadius: '999px',
|
||||||
cursor: 'pointer',
|
padding: '10px 14px',
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: cooldown > 0 ? '#9aa3a0' : '#2f6b4f',
|
||||||
|
cursor: cooldown > 0 ? 'default' : 'pointer',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Back to Sign In
|
{cooldown > 0 ? `Resend code in ${cooldown}s` : 'Resend code'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '24px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: '#0f1720',
|
|
||||||
lineHeight: '1.15',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Verify your email
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#5f6d63',
|
|
||||||
lineHeight: '1.55',
|
|
||||||
marginTop: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
We sent a 6-digit code to <strong>{email}</strong>. Enter it
|
|
||||||
below to confirm your account.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div
|
<div
|
||||||
|
style={{
|
||||||
|
background: 'rgba(190, 60, 60, 0.10)',
|
||||||
|
borderRadius: '12px',
|
||||||
|
padding: '12px 14px',
|
||||||
|
margin: '16px 0 0 0',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p
|
||||||
style={{
|
style={{
|
||||||
background: 'rgba(239, 68, 68, 0.10)',
|
margin: 0,
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
fontWeight: '500',
|
fontWeight: '500',
|
||||||
color: '#b91c1c',
|
color: '#a33b32',
|
||||||
|
lineHeight: '1.4',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</p>
|
||||||
)}
|
|
||||||
|
|
||||||
<form
|
|
||||||
onSubmit={handleVerifyOtp}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '20px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<OtpInput
|
|
||||||
value={code}
|
|
||||||
onChange={setCode}
|
|
||||||
disabled={loading}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={loading || code.length !== 6}
|
|
||||||
style={{
|
|
||||||
background: '#166534',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
opacity: loading || code.length !== 6 ? 0.7 : 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'Verify'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={handleResend}
|
|
||||||
disabled={cooldown > 0}
|
|
||||||
style={{
|
|
||||||
background: 'transparent',
|
|
||||||
border: 'none',
|
|
||||||
padding: '0',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: cooldown > 0 ? '#8a978f' : '#f59e0b',
|
|
||||||
cursor: cooldown > 0 ? 'default' : 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{cooldown > 0
|
|
||||||
? `Resend code in ${cooldown}s`
|
|
||||||
: 'Resend code'}
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
)}
|
||||||
)}
|
</>
|
||||||
</div>
|
) : (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: '#ffffff',
|
||||||
|
borderRadius: '24px',
|
||||||
|
padding: '24px',
|
||||||
|
margin: '24px 0 0 0',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '12px',
|
||||||
|
alignItems: 'center',
|
||||||
|
textAlign: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IonIcon
|
||||||
|
icon={checkmarkCircleOutline}
|
||||||
|
style={{ fontSize: '36px', color: '#2f6b4f' }}
|
||||||
|
/>
|
||||||
|
<h2
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '18px',
|
||||||
|
fontWeight: '700',
|
||||||
|
color: '#1f2937',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Email confirmed
|
||||||
|
</h2>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: '400',
|
||||||
|
color: '#6b7280',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
You can now sign in to your account.
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={goBackToAuth}
|
||||||
|
style={{
|
||||||
|
background: '#2f6b4f',
|
||||||
|
border: 'none',
|
||||||
|
borderRadius: '999px',
|
||||||
|
padding: '16px',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#ffffff',
|
||||||
|
cursor: 'pointer',
|
||||||
|
width: '100%',
|
||||||
|
marginTop: '12px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Back to Sign In
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
|
|||||||
@@ -1,311 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import { useHistory, useLocation } from 'react-router-dom';
|
|
||||||
import {
|
|
||||||
IonPage,
|
|
||||||
IonHeader,
|
|
||||||
IonToolbar,
|
|
||||||
IonButtons,
|
|
||||||
IonButton,
|
|
||||||
IonIcon,
|
|
||||||
IonTitle,
|
|
||||||
IonContent,
|
|
||||||
IonSpinner,
|
|
||||||
} from '@ionic/react';
|
|
||||||
import { chevronBackOutline, eyeOutline, eyeOffOutline } from 'ionicons/icons';
|
|
||||||
import { supabase } from '../supabase';
|
|
||||||
import { useProfileLoader } from '../hooks/useProfileLoader';
|
|
||||||
import OtpInput from '../components/OtpInput';
|
|
||||||
|
|
||||||
interface LocationState {
|
|
||||||
email?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const VerifyReset: React.FC = () => {
|
|
||||||
const history = useHistory();
|
|
||||||
const location = useLocation<LocationState>();
|
|
||||||
const email = location.state?.email || '';
|
|
||||||
|
|
||||||
const { loadProfileAndNavigate } = useProfileLoader();
|
|
||||||
|
|
||||||
const [code, setCode] = useState('');
|
|
||||||
const [newPassword, setNewPassword] = useState('');
|
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
const [cooldown, setCooldown] = useState(60);
|
|
||||||
|
|
||||||
const [overlayVisible, setOverlayVisible] = useState(false);
|
|
||||||
const [overlayError, setOverlayError] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!email) {
|
|
||||||
history.replace('/forgot-password');
|
|
||||||
}
|
|
||||||
}, [email, history]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (cooldown > 0) {
|
|
||||||
const timer = setTimeout(() => setCooldown(cooldown - 1), 1000);
|
|
||||||
return () => clearTimeout(timer);
|
|
||||||
}
|
|
||||||
}, [cooldown]);
|
|
||||||
|
|
||||||
const showError = (msg: string) => {
|
|
||||||
setError(msg);
|
|
||||||
setTimeout(() => setError(''), 4000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleVerifyReset = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (code.length !== 6) {
|
|
||||||
showError('Please enter the 6-digit code');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (newPassword.length < 6) {
|
|
||||||
showError('Password must be at least 6 characters');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(true);
|
|
||||||
setError('');
|
|
||||||
|
|
||||||
const { error: verifyError } = await supabase.auth.verifyOtp({
|
|
||||||
email,
|
|
||||||
token: code,
|
|
||||||
type: 'recovery',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (verifyError) {
|
|
||||||
showError(verifyError.message);
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { error: updateError } = await supabase.auth.updateUser({
|
|
||||||
password: newPassword,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (updateError) {
|
|
||||||
showError(updateError.message);
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success -> load profile and navigate
|
|
||||||
loadProfileAndNavigate(setOverlayVisible, setOverlayError);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleResend = async () => {
|
|
||||||
if (cooldown > 0) return;
|
|
||||||
const { error } = await supabase.auth.resetPasswordForEmail(email);
|
|
||||||
if (error) {
|
|
||||||
showError(error.message);
|
|
||||||
} else {
|
|
||||||
setCooldown(60);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!email) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage style={{ background: '#f7faf7' }}>
|
|
||||||
<IonHeader className="ion-no-border">
|
|
||||||
<IonToolbar style={{ '--background': '#f7faf7' }}>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonButton
|
|
||||||
onClick={() => history.goBack()}
|
|
||||||
style={{ color: '#14532d' }}
|
|
||||||
>
|
|
||||||
<IonIcon icon={chevronBackOutline} slot="icon-only" />
|
|
||||||
</IonButton>
|
|
||||||
</IonButtons>
|
|
||||||
<IonTitle
|
|
||||||
style={{ fontSize: '18px', fontWeight: '700', color: '#0f1720' }}
|
|
||||||
>
|
|
||||||
Set New Password
|
|
||||||
</IonTitle>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
|
|
||||||
<IonContent
|
|
||||||
style={{
|
|
||||||
'--background': '#f7faf7',
|
|
||||||
'--padding-start': '20px',
|
|
||||||
'--padding-end': '20px',
|
|
||||||
'--padding-top': '20px',
|
|
||||||
'--padding-bottom': 'calc(28px + var(--ion-safe-area-bottom))',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: '#ffffff',
|
|
||||||
borderRadius: '24px',
|
|
||||||
padding: '24px',
|
|
||||||
margin: '0',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
gap: '18px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div>
|
|
||||||
<h2
|
|
||||||
style={{
|
|
||||||
fontSize: '22px',
|
|
||||||
fontWeight: '700',
|
|
||||||
color: '#0f1720',
|
|
||||||
margin: '0 0 8px 0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Enter code
|
|
||||||
</h2>
|
|
||||||
<p
|
|
||||||
style={{
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#5f6d63',
|
|
||||||
margin: '0',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
We sent a 6-digit code to <strong>{email}</strong>.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
background: 'rgba(239, 68, 68, 0.10)',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '12px 14px',
|
|
||||||
fontSize: '13px',
|
|
||||||
fontWeight: '500',
|
|
||||||
color: '#b91c1c',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<form
|
|
||||||
onSubmit={handleVerifyReset}
|
|
||||||
style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}
|
|
||||||
>
|
|
||||||
<OtpInput value={code} onChange={setCode} disabled={loading} />
|
|
||||||
|
|
||||||
<div style={{ position: 'relative' }}>
|
|
||||||
<input
|
|
||||||
type={showPassword ? 'text' : 'password'}
|
|
||||||
placeholder="New password"
|
|
||||||
value={newPassword}
|
|
||||||
onChange={(e) => setNewPassword(e.target.value)}
|
|
||||||
style={{
|
|
||||||
background: '#f4f7f4',
|
|
||||||
border: 'none',
|
|
||||||
borderRadius: '12px',
|
|
||||||
padding: '0 40px 0 14px',
|
|
||||||
height: '48px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '400',
|
|
||||||
color: '#0f1720',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
required
|
|
||||||
minLength={6}
|
|
||||||
/>
|
|
||||||
<IonIcon
|
|
||||||
icon={showPassword ? eyeOffOutline : eyeOutline}
|
|
||||||
onClick={() => setShowPassword(!showPassword)}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
right: '14px',
|
|
||||||
top: '14px',
|
|
||||||
fontSize: '20px',
|
|
||||||
color: '#8a978f',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={loading || code.length !== 6 || !newPassword}
|
|
||||||
style={{
|
|
||||||
background: '#166534',
|
|
||||||
color: '#ffffff',
|
|
||||||
borderRadius: '999px',
|
|
||||||
padding: '16px 20px',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '700',
|
|
||||||
border: 'none',
|
|
||||||
cursor: 'pointer',
|
|
||||||
opacity: loading || code.length !== 6 || !newPassword ? 0.7 : 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<IonSpinner
|
|
||||||
name="crescent"
|
|
||||||
style={{ color: '#fff', width: '20px', height: '20px' }}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
'Reset Password'
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={handleResend}
|
|
||||||
disabled={cooldown > 0}
|
|
||||||
style={{
|
|
||||||
background: 'transparent',
|
|
||||||
border: 'none',
|
|
||||||
padding: '0',
|
|
||||||
fontSize: '14px',
|
|
||||||
fontWeight: '600',
|
|
||||||
color: cooldown > 0 ? '#8a978f' : '#f59e0b',
|
|
||||||
cursor: cooldown > 0 ? 'default' : 'pointer',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{cooldown > 0 ? `Resend code in ${cooldown}s` : 'Resend code'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{overlayVisible && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
background: 'rgba(255,255,255,0.9)',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
zIndex: 9999,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{overlayError ? (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
color: '#b91c1c',
|
|
||||||
fontSize: '15px',
|
|
||||||
fontWeight: '600',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Error updating profile.
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<IonSpinner name="crescent" style={{ color: '#166534' }} />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default VerifyReset;
|
|
||||||
@@ -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://ilffyqxtkssvqmszsfyw.supabase.co',
|
'https://kxejpmyjfdrbaupauexc.supabase.co',
|
||||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImlsZmZ5cXh0a3NzdnFtc3pzZnl3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODE5MDQ2NTIsImV4cCI6MjA5NzQ4MDY1Mn0.xvCQEtNrr74KX8uD7enFktfFJhuFrSm6kFih1SlLFgk',
|
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imt4ZWpwbXlqZmRyYmF1cGF1ZXhjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODM2OTkzMzksImV4cCI6MjA5OTI3NTMzOX0.FteANsPY4x605R26bxC6sR4iiYbw_nwG4zrcDYEH83Y',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,114 +1,73 @@
|
|||||||
/* Ionic CSS Variables */
|
/* Ionic Variables and Color Palette */
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
/** primary (QuoteLink forest green) **/
|
--ion-color-primary: #7b2d26;
|
||||||
--ion-color-primary: #166534;
|
--ion-color-primary-rgb: 123, 45, 38;
|
||||||
--ion-color-primary-rgb: 22, 101, 52;
|
|
||||||
--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: #14532d;
|
--ion-color-primary-shade: #6c2721;
|
||||||
--ion-color-primary-tint: #2b7a45;
|
--ion-color-primary-tint: #883f3a;
|
||||||
|
|
||||||
/** secondary (logo price-tag orange) **/
|
--ion-color-secondary: #b07a3a;
|
||||||
--ion-color-secondary: #f7931a;
|
--ion-color-secondary-rgb: 176, 122, 58;
|
||||||
--ion-color-secondary-rgb: 247, 147, 26;
|
|
||||||
--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: #d97d12;
|
--ion-color-secondary-shade: #9b6b33;
|
||||||
--ion-color-secondary-tint: #f9a640;
|
--ion-color-secondary-tint: #b8894e;
|
||||||
|
|
||||||
--color-brand: #166534;
|
--ion-background-color: #f8f4ef;
|
||||||
--color-brand-strong: #14532d;
|
--color-bg: #f8f4ef;
|
||||||
--color-brand-soft: rgba(22, 101, 52, 0.1);
|
|
||||||
--color-brand-medium: rgba(22, 101, 52, 0.18);
|
|
||||||
--color-accent: #f7931a;
|
|
||||||
--color-accent-strong: #ea8200;
|
|
||||||
--color-accent-soft: rgba(247, 147, 26, 0.14);
|
|
||||||
--color-bg: #f3f4f1;
|
|
||||||
--color-bg-gradient: linear-gradient(
|
|
||||||
180deg,
|
|
||||||
#eef1ee 0%,
|
|
||||||
#f7f8f5 52%,
|
|
||||||
#fbfcfa 100%
|
|
||||||
);
|
|
||||||
--color-surface: #ffffff;
|
--color-surface: #ffffff;
|
||||||
--color-surface-raised: #eef2ee;
|
--color-surface-raised: #f2ece4;
|
||||||
--color-surface-soft: #f7f8f6;
|
--color-brand: #7b2d26;
|
||||||
--color-text-primary: #18212b;
|
--color-brand-soft: rgba(123, 45, 38, 0.1);
|
||||||
--color-text-secondary: rgba(24, 33, 43, 0.64);
|
--color-brand-medium: rgba(123, 45, 38, 0.18);
|
||||||
--color-text-tertiary: rgba(24, 33, 43, 0.42);
|
|
||||||
--color-border: rgba(23, 33, 43, 0.08);
|
|
||||||
--color-success-soft: rgba(22, 101, 52, 0.12);
|
|
||||||
--color-success-text: #166534;
|
|
||||||
--color-warning-soft: rgba(247, 147, 26, 0.14);
|
|
||||||
--color-warning-text: #c36a00;
|
|
||||||
--color-danger-soft: rgba(220, 38, 38, 0.1);
|
|
||||||
--color-danger-text: #b91c1c;
|
|
||||||
--color-shell: rgba(255, 255, 255, 0.58);
|
|
||||||
--color-shadow-lg:
|
|
||||||
0 24px 60px rgba(23, 33, 43, 0.08), 0 8px 20px rgba(23, 33, 43, 0.04);
|
|
||||||
--color-shadow-sm: 0 4px 16px rgba(23, 33, 43, 0.05);
|
|
||||||
|
|
||||||
/* Backwards-compatible aliases */
|
--ion-text-color: #2f221d;
|
||||||
--color-surface-hover: var(--color-surface-soft);
|
--ion-text-color-rgb: 47, 34, 29;
|
||||||
--color-text-main: var(--color-text-primary);
|
--color-text-primary: #2f221d;
|
||||||
--color-text-muted: var(--color-text-secondary);
|
--color-text-secondary: rgba(47, 34, 29, 0.64);
|
||||||
|
--color-text-tertiary: rgba(47, 34, 29, 0.42);
|
||||||
|
--color-border: rgba(47, 34, 29, 0.08);
|
||||||
|
|
||||||
/* Basic Ionic variables */
|
--ion-color-success: #7b2d26;
|
||||||
--ion-background-color: var(--color-bg);
|
--ion-color-warning: #d29a3f;
|
||||||
--ion-text-color: var(--color-text-primary);
|
--ion-color-danger: #a33b32;
|
||||||
|
--ion-color-medium: #8e7d73;
|
||||||
--ion-font-family:
|
--ion-color-light: #f8f4ef;
|
||||||
Inter, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Roboto',
|
|
||||||
sans-serif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body.dark {
|
@media (prefers-color-scheme: dark) {
|
||||||
--ion-color-primary: #0f3d2e;
|
:root {
|
||||||
--ion-color-primary-rgb: 15, 61, 46;
|
--ion-background-color: #201513;
|
||||||
--ion-color-primary-contrast: #ffffff;
|
--color-bg: #201513;
|
||||||
--ion-color-primary-contrast-rgb: 255, 255, 255;
|
--color-surface: #2b1c19;
|
||||||
--ion-color-primary-shade: #0c3125;
|
--color-surface-raised: #3a2723;
|
||||||
--ion-color-primary-tint: #295746;
|
--color-brand: #c7865f;
|
||||||
|
--color-brand-soft: rgba(199, 134, 95, 0.14);
|
||||||
|
--color-brand-medium: rgba(199, 134, 95, 0.22);
|
||||||
|
|
||||||
--ion-color-secondary: #f57c00;
|
--ion-text-color: #f5ebe3;
|
||||||
--ion-color-secondary-rgb: 245, 124, 0;
|
--ion-text-color-rgb: 245, 235, 227;
|
||||||
--ion-color-secondary-contrast: #ffffff;
|
--color-text-primary: #f5ebe3;
|
||||||
--ion-color-secondary-contrast-rgb: 255, 255, 255;
|
--color-text-secondary: rgba(245, 235, 227, 0.68);
|
||||||
--ion-color-secondary-shade: #d66d00;
|
--color-text-tertiary: rgba(245, 235, 227, 0.44);
|
||||||
--ion-color-secondary-tint: #f78f26;
|
|
||||||
|
|
||||||
--color-brand: #0f3d2e;
|
--ion-color-primary: #c7865f;
|
||||||
--color-brand-strong: #145340;
|
--ion-color-primary-rgb: 199, 134, 95;
|
||||||
--color-brand-soft: rgba(15, 61, 46, 0.28);
|
--ion-color-primary-contrast: #201513;
|
||||||
--color-brand-medium: rgba(15, 61, 46, 0.42);
|
--ion-color-primary-contrast-rgb: 32, 21, 19;
|
||||||
--color-accent: #f57c00;
|
--ion-color-primary-shade: #b27754;
|
||||||
--color-accent-strong: #ff9831;
|
--ion-color-primary-tint: #cd9270;
|
||||||
--color-accent-soft: rgba(245, 124, 0, 0.18);
|
}
|
||||||
--color-bg: #121212;
|
}
|
||||||
--color-bg-gradient: linear-gradient(
|
|
||||||
180deg,
|
html,
|
||||||
#151515 0%,
|
body {
|
||||||
#121212 55%,
|
background-color: var(--color-bg);
|
||||||
#101010 100%
|
}
|
||||||
);
|
|
||||||
--color-surface: #1b1b1b;
|
.page-shell {
|
||||||
--color-surface-raised: #242424;
|
padding: calc(var(--ion-safe-area-top, 0px) + 18px) 20px
|
||||||
--color-surface-soft: #202020;
|
calc(var(--ion-safe-area-bottom, 0px) + 28px);
|
||||||
--color-text-primary: #f4f4f4;
|
|
||||||
--color-text-secondary: rgba(244, 244, 244, 0.72);
|
|
||||||
--color-text-tertiary: rgba(244, 244, 244, 0.48);
|
|
||||||
--color-border: rgba(255, 255, 255, 0.08);
|
|
||||||
--color-success-soft: rgba(29, 185, 84, 0.16);
|
|
||||||
--color-success-text: #78d29a;
|
|
||||||
--color-warning-soft: rgba(245, 124, 0, 0.2);
|
|
||||||
--color-warning-text: #ffb15c;
|
|
||||||
--color-danger-soft: rgba(255, 99, 99, 0.16);
|
|
||||||
--color-danger-text: #ff8f8f;
|
|
||||||
--color-shell: rgba(33, 33, 33, 0.76);
|
|
||||||
--color-shadow-lg:
|
|
||||||
0 24px 60px rgba(0, 0, 0, 0.34), 0 8px 20px rgba(0, 0, 0, 0.22);
|
|
||||||
--color-shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.24);
|
|
||||||
|
|
||||||
--ion-background-color: var(--color-bg);
|
|
||||||
--ion-text-color: var(--color-text-primary);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
export interface EventCategory {
|
||||||
|
id: string;
|
||||||
|
slug: string;
|
||||||
|
name: string;
|
||||||
|
accent_color: string;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChurchEvent {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
category_id: string;
|
||||||
|
audience: 'all' | 'youth' | 'children';
|
||||||
|
venue: string;
|
||||||
|
start_at: string;
|
||||||
|
end_at: string | null;
|
||||||
|
day_label: string;
|
||||||
|
is_featured: boolean;
|
||||||
|
created_by: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
event_categories?: EventCategory; // Relation
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NewsItem {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
content: string;
|
||||||
|
image_url: string | null;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
created_by: string;
|
||||||
|
}
|
||||||
@@ -17,8 +17,18 @@ const injectRouterBasename: Plugin = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hideScrollbars: Plugin = {
|
||||||
|
name: 'hide-scrollbars',
|
||||||
|
transformIndexHtml(html) {
|
||||||
|
return html.replace(
|
||||||
|
'</head>',
|
||||||
|
'<style>*{scrollbar-width:none!important;-ms-overflow-style:none!important}*::-webkit-scrollbar{display:none!important}</style></head>',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [injectRouterBasename, react()],
|
plugins: [injectRouterBasename, hideScrollbars, react()],
|
||||||
server: {
|
server: {
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: 8100,
|
port: 8100,
|
||||||
|
|||||||
@@ -1373,9 +1373,9 @@ __metadata:
|
|||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@protobufjs/utf8@npm:^1.1.1":
|
"@protobufjs/utf8@npm:^1.1.1":
|
||||||
version: 1.1.1
|
version: 1.1.2
|
||||||
resolution: "@protobufjs/utf8@npm:1.1.1"
|
resolution: "@protobufjs/utf8@npm:1.1.2"
|
||||||
checksum: 10c0/641fc145f00626405e8984b6e90b9edcbcc072ffc82d0647ca3176e09c730b2d022f988e65f011a7a17e2e4d77cde7733643aa10d8ac2bfa30f134dbcad553fd
|
checksum: 10c0/975c6e2c0319bd50c17531d186b537a88cb4d3205e3ca9297cd842b631d341da0ee3ff16be8656cd2660756dc753b29c8a6a14c0ad8ed602c1f91ddf22e7b3f3
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -1743,70 +1743,70 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@supabase/auth-js@npm:2.108.2":
|
"@supabase/auth-js@npm:2.110.2":
|
||||||
version: 2.108.2
|
version: 2.110.2
|
||||||
resolution: "@supabase/auth-js@npm:2.108.2"
|
resolution: "@supabase/auth-js@npm:2.110.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: "npm:2.8.1"
|
tslib: "npm:2.8.1"
|
||||||
checksum: 10c0/31617770accb5910c1e7d19f230e3f1e5e1fd3e78912ea5ae342dddb7e032f58fb1d277560eae9a7892ef2d20b03c4989118a9ff17cb48aa5e7dd99eb566fb02
|
checksum: 10c0/3cb1bd3e78498c964ed897032fc09e19a5d8640c1d6b0edbf66a9cad5884547b9107d769f327a556ffab848656fca0de405ba9b961f38b71d44870c28d7b3bd6
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@supabase/functions-js@npm:2.108.2":
|
"@supabase/functions-js@npm:2.110.2":
|
||||||
version: 2.108.2
|
version: 2.110.2
|
||||||
resolution: "@supabase/functions-js@npm:2.108.2"
|
resolution: "@supabase/functions-js@npm:2.110.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: "npm:2.8.1"
|
tslib: "npm:2.8.1"
|
||||||
checksum: 10c0/06e899cd3445f519f8f595c648b8fa38f174f01335b18cf1ebcc87efc7cede997896e6b06c74747b4275c7b2514accee26d5ee0d4bb2bf5fc757c82070435624
|
checksum: 10c0/1e6de0a6e6304b1c2593d5ddf232a996688f8c442eb00a704f6b20d2042ae0246240f93c9dc1f5e2a936602c7b9f1ffcdd95921672d2790b30882baa24406b9d
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@supabase/phoenix@npm:^0.4.2":
|
"@supabase/phoenix@npm:0.4.4":
|
||||||
version: 0.4.4
|
version: 0.4.4
|
||||||
resolution: "@supabase/phoenix@npm:0.4.4"
|
resolution: "@supabase/phoenix@npm:0.4.4"
|
||||||
checksum: 10c0/b4ba930c82b20d412358826aa87ce0735147fd168efb817bfc34e31d78605220947dc7c5844726268ac6bf338f0cd081f9908a7bab87aaff4058cb80bf71ab5b
|
checksum: 10c0/b4ba930c82b20d412358826aa87ce0735147fd168efb817bfc34e31d78605220947dc7c5844726268ac6bf338f0cd081f9908a7bab87aaff4058cb80bf71ab5b
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@supabase/postgrest-js@npm:2.108.2":
|
"@supabase/postgrest-js@npm:2.110.2":
|
||||||
version: 2.108.2
|
version: 2.110.2
|
||||||
resolution: "@supabase/postgrest-js@npm:2.108.2"
|
resolution: "@supabase/postgrest-js@npm:2.110.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: "npm:2.8.1"
|
tslib: "npm:2.8.1"
|
||||||
checksum: 10c0/eafb794763943f1c72683157785e325647e5cc8eb17904b6922b896b5c25f0be75c11376cb7a518b6f6ee983ad7d94a509e75950533f3da4fcf8f910f1e11433
|
checksum: 10c0/d08f91dbd924d39ce194a7a698ce0a56b61208efd5642368ede0ff9c419cff026da477293b11870c02850bf8e31f69148fce71a051794af83f1175c12b951d9c
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@supabase/realtime-js@npm:2.108.2":
|
"@supabase/realtime-js@npm:2.110.2":
|
||||||
version: 2.108.2
|
version: 2.110.2
|
||||||
resolution: "@supabase/realtime-js@npm:2.108.2"
|
resolution: "@supabase/realtime-js@npm:2.110.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@supabase/phoenix": "npm:^0.4.2"
|
"@supabase/phoenix": "npm:0.4.4"
|
||||||
tslib: "npm:2.8.1"
|
tslib: "npm:2.8.1"
|
||||||
checksum: 10c0/3a5c19c4283b64cf22e91d264580905de0a724376314acf6a9f9e53ae74ba05bad679eaf57fe5c31e95213608c1bd065485127824bed377500b021d01cec0454
|
checksum: 10c0/3b6bca9a6e629293b3e41be467a99ac311ebd1ff581979abbd91da646312e7f1f6a2b944ff6d9c409532aa4271f8ad5b23a028546c14d3c0fadcc0a76799af69
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@supabase/storage-js@npm:2.108.2":
|
"@supabase/storage-js@npm:2.110.2":
|
||||||
version: 2.108.2
|
version: 2.110.2
|
||||||
resolution: "@supabase/storage-js@npm:2.108.2"
|
resolution: "@supabase/storage-js@npm:2.110.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
iceberg-js: "npm:^0.8.1"
|
iceberg-js: "npm:^0.8.1"
|
||||||
tslib: "npm:2.8.1"
|
tslib: "npm:2.8.1"
|
||||||
checksum: 10c0/9e7ed4560150012ea8fa45c12b180533f166d6900b4a61e1a2bbf7f12e872ea42f85670db3dc781b7e76f983f5c9d320d84574775969d18804c6a0ca4aa44e7d
|
checksum: 10c0/a672ac600a5f37ccc196b3a5e8e17f6d57d142b8bed7ab979d69d664d4782dd050e5c3166280b5f1753b18911de7529d43487c02c1e1d1efef20c0b53deb503d
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@supabase/supabase-js@npm:^2.108.1":
|
"@supabase/supabase-js@npm:^2.108.1":
|
||||||
version: 2.108.2
|
version: 2.110.2
|
||||||
resolution: "@supabase/supabase-js@npm:2.108.2"
|
resolution: "@supabase/supabase-js@npm:2.110.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@supabase/auth-js": "npm:2.108.2"
|
"@supabase/auth-js": "npm:2.110.2"
|
||||||
"@supabase/functions-js": "npm:2.108.2"
|
"@supabase/functions-js": "npm:2.110.2"
|
||||||
"@supabase/postgrest-js": "npm:2.108.2"
|
"@supabase/postgrest-js": "npm:2.110.2"
|
||||||
"@supabase/realtime-js": "npm:2.108.2"
|
"@supabase/realtime-js": "npm:2.110.2"
|
||||||
"@supabase/storage-js": "npm:2.108.2"
|
"@supabase/storage-js": "npm:2.110.2"
|
||||||
checksum: 10c0/1e627189af3d8088329fdbdfbff754285dd757f30d7d4e0415881d75b684143b6c1fe519449b69d4b30b52f732a7f4510566718640826a966e124c8331becbfb
|
checksum: 10c0/5ec5432898bc801e871b7aa700429f6e97a77fb70b61de456b6d1e6f84feccab689fdbc4efdfc44fb4c74d48bcde3446c4cf26fcbfa72c787005efe4a72981c2
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -1905,11 +1905,11 @@ __metadata:
|
|||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@types/node@npm:>=12.12.47, @types/node@npm:>=13.7.0":
|
"@types/node@npm:>=12.12.47, @types/node@npm:>=13.7.0":
|
||||||
version: 26.0.0
|
version: 26.1.1
|
||||||
resolution: "@types/node@npm:26.0.0"
|
resolution: "@types/node@npm:26.1.1"
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: "npm:~8.3.0"
|
undici-types: "npm:~8.3.0"
|
||||||
checksum: 10c0/f36e21634fd8e8ded162ca486508bd8bb229d398a8d5541f6d8c1255968d4464e53327a77f403b216ef98e3b6f6956882eef83e4857d4bc2be9569dd55d37aae
|
checksum: 10c0/25ac5093195736dd074d5027adbba85617bc951d5a41506ebd3b9073048acb7233613f3822d5f9b9447f9c0841c91f6387c46283916767e3ef79f23917452c46
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -2389,9 +2389,9 @@ __metadata:
|
|||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"fast-equals@npm:^5.2.2":
|
"fast-equals@npm:^5.2.2":
|
||||||
version: 5.4.0
|
version: 5.4.1
|
||||||
resolution: "fast-equals@npm:5.4.0"
|
resolution: "fast-equals@npm:5.4.1"
|
||||||
checksum: 10c0/4fdce3a8f814e78af7296ca4ebe82f4765074a6dfe557ee98c18f5d2958c3de59025fbff7556d65f250165ccef424d37f9952ee159400f8ebe5f2edb704ec80e
|
checksum: 10c0/18faf5894c39591d61e802b2f574cbc57d2ff2530c71b8cd4e2b4f3c250174002a9aa0b5f4d6f61073a9942a96d71bc7f36514a9b0dc9a2a5cc3395b2a910dbf
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -2991,8 +2991,8 @@ __metadata:
|
|||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"protobufjs@npm:^7.2.5":
|
"protobufjs@npm:^7.2.5":
|
||||||
version: 7.6.4
|
version: 7.6.5
|
||||||
resolution: "protobufjs@npm:7.6.4"
|
resolution: "protobufjs@npm:7.6.5"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@protobufjs/aspromise": "npm:^1.1.2"
|
"@protobufjs/aspromise": "npm:^1.1.2"
|
||||||
"@protobufjs/base64": "npm:^1.1.2"
|
"@protobufjs/base64": "npm:^1.1.2"
|
||||||
@@ -3005,7 +3005,7 @@ __metadata:
|
|||||||
"@protobufjs/utf8": "npm:^1.1.1"
|
"@protobufjs/utf8": "npm:^1.1.1"
|
||||||
"@types/node": "npm:>=13.7.0"
|
"@types/node": "npm:>=13.7.0"
|
||||||
long: "npm:^5.3.2"
|
long: "npm:^5.3.2"
|
||||||
checksum: 10c0/6403eaa9c5a72cc6450c11f38fefafdde243fd806e7ac606ac8d591bc3fdaec45ae764febf83181a2d9aac51aca624e0f46dec368ceea191f7e85e2d6ccaaf93
|
checksum: 10c0/863eaca9c6f45bfcfb8787c545f53e9c6696507e328e3981b4643c12d35df7f2826021c10e3fd30bef342c13a8e9d306547bac9c0849ee3bf50f770a12f01dc5
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|||||||