Compare commits
152 Commits
v-2.0.5
...
amalia/09-
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ab8422808 | |||
| 3370f48238 | |||
| 9cd78dae3a | |||
| 209254af23 | |||
| 6c80eb77fb | |||
| ae96a79b69 | |||
| a5c58d0de2 | |||
| c979a68028 | |||
| 2cf5c8d960 | |||
| 9dc4d8dc8d | |||
| 789e4f84f1 | |||
| 99c13b57e1 | |||
| 47ed52e9d2 | |||
| 02904b1e48 | |||
| 8df5b48578 | |||
| 21617f9c4c | |||
| 383ca069d5 | |||
| 267454637f | |||
| f939ddb5f5 | |||
| e135c9dc11 | |||
| 144db584d0 | |||
| 90551399a5 | |||
| 0d46d76c70 | |||
| e3d2752a4c | |||
| 4dcfcbb7a7 | |||
| f27707eb74 | |||
| e4e8b44c45 | |||
| 79c9c9046c | |||
| f6122fb35a | |||
| 2ae88ff2e3 | |||
| fbf25bdd59 | |||
| 600218cb11 | |||
| 18eea92cfd | |||
| 1c3aa308d1 | |||
| c21d928701 | |||
| d8a50cbc75 | |||
| 59459e2c22 | |||
| a61c194ece | |||
| 2be59b5ac6 | |||
| d272b96e53 | |||
| 6d0203cc7d | |||
| 165f423798 | |||
| 0cb085caa8 | |||
| 2bacc47d75 | |||
| fcd3dc7537 | |||
| 0cbf12eea7 | |||
| 85aca330e5 | |||
| 3f113a4049 | |||
| f873921325 | |||
| 90419b5d15 | |||
| ecb3d3953b | |||
| 9ca128a5ed | |||
| d299484a98 | |||
| 003d92e4e3 | |||
| 18f548ed5c | |||
| 906a619593 | |||
| af2048b4cd | |||
| 7341f378dd | |||
| 84935e8188 | |||
| 74d8b8ef31 | |||
| d31a21cc9c | |||
| 4af54980a0 | |||
| 4eebf2f893 | |||
| bc2c89e030 | |||
| d96c954559 | |||
| ca512372dd | |||
| d82f0c5b20 | |||
| fad89fc910 | |||
| e48456ea7f | |||
| d2e1663f9f | |||
| bdfb3a8b2b | |||
| 11bb1ddc98 | |||
| 97726609e1 | |||
| b61cd51628 | |||
| eccfe29387 | |||
| a090a85142 | |||
| bbacc2a5bd | |||
| 5ad7874a92 | |||
| a5e379cc7f | |||
| 4d464adb2e | |||
| 36c2519fa0 | |||
| e2ffef1085 | |||
| cb2a57ee8e | |||
| f3b677f847 | |||
| 6ffe599ad0 | |||
| 4a92def490 | |||
| 0bad792ce8 | |||
| 6c9623954c | |||
| f39d5a4c85 | |||
| 6021d17b5a | |||
| 2d86a77a48 | |||
| b7165c5990 | |||
| 7dc51bd2b9 | |||
| de5ad545a7 | |||
| 47cb146c5a | |||
| 8b8ea61a13 | |||
| 5dac451754 | |||
| ccf8ee1caf | |||
| 887e787a99 | |||
| 772551a917 | |||
| 555b9e4037 | |||
| d4b4db4251 | |||
| 17d92cba25 | |||
| e1b62be6da | |||
| b2b125c410 | |||
| 1cfecbbdd5 | |||
| 21006e8eee | |||
| 91231d60e4 | |||
| 7174e27be1 | |||
| 9d4b931aa6 | |||
| 166d8f1c16 | |||
| 7060a2d165 | |||
| d6217aecf1 | |||
| 608381673f | |||
| 3cc7f76346 | |||
| 868b712fbb | |||
| a53b99b39d | |||
| 25d521f013 | |||
| aee0823cb1 | |||
| 2a0e1f4c1f | |||
| ef08c821fa | |||
| fd5d582092 | |||
| 7729dc38f8 | |||
| 8c6ff06216 | |||
| 214a243e44 | |||
| 449f6f96cc | |||
| d1dec49784 | |||
| e351f54f6c | |||
| 3809d382fa | |||
| d58a35bde2 | |||
| 86b9fa6396 | |||
| 6770d40b41 | |||
| 77f478b7ca | |||
| e2a601c590 | |||
| 4681f0a0cc | |||
| 31b7cf6a30 | |||
| 64aaafa2be | |||
| 42cb7c8f8e | |||
| 8c63c08bc3 | |||
| 6ca935483a | |||
| 039b26f5aa | |||
| 10212aa5de | |||
| f0373ef479 | |||
| acacf9c125 | |||
| 700192dd8d | |||
| 4df0a44ac9 | |||
| 27b0b7d51f | |||
| 8012f7f322 | |||
| 65278df750 | |||
| 064a8ccaad | |||
| 8b98fee632 | |||
| d3802ca26c |
37
CLAUDE.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
**Desa+** is a React Native (Expo) mobile app for village administration — managing announcements, projects, discussions, members, divisions, and documents. Primary platforms are Android and iOS.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run start # Start Expo dev server
|
||||||
|
npm run android # Run on Android
|
||||||
|
npm run ios # Run on iOS
|
||||||
|
npm run lint # Expo lint
|
||||||
|
npm run test # Jest tests
|
||||||
|
npm run build:android # Production Android build via EAS (bumps version first)
|
||||||
|
```
|
||||||
|
|
||||||
|
Run a single test file:
|
||||||
|
```bash
|
||||||
|
bunx jest path/to/test.tsx --no-coverage
|
||||||
|
```
|
||||||
|
|
||||||
|
> Project uses **Bun** as the package manager (`bun.lock` present). Use `bun add` / `bunx` instead of `npm install` / `npx`.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
See @docs/ARCHITECTURE.md
|
||||||
|
|
||||||
|
## Key Conventions
|
||||||
|
|
||||||
|
See @docs/CONVENTIONS.md
|
||||||
|
|
||||||
|
## File Health
|
||||||
|
|
||||||
|
See @docs/FILE-HEALTH.md
|
||||||
86
GEMINI.md
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# Project Overview: Desa+
|
||||||
|
|
||||||
|
Desa+ is a mobile application built with React Native and Expo, designed to facilitate management and communication within villages/communities. It aims to streamline village administration, inter-community communication, and the management of essential information.
|
||||||
|
|
||||||
|
## Key Features:
|
||||||
|
- Village announcements and information
|
||||||
|
- Community discussion forum
|
||||||
|
- Village activity calendar
|
||||||
|
- Village documentation and archives
|
||||||
|
- Project and task management
|
||||||
|
- Member and organizational structure management
|
||||||
|
- Push notifications for important updates
|
||||||
|
- Verification and authentication features
|
||||||
|
|
||||||
|
## Technologies Used:
|
||||||
|
- **React Native**: Cross-platform mobile development framework.
|
||||||
|
- **Expo**: Platform for React Native application development.
|
||||||
|
- **Firebase**: Backend services including Authentication, Realtime Database, and Cloud Messaging.
|
||||||
|
- **Redux Toolkit**: State management.
|
||||||
|
- **React Navigation**: Application navigation.
|
||||||
|
- **TypeScript**: For type safety.
|
||||||
|
|
||||||
|
## Building and Running:
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
1. **Clone the repository:**
|
||||||
|
```bash
|
||||||
|
git clone <repository-url>
|
||||||
|
cd mobile-darmasaba
|
||||||
|
```
|
||||||
|
2. **Install dependencies:**
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
3. **Configure environment variables:**
|
||||||
|
Create a `.env` file in the root directory and add the following variables:
|
||||||
|
```
|
||||||
|
URL_API=<api-endpoint>
|
||||||
|
URL_OTP=<otp-service-endpoint>
|
||||||
|
URL_STORAGE=<storage-endpoint>
|
||||||
|
URL_FIREBASE_DB=<firebase-database-url>
|
||||||
|
PASS_ENC=<encryption-password>
|
||||||
|
WA_SERVER_TOKEN=<whatsapp-server-token>
|
||||||
|
IOS_GOOGLE_SERVICES_FILE=<path-to-ios-google-services>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running the Application
|
||||||
|
- **Start development server:**
|
||||||
|
```bash
|
||||||
|
npx expo start
|
||||||
|
```
|
||||||
|
- **Run on Android emulator/device:**
|
||||||
|
```bash
|
||||||
|
npm run android
|
||||||
|
```
|
||||||
|
- **Run on iOS simulator/device:**
|
||||||
|
```bash
|
||||||
|
npm run ios
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build Production
|
||||||
|
- **Build Android production package:**
|
||||||
|
```bash
|
||||||
|
npm run build:android
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development Conventions:
|
||||||
|
|
||||||
|
### Project Structure:
|
||||||
|
- `app/`: Main page files.
|
||||||
|
- `components/`: Reusable UI components, categorized by feature (e.g., `announcement/`, `auth/`, `discussion/`).
|
||||||
|
- `assets/`: Images and static assets.
|
||||||
|
- `constants/`: Global constants.
|
||||||
|
- `lib/`: Libraries and utilities.
|
||||||
|
|
||||||
|
### Contribution Guidelines:
|
||||||
|
1. Fork the repository.
|
||||||
|
2. Create a new feature branch (`git checkout -b feature/FeatureName`).
|
||||||
|
3. Commit your changes (`git commit -m 'Add FeatureName feature'`).
|
||||||
|
4. Push to the branch (`git push origin feature/FeatureName`).
|
||||||
|
5. Create a pull request.
|
||||||
|
|
||||||
|
## Platform Support:
|
||||||
|
- ✅ Android
|
||||||
|
- ✅ iOS
|
||||||
|
- ❌ Web (not yet optimized)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Desa+
|
# Desa+
|
||||||
|
|
||||||
Desa+ adalah aplikasi mobile berbasis React Native yang dikembangkan dengan Expo untuk membantu pengelolaan dan komunikasi di lingkungan desa/kelurahan. Aplikasi ini menyediakan berbagai fitur untuk memudahkan administrasi desa, komunikasi antar warga, dan pengelolaan informasi penting.
|
Desa+ (Desa Plus) adalah aplikasi mobile berbasis React Native yang dikembangkan dengan Expo untuk membantu pengelolaan dan komunikasi di lingkungan desa/kelurahan. Aplikasi ini menyediakan berbagai fitur untuk memudahkan administrasi desa, komunikasi antar warga, dan pengelolaan informasi penting.
|
||||||
|
|
||||||
## Fitur Utama
|
## Fitur Utama
|
||||||
|
|
||||||
|
|||||||
77
__tests__/ErrorBoundary-test.tsx
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { render, fireEvent } from '@testing-library/react-native';
|
||||||
|
import ErrorBoundary from '@/components/ErrorBoundary';
|
||||||
|
|
||||||
|
// Komponen yang sengaja throw error saat render
|
||||||
|
const BrokenComponent = () => {
|
||||||
|
throw new Error('Test error boundary!');
|
||||||
|
};
|
||||||
|
|
||||||
|
// Komponen normal
|
||||||
|
const NormalComponent = () => <></>;
|
||||||
|
|
||||||
|
// Suppress React's error boundary console output selama test
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
(console.error as jest.Mock).mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ErrorBoundary', () => {
|
||||||
|
it('merender children dengan normal jika tidak ada error', () => {
|
||||||
|
// Tidak boleh throw dan tidak menampilkan teks error
|
||||||
|
const { queryByText } = render(
|
||||||
|
<ErrorBoundary>
|
||||||
|
<NormalComponent />
|
||||||
|
</ErrorBoundary>
|
||||||
|
);
|
||||||
|
expect(queryByText('Terjadi Kesalahan')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('menampilkan UI fallback ketika child throw error', () => {
|
||||||
|
const { getByText } = render(
|
||||||
|
<ErrorBoundary>
|
||||||
|
<BrokenComponent />
|
||||||
|
</ErrorBoundary>
|
||||||
|
);
|
||||||
|
expect(getByText('Terjadi Kesalahan')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('menampilkan pesan error yang dilempar', () => {
|
||||||
|
const { getByText } = render(
|
||||||
|
<ErrorBoundary>
|
||||||
|
<BrokenComponent />
|
||||||
|
</ErrorBoundary>
|
||||||
|
);
|
||||||
|
expect(getByText('Test error boundary!')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('merender custom fallback jika prop fallback diberikan', () => {
|
||||||
|
const { getByText } = render(
|
||||||
|
<ErrorBoundary fallback={<></>}>
|
||||||
|
<BrokenComponent />
|
||||||
|
</ErrorBoundary>
|
||||||
|
);
|
||||||
|
// Custom fallback fragment kosong — pastikan teks default tidak muncul
|
||||||
|
expect(() => getByText('Terjadi Kesalahan')).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('mereset error state saat tombol Coba Lagi ditekan', () => {
|
||||||
|
const { getByText } = render(
|
||||||
|
<ErrorBoundary>
|
||||||
|
<BrokenComponent />
|
||||||
|
</ErrorBoundary>
|
||||||
|
);
|
||||||
|
|
||||||
|
const button = getByText('Coba Lagi');
|
||||||
|
expect(button).toBeTruthy();
|
||||||
|
|
||||||
|
// Tekan tombol reset — hasError kembali false, BrokenComponent throw lagi
|
||||||
|
// sehingga fallback muncul kembali (membuktikan reset berjalan)
|
||||||
|
fireEvent.press(button);
|
||||||
|
expect(getByText('Terjadi Kesalahan')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
kotlin version: 2.0.21
|
|
||||||
error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output:
|
|
||||||
1. Kotlin compile daemon is ready
|
|
||||||
|
|
||||||
@@ -92,8 +92,8 @@ android {
|
|||||||
applicationId 'mobiledarmasaba.app'
|
applicationId 'mobiledarmasaba.app'
|
||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 6
|
versionCode 21
|
||||||
versionName "1.0.2"
|
versionName "2.2.0"
|
||||||
}
|
}
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
debug {
|
debug {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
|
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
|
||||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
|
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" tools:node="remove"/>
|
||||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
|
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" tools:node="remove"/>
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
||||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.0 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 904 B |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 5.2 KiB |
@@ -1,9 +1,9 @@
|
|||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
|
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||||
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
|
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
|
||||||
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
|
|
||||||
<item name="colorPrimary">@color/colorPrimary</item>
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
<item name="android:statusBarColor">#ffffff</item>
|
<item name="android:statusBarColor">#ffffff</item>
|
||||||
|
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
|
||||||
</style>
|
</style>
|
||||||
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
|
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
|
||||||
<item name="windowSplashScreenBackground">@color/splashscreen_background</item>
|
<item name="windowSplashScreenBackground">@color/splashscreen_background</item>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export default {
|
|||||||
expo: {
|
expo: {
|
||||||
name: "Desa+",
|
name: "Desa+",
|
||||||
slug: "mobile-darmasaba",
|
slug: "mobile-darmasaba",
|
||||||
version: "2.0.5", // Versi aplikasi (App Store)
|
version: "2.2.0", // Versi aplikasi (App Store)
|
||||||
jsEngine: "jsc",
|
jsEngine: "jsc",
|
||||||
orientation: "portrait",
|
orientation: "portrait",
|
||||||
icon: "./assets/images/logo-icon-small.png",
|
icon: "./assets/images/logo-icon-small.png",
|
||||||
@@ -14,7 +14,7 @@ export default {
|
|||||||
ios: {
|
ios: {
|
||||||
supportsTablet: true,
|
supportsTablet: true,
|
||||||
bundleIdentifier: "mobiledarmasaba.app",
|
bundleIdentifier: "mobiledarmasaba.app",
|
||||||
buildNumber: "7",
|
buildNumber: "10",
|
||||||
infoPlist: {
|
infoPlist: {
|
||||||
ITSAppUsesNonExemptEncryption: false,
|
ITSAppUsesNonExemptEncryption: false,
|
||||||
CFBundleDisplayName: "Desa+"
|
CFBundleDisplayName: "Desa+"
|
||||||
@@ -23,7 +23,7 @@ export default {
|
|||||||
},
|
},
|
||||||
android: {
|
android: {
|
||||||
package: "mobiledarmasaba.app",
|
package: "mobiledarmasaba.app",
|
||||||
versionCode: 15,
|
versionCode: 21,
|
||||||
adaptiveIcon: {
|
adaptiveIcon: {
|
||||||
foregroundImage: "./assets/images/logo-icon-small.png",
|
foregroundImage: "./assets/images/logo-icon-small.png",
|
||||||
backgroundColor: "#ffffff"
|
backgroundColor: "#ffffff"
|
||||||
@@ -32,9 +32,7 @@ export default {
|
|||||||
permissions: [
|
permissions: [
|
||||||
"READ_EXTERNAL_STORAGE",
|
"READ_EXTERNAL_STORAGE",
|
||||||
"WRITE_EXTERNAL_STORAGE",
|
"WRITE_EXTERNAL_STORAGE",
|
||||||
"READ_MEDIA_IMAGES", // Android 13+
|
"READ_MEDIA_AUDIO"
|
||||||
"READ_MEDIA_VIDEO", // Android 13+
|
|
||||||
"READ_MEDIA_AUDIO" // Android 13+
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
web: {
|
web: {
|
||||||
@@ -56,6 +54,7 @@ export default {
|
|||||||
"expo-font",
|
"expo-font",
|
||||||
"expo-image-picker",
|
"expo-image-picker",
|
||||||
"expo-web-browser",
|
"expo-web-browser",
|
||||||
|
"./plugins/withRemoveMediaPermissions",
|
||||||
[
|
[
|
||||||
"@react-native-firebase/app",
|
"@react-native-firebase/app",
|
||||||
{
|
{
|
||||||
@@ -79,6 +78,14 @@ export default {
|
|||||||
URL_FIREBASE_DB: process.env.URL_FIREBASE_DB,
|
URL_FIREBASE_DB: process.env.URL_FIREBASE_DB,
|
||||||
PASS_ENC: process.env.PASS_ENC,
|
PASS_ENC: process.env.PASS_ENC,
|
||||||
WA_SERVER_TOKEN: process.env.WA_SERVER_TOKEN,
|
WA_SERVER_TOKEN: process.env.WA_SERVER_TOKEN,
|
||||||
|
FIREBASE_API_KEY: process.env.FIREBASE_API_KEY,
|
||||||
|
FIREBASE_AUTH_DOMAIN: process.env.FIREBASE_AUTH_DOMAIN,
|
||||||
|
FIREBASE_PROJECT_ID: process.env.FIREBASE_PROJECT_ID,
|
||||||
|
FIREBASE_STORAGE_BUCKET: process.env.FIREBASE_STORAGE_BUCKET,
|
||||||
|
FIREBASE_MESSAGING_SENDER_ID: process.env.FIREBASE_MESSAGING_SENDER_ID,
|
||||||
|
FIREBASE_APP_ID: process.env.FIREBASE_APP_ID,
|
||||||
|
URL_MONITORING: process.env.URL_MONITORING,
|
||||||
|
KEY_API_MONITORING: process.env.KEY_API_MONITORING,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import HeaderRightAnnouncementList from "@/components/announcement/headerAnnouncementList";
|
import HeaderRightAnnouncementList from "@/components/announcement/headerAnnouncementList";
|
||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
|
import Styles from "@/constants/Styles";
|
||||||
import HeaderDiscussionGeneral from "@/components/discussion_general/headerDiscussionGeneral";
|
import HeaderDiscussionGeneral from "@/components/discussion_general/headerDiscussionGeneral";
|
||||||
import HeaderRightDivisionList from "@/components/division/headerDivisionList";
|
import HeaderRightDivisionList from "@/components/division/headerDivisionList";
|
||||||
import HeaderRightGroupList from "@/components/group/headerGroupList";
|
import HeaderRightGroupList from "@/components/group/headerGroupList";
|
||||||
@@ -8,28 +9,106 @@ import HeaderRightPositionList from "@/components/position/headerRightPositionLi
|
|||||||
import HeaderRightProjectList from "@/components/project/headerProjectList";
|
import HeaderRightProjectList from "@/components/project/headerProjectList";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import ToastCustom from "@/components/toastCustom";
|
import ToastCustom from "@/components/toastCustom";
|
||||||
import { apiReadOneNotification } from "@/lib/api";
|
import ModalUpdateMaintenance from "@/components/ModalUpdateMaintenance";
|
||||||
|
import { apiGetVersion, apiReadOneNotification } from "@/lib/api";
|
||||||
import { pushToPage } from "@/lib/pushToPage";
|
import { pushToPage } from "@/lib/pushToPage";
|
||||||
import store from "@/lib/store";
|
import store from "@/lib/store";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
|
import Constants from "expo-constants";
|
||||||
import { getApp } from "@react-native-firebase/app";
|
import { getApp } from "@react-native-firebase/app";
|
||||||
import { getMessaging, onMessage } from "@react-native-firebase/messaging";
|
import { getMessaging, onMessage } from "@react-native-firebase/messaging";
|
||||||
import { Redirect, router, Stack, usePathname } from "expo-router";
|
import { Redirect, router, Stack, usePathname } from "expo-router";
|
||||||
import { StatusBar } from 'expo-status-bar';
|
import { StatusBar } from 'expo-status-bar';
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Easing, Notifier } from 'react-native-notifier';
|
import { Easing, Notifier, NotifierComponents } from 'react-native-notifier';
|
||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
|
||||||
export default function RootLayout() {
|
export default function RootLayout() {
|
||||||
const { token, decryptToken, isLoading } = useAuthSession()
|
const { token, decryptToken, isLoading } = useAuthSession()
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
const { colors } = useTheme()
|
||||||
|
const [modalUpdateMaintenance, setModalUpdateMaintenance] = useState(false)
|
||||||
|
const [modalType, setModalType] = useState<'update' | 'maintenance'>('update')
|
||||||
|
const [isForceUpdate, setIsForceUpdate] = useState(false)
|
||||||
|
const [updateMessage, setUpdateMessage] = useState('')
|
||||||
|
|
||||||
|
const currentVersion = Constants.expoConfig?.version ?? '0.0.0'
|
||||||
|
|
||||||
|
const compareVersions = (v1: string, v2: string) => {
|
||||||
|
const parts1 = v1.split('.').map(Number);
|
||||||
|
const parts2 = v2.split('.').map(Number);
|
||||||
|
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
||||||
|
const p1 = parts1[i] || 0;
|
||||||
|
const p2 = parts2[i] || 0;
|
||||||
|
if (p1 < p2) return -1;
|
||||||
|
if (p1 > p2) return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const checkVersion = async () => {
|
||||||
|
try {
|
||||||
|
const response = await apiGetVersion();
|
||||||
|
if (response.success && response.data) {
|
||||||
|
const maintenance = response.data.find((item: any) => item.id === 'mobile_maintenance')?.value === 'true';
|
||||||
|
const latestVersion = response.data.find((item: any) => item.id === 'mobile_latest_version')?.value || '0.0.0';
|
||||||
|
const minVersion = response.data.find((item: any) => item.id === 'mobile_minimum_version')?.value || '0.0.0';
|
||||||
|
const message = response.data.find((item: any) => item.id === 'mobile_message_update')?.value || '';
|
||||||
|
|
||||||
|
if (maintenance) {
|
||||||
|
setModalType('maintenance');
|
||||||
|
setModalUpdateMaintenance(true);
|
||||||
|
setIsForceUpdate(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compareVersions(currentVersion, minVersion) === -1) {
|
||||||
|
setModalType('update');
|
||||||
|
setIsForceUpdate(true);
|
||||||
|
setUpdateMessage(message);
|
||||||
|
setModalUpdateMaintenance(true);
|
||||||
|
} else if (compareVersions(currentVersion, latestVersion) === -1) {
|
||||||
|
// Check if this soft update version was already dismissed
|
||||||
|
const dismissedVersion = await AsyncStorage.getItem('dismissed_update_version');
|
||||||
|
if (dismissedVersion !== latestVersion) {
|
||||||
|
setModalType('update');
|
||||||
|
setIsForceUpdate(false);
|
||||||
|
setUpdateMessage(message);
|
||||||
|
setModalUpdateMaintenance(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to check version:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
checkVersion();
|
||||||
|
}, [currentVersion]);
|
||||||
|
|
||||||
|
const handleDismissUpdate = async () => {
|
||||||
|
if (!isForceUpdate) {
|
||||||
|
try {
|
||||||
|
const response = await apiGetVersion();
|
||||||
|
const latestVersion = response.data.find((item: any) => item.id === 'mobile_latest_version')?.value;
|
||||||
|
if (latestVersion) {
|
||||||
|
await AsyncStorage.setItem('dismissed_update_version', latestVersion);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
setModalUpdateMaintenance(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleReadNotification(id: string, category: string, idContent: string, title: string) {
|
async function handleReadNotification(id: string, category: string, idContent: string, title: string) {
|
||||||
try {
|
try {
|
||||||
if (title != "Komentar Baru") {
|
if (title !== "Komentar Baru") {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiReadOneNotification({ user: hasil, id: id })
|
await apiReadOneNotification({ user: hasil, id: id })
|
||||||
}
|
}
|
||||||
pushToPage(category, idContent)
|
pushToPage(category, idContent)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -65,12 +144,34 @@ export default function RootLayout() {
|
|||||||
} else if (pathname !== `/${category}/${content}`) {
|
} else if (pathname !== `/${category}/${content}`) {
|
||||||
Notifier.showNotification({
|
Notifier.showNotification({
|
||||||
title: title,
|
title: title,
|
||||||
description: remoteMessage.notification?.body,
|
description: String(remoteMessage.notification?.body),
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
animationDuration: 300,
|
animationDuration: 300,
|
||||||
showEasing: Easing.ease,
|
showEasing: Easing.ease,
|
||||||
onPress: () => handleReadNotification(String(id), String(category), String(content), String(title)),
|
onPress: () => handleReadNotification(String(id), String(category), String(content), String(title)),
|
||||||
hideOnPress: true,
|
hideOnPress: true,
|
||||||
|
Component: NotifierComponents.Notification,
|
||||||
|
componentProps: {
|
||||||
|
containerStyle: [
|
||||||
|
Styles.shadowBox,
|
||||||
|
{
|
||||||
|
backgroundColor: colors.modalBackground,
|
||||||
|
borderRadius: 5,
|
||||||
|
marginHorizontal: 15,
|
||||||
|
marginTop: 10,
|
||||||
|
padding: 15,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
titleStyle: {
|
||||||
|
color: colors.text,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
fontSize: 16,
|
||||||
|
},
|
||||||
|
descriptionStyle: {
|
||||||
|
color: colors.dimmed,
|
||||||
|
fontSize: 14,
|
||||||
|
},
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,18 +194,15 @@ export default function RootLayout() {
|
|||||||
<Stack screenOptions={{
|
<Stack screenOptions={{
|
||||||
headerShown: true,
|
headerShown: true,
|
||||||
animation: "slide_from_right",
|
animation: "slide_from_right",
|
||||||
|
|
||||||
// ⬇️ PENTING BANGET
|
|
||||||
animationTypeForReplace: "pop",
|
animationTypeForReplace: "pop",
|
||||||
fullScreenGestureEnabled: true,
|
fullScreenGestureEnabled: true,
|
||||||
gestureEnabled: true,
|
gestureEnabled: true,
|
||||||
|
contentStyle: { backgroundColor: colors.header },
|
||||||
}} >
|
}} >
|
||||||
<Stack.Screen name="home" options={{ title: 'Home' }} />
|
<Stack.Screen name="home" options={{ title: 'Home' }} />
|
||||||
<Stack.Screen name="feature" options={{ title: 'Fitur' }} />
|
<Stack.Screen name="feature" options={{ title: 'Fitur' }} />
|
||||||
<Stack.Screen name="search" options={{ title: 'Pencarian' }} />
|
<Stack.Screen name="search" options={{ title: 'Pencarian' }} />
|
||||||
<Stack.Screen name="notification" options={{
|
<Stack.Screen name="notification" options={{
|
||||||
title: 'Notifikasi',
|
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Notifikasi',
|
headerTitle: 'Notifikasi',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
header: () => (
|
header: () => (
|
||||||
@@ -112,11 +210,19 @@ export default function RootLayout() {
|
|||||||
)
|
)
|
||||||
}} />
|
}} />
|
||||||
<Stack.Screen name="profile" options={{ title: 'Profile' }} />
|
<Stack.Screen name="profile" options={{ title: 'Profile' }} />
|
||||||
|
<Stack.Screen name="setting/index" options={{
|
||||||
|
title: 'Pengaturan',
|
||||||
|
headerTitleAlign: 'center',
|
||||||
|
header: () => (
|
||||||
|
<AppHeader title="Pengaturan"
|
||||||
|
showBack={true}
|
||||||
|
onPressLeft={() => router.back()}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}} />
|
||||||
<Stack.Screen name="member/index" options={{
|
<Stack.Screen name="member/index" options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
title: 'Anggota',
|
title: 'Anggota',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
// headerRight: () => <HeaderMemberList />
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader title="Anggota"
|
<AppHeader title="Anggota"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
@@ -126,10 +232,8 @@ export default function RootLayout() {
|
|||||||
)
|
)
|
||||||
}} />
|
}} />
|
||||||
<Stack.Screen name="discussion/index" options={{
|
<Stack.Screen name="discussion/index" options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
title: 'Diskusi Umum',
|
title: 'Diskusi Umum',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
// headerRight: () => <HeaderDiscussionGeneral />
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Diskusi Umum"
|
title="Diskusi Umum"
|
||||||
@@ -140,10 +244,8 @@ export default function RootLayout() {
|
|||||||
)
|
)
|
||||||
}} />
|
}} />
|
||||||
<Stack.Screen name="project/index" options={{
|
<Stack.Screen name="project/index" options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
title: 'Kegiatan',
|
title: 'Kegiatan',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
// headerRight: () => <HeaderRightProjectList />
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader title="Kegiatan"
|
<AppHeader title="Kegiatan"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
@@ -153,10 +255,8 @@ export default function RootLayout() {
|
|||||||
)
|
)
|
||||||
}} />
|
}} />
|
||||||
<Stack.Screen name="division/index" options={{
|
<Stack.Screen name="division/index" options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
title: 'Divisi',
|
title: 'Divisi',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
// headerRight: () => <HeaderRightDivisionList />
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader title="Divisi"
|
<AppHeader title="Divisi"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
@@ -167,10 +267,8 @@ export default function RootLayout() {
|
|||||||
}} />
|
}} />
|
||||||
<Stack.Screen name="division/[id]/(fitur-division)" options={{ headerShown: false }} />
|
<Stack.Screen name="division/[id]/(fitur-division)" options={{ headerShown: false }} />
|
||||||
<Stack.Screen name="group/index" options={{
|
<Stack.Screen name="group/index" options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Lembaga Desa',
|
headerTitle: 'Lembaga Desa',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
// headerRight: () => <HeaderRightGroupList />
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader title="Lembaga Desa"
|
<AppHeader title="Lembaga Desa"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
@@ -180,10 +278,8 @@ export default function RootLayout() {
|
|||||||
)
|
)
|
||||||
}} />
|
}} />
|
||||||
<Stack.Screen name="position/index" options={{
|
<Stack.Screen name="position/index" options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Jabatan',
|
headerTitle: 'Jabatan',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
// headerRight: () => <HeaderRightPositionList />
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader title="Jabatan"
|
<AppHeader title="Jabatan"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
@@ -194,10 +290,8 @@ export default function RootLayout() {
|
|||||||
}} />
|
}} />
|
||||||
<Stack.Screen name="announcement/index"
|
<Stack.Screen name="announcement/index"
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Pengumuman',
|
headerTitle: 'Pengumuman',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
// headerRight: () => <HeaderRightAnnouncementList />
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader title="Pengumuman"
|
<AppHeader title="Pengumuman"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
@@ -210,6 +304,13 @@ export default function RootLayout() {
|
|||||||
</Stack>
|
</Stack>
|
||||||
<StatusBar style={'light'} translucent={false} backgroundColor="black" />
|
<StatusBar style={'light'} translucent={false} backgroundColor="black" />
|
||||||
<ToastCustom />
|
<ToastCustom />
|
||||||
|
<ModalUpdateMaintenance
|
||||||
|
visible={modalUpdateMaintenance}
|
||||||
|
type={modalType}
|
||||||
|
isForceUpdate={isForceUpdate}
|
||||||
|
customDescription={updateMessage}
|
||||||
|
onDismiss={handleDismissUpdate}
|
||||||
|
/>
|
||||||
</Provider>
|
</Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import HeaderRightAnnouncementDetail from "@/components/announcement/headerAnnouncementDetail";
|
import HeaderRightAnnouncementDetail from "@/components/announcement/headerAnnouncementDetail";
|
||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import Skeleton from "@/components/skeleton";
|
import Skeleton from "@/components/skeleton";
|
||||||
import Text from '@/components/Text';
|
import Text from '@/components/Text';
|
||||||
|
import ErrorView from "@/components/ErrorView";
|
||||||
import { ConstEnv } from "@/constants/ConstEnv";
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
import { isImageFile } from "@/constants/FileExtensions";
|
import { isImageFile } from "@/constants/FileExtensions";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetAnnouncementOne } from "@/lib/api";
|
import { apiGetAnnouncementOne } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { Entypo, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
||||||
import * as FileSystem from 'expo-file-system';
|
import * as FileSystem from 'expo-file-system';
|
||||||
import { startActivityAsync } from 'expo-intent-launcher';
|
import { startActivityAsync } from 'expo-intent-launcher';
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
@@ -21,7 +22,6 @@ import RenderHTML from 'react-native-render-html';
|
|||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
// Define TypeScript interfaces for better type safety
|
|
||||||
interface AnnouncementData {
|
interface AnnouncementData {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -51,32 +51,40 @@ interface ApiResponse {
|
|||||||
export default function DetailAnnouncement() {
|
export default function DetailAnnouncement() {
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const [data, setData] = useState<AnnouncementData>({ id: '', title: '', desc: '' })
|
const [data, setData] = useState<AnnouncementData>({ id: '', title: '', desc: '' })
|
||||||
const [dataMember, setDataMember] = useState<Record<string, MemberData[]>>({})
|
const [dataMember, setDataMember] = useState<Record<string, MemberData[]>>({})
|
||||||
const [dataFile, setDataFile] = useState<FileData[]>([])
|
const [dataFile, setDataFile] = useState<FileData[]>([])
|
||||||
const update = useSelector((state: any) => state.announcementUpdate)
|
const update = useSelector((state: any) => state.announcementUpdate)
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const contentWidth = Dimensions.get('window').width
|
const contentWidth = Dimensions.get('window').width - 62
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const arrSkeleton = Array.from({ length: 2 }, (_, index) => index)
|
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
const [loadingOpen, setLoadingOpen] = useState(false)
|
const [loadingOpen, setLoadingOpen] = useState(false)
|
||||||
const [preview, setPreview] = useState(false)
|
const [preview, setPreview] = useState(false)
|
||||||
const [chooseFile, setChooseFile] = useState<FileData>()
|
const [chooseFile, setChooseFile] = useState<FileData>()
|
||||||
|
const [isError, setIsError] = useState(false)
|
||||||
|
|
||||||
/**
|
const themed = {
|
||||||
* Opens the image preview modal for the selected image file
|
background: { backgroundColor: colors.background },
|
||||||
* @param item The file data object containing image information
|
card: { backgroundColor: colors.card, borderColor: colors.icon + '18' },
|
||||||
*/
|
iconBox: { backgroundColor: colors.icon + '18' },
|
||||||
|
sectionLabel: { color: colors.dimmed },
|
||||||
|
titleText: { color: colors.text },
|
||||||
|
fileChipBorder: { borderColor: colors.icon + '30' },
|
||||||
|
fileChipPressed: { backgroundColor: colors.icon + '10' },
|
||||||
|
groupSeparator: { borderTopColor: colors.icon + '18' },
|
||||||
|
divisionIconBg: { backgroundColor: colors.icon + '15' },
|
||||||
|
}
|
||||||
|
|
||||||
function handleChooseFile(item: FileData) {
|
function handleChooseFile(item: FileData) {
|
||||||
setChooseFile(item)
|
setChooseFile(item)
|
||||||
setPreview(true)
|
setPreview(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function handleLoad(loading: boolean) {
|
async function handleLoad(loading: boolean) {
|
||||||
try {
|
try {
|
||||||
|
setIsError(false)
|
||||||
setLoading(loading)
|
setLoading(loading)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response: ApiResponse = await apiGetAnnouncementOne({ id: id, user: hasil })
|
const response: ApiResponse = await apiGetAnnouncementOne({ id: id, user: hasil })
|
||||||
@@ -85,42 +93,29 @@ export default function DetailAnnouncement() {
|
|||||||
setDataMember(response.member)
|
setDataMember(response.member)
|
||||||
setDataFile(response.file)
|
setDataFile(response.file)
|
||||||
} else {
|
} else {
|
||||||
|
setIsError(true)
|
||||||
Toast.show({ type: 'small', text1: response.message })
|
Toast.show({ type: 'small', text1: response.message })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Gagal mengambil data' })
|
setIsError(true)
|
||||||
|
const message = error?.response?.data?.message || "Gagal mengambil data"
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { handleLoad(false) }, [update])
|
||||||
handleLoad(false)
|
useEffect(() => { handleLoad(true) }, [])
|
||||||
}, [update])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(true)
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a string contains HTML tags
|
|
||||||
* @param text The text to check for HTML tags
|
|
||||||
* @returns True if the text contains HTML tags, false otherwise
|
|
||||||
*/
|
|
||||||
function hasHtmlTags(text: string) {
|
function hasHtmlTags(text: string) {
|
||||||
const htmlRegex = /<[a-z][\s\S]*>/i;
|
return /<[a-z][\s\S]*>/i.test(text);
|
||||||
return htmlRegex.test(text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles pull-to-refresh functionality
|
|
||||||
* Reloads the announcement data without showing loading indicators
|
|
||||||
*/
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleLoad(false)
|
handleLoad(false)
|
||||||
// Simulate network request delay for better UX
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
@@ -132,173 +127,173 @@ export default function DetailAnnouncement() {
|
|||||||
const fileName = item.name + '.' + item.extension;
|
const fileName = item.name + '.' + item.extension;
|
||||||
const localPath = `${FileSystem.documentDirectory}/${fileName}`;
|
const localPath = `${FileSystem.documentDirectory}/${fileName}`;
|
||||||
const mimeType = mime.lookup(fileName);
|
const mimeType = mime.lookup(fileName);
|
||||||
|
|
||||||
// Download the file
|
|
||||||
const downloadResult = await FileSystem.downloadAsync(remoteUrl, localPath);
|
const downloadResult = await FileSystem.downloadAsync(remoteUrl, localPath);
|
||||||
|
|
||||||
if (downloadResult.status !== 200) {
|
if (downloadResult.status !== 200) {
|
||||||
throw new Error(`Download failed with status ${downloadResult.status}`);
|
throw new Error(`Download failed with status ${downloadResult.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentURL = await FileSystem.getContentUriAsync(downloadResult.uri);
|
const contentURL = await FileSystem.getContentUriAsync(downloadResult.uri);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (Platform.OS === 'android') {
|
if (Platform.OS === 'android') {
|
||||||
await startActivityAsync(
|
await startActivityAsync('android.intent.action.VIEW', {
|
||||||
'android.intent.action.VIEW',
|
data: contentURL,
|
||||||
{
|
flags: 1,
|
||||||
data: contentURL,
|
type: mimeType as string,
|
||||||
flags: 1,
|
});
|
||||||
type: mimeType as string,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else if (Platform.OS === 'ios') {
|
} else if (Platform.OS === 'ios') {
|
||||||
await Sharing.shareAsync(localPath);
|
await Sharing.shareAsync(localPath);
|
||||||
}
|
}
|
||||||
} catch (openError) {
|
} catch {
|
||||||
console.error('Error opening file:', openError);
|
Toast.show({ type: 'error', text1: 'Tidak ada aplikasi yang dapat membuka file ini' });
|
||||||
Toast.show({
|
|
||||||
type: 'error',
|
|
||||||
text1: 'Tidak ada aplikasi yang dapat membuka file ini'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch {
|
||||||
console.error('Error downloading or opening file:', error);
|
Toast.show({ type: 'error', text1: 'Gagal membuka file', text2: 'Silakan coba lagi nanti' });
|
||||||
Toast.show({
|
|
||||||
type: 'error',
|
|
||||||
text1: 'Gagal membuka file',
|
|
||||||
text2: 'Silakan coba lagi nanti'
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingOpen(false);
|
setLoadingOpen(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, themed.background]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Pengumuman',
|
|
||||||
headerTitleAlign: 'center',
|
|
||||||
// headerRight: () => entityUser.role != 'user' && entityUser.role != 'coadmin' ? <HeaderRightAnnouncementDetail id={id} /> : <></>,
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader title="Pengumuman"
|
<AppHeader
|
||||||
|
title="Pengumuman"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={entityUser.role != 'user' && entityUser.role != 'coadmin' ? <HeaderRightAnnouncementDetail id={id} /> : <></>}
|
right={entityUser.role != 'user' && entityUser.role != 'coadmin'
|
||||||
|
? <HeaderRightAnnouncementDetail id={id} />
|
||||||
|
: <></>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
style={[Styles.h100]}
|
style={[Styles.flex1, themed.background]}
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} tintColor={colors.icon} />
|
||||||
refreshing={refreshing}
|
|
||||||
onRefresh={() => handleRefresh()}
|
|
||||||
/>
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15, Styles.mb50]}>
|
{isError && !loading ? (
|
||||||
<View style={[Styles.wrapPaper]}>
|
<View style={Styles.mv50}>
|
||||||
{
|
<ErrorView />
|
||||||
loading ?
|
</View>
|
||||||
<View>
|
) : (
|
||||||
<View style={[Styles.rowOnly]}>
|
<View style={Styles.announcementDetailContainer}>
|
||||||
<Skeleton width={30} height={30} borderRadius={10} />
|
|
||||||
<View style={[{ flex: 1 }, Styles.ph05]}>
|
{/* Title + Description */}
|
||||||
<Skeleton width={100} widthType="percent" height={30} borderRadius={10} />
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.sectionCard, Styles.announcementDetailCard, themed.card]}>
|
||||||
</View>
|
{loading ? (
|
||||||
|
<View style={Styles.announcementDetailSkeletonGap}>
|
||||||
|
<View style={[Styles.rowItemsCenter, Styles.announcementDetailSkeletonIconRow]}>
|
||||||
|
<Skeleton width={38} height={38} borderRadius={10} />
|
||||||
|
<Skeleton width={60} widthType="percent" height={16} borderRadius={6} />
|
||||||
</View>
|
</View>
|
||||||
<Skeleton width={100} widthType="percent" height={10} borderRadius={10} />
|
<Skeleton width={100} widthType="percent" height={10} borderRadius={6} />
|
||||||
<Skeleton width={100} widthType="percent" height={10} borderRadius={10} />
|
<Skeleton width={100} widthType="percent" height={10} borderRadius={6} />
|
||||||
<Skeleton width={100} widthType="percent" height={10} borderRadius={10} />
|
<Skeleton width={80} widthType="percent" height={10} borderRadius={6} />
|
||||||
</View>
|
</View>
|
||||||
:
|
) : (
|
||||||
<>
|
<>
|
||||||
<View style={[Styles.rowItemsCenter, { alignItems: 'flex-start' }]}>
|
<View style={[Styles.rowItemsCenter, Styles.announcementDetailTitleRow]}>
|
||||||
<MaterialIcons name="campaign" size={25} color="black" style={[Styles.mr05]} />
|
<View style={[Styles.sectionIconBox, Styles.announcementDetailIconBox, themed.iconBox]}>
|
||||||
<Text style={[Styles.textDefaultSemiBold, Styles.w90, Styles.mt02]}>{data?.title}</Text>
|
<MaterialIcons name="campaign" size={22} color={colors.icon} />
|
||||||
</View>
|
</View>
|
||||||
<View style={[Styles.mt10]}>
|
<Text style={[Styles.textDefaultSemiBold, Styles.announcementDetailTitleText, themed.titleText]} numberOfLines={2}>
|
||||||
{
|
{data.title}
|
||||||
hasHtmlTags(data?.desc) ?
|
</Text>
|
||||||
<RenderHTML
|
|
||||||
contentWidth={contentWidth}
|
|
||||||
source={{ html: data?.desc }}
|
|
||||||
baseStyle={{ color: 'black' }}
|
|
||||||
/>
|
|
||||||
:
|
|
||||||
<Text>{data?.desc}</Text>
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
|
{hasHtmlTags(data.desc)
|
||||||
|
? <RenderHTML
|
||||||
|
contentWidth={contentWidth}
|
||||||
|
source={{ html: data.desc }}
|
||||||
|
baseStyle={{ color: colors.text }}
|
||||||
|
/>
|
||||||
|
: <Text style={Styles.textDefault}>{data.desc}</Text>
|
||||||
|
}
|
||||||
</>
|
</>
|
||||||
}
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
{/* Files */}
|
||||||
{
|
{dataFile.length > 0 && (
|
||||||
dataFile.length > 0 && (
|
<View>
|
||||||
<View style={[Styles.wrapPaper, Styles.mt10]}>
|
<View style={[Styles.rowItemsCenter, Styles.announcementDetailSectionLabelRow]}>
|
||||||
<View style={[Styles.mb05]}>
|
<MaterialCommunityIcons name="paperclip" size={14} color={colors.dimmed} />
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
|
<Text style={[Styles.textInformation, themed.sectionLabel]}>
|
||||||
|
Lampiran ({dataFile.length})
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.sectionCard, Styles.announcementDetailCard, Styles.announcementDetailFileCardPadding, themed.card]}>
|
||||||
|
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
|
||||||
|
<View style={[Styles.rowItemsCenter, Styles.announcementDetailFileChipList]}>
|
||||||
|
{dataFile.map((item, index) => (
|
||||||
|
<Pressable
|
||||||
|
key={`${item.id}-${index}`}
|
||||||
|
onPress={() => isImageFile(item.extension) ? handleChooseFile(item) : openFile(item)}
|
||||||
|
style={({ pressed }) => [Styles.announcementDetailFileChip, themed.fileChipBorder,
|
||||||
|
pressed ? themed.fileChipPressed : themed.background]}
|
||||||
|
>
|
||||||
|
<MaterialCommunityIcons
|
||||||
|
name={isImageFile(item.extension) ? "file-image-outline" : "file-document-outline"}
|
||||||
|
size={16}
|
||||||
|
color={colors.icon}
|
||||||
|
/>
|
||||||
|
<Text style={[Styles.textInformation, Styles.announcementDetailFileChipText, themed.titleText]} numberOfLines={1}>
|
||||||
|
{item.name}.{item.extension}
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
</ScrollView>
|
||||||
</View>
|
</View>
|
||||||
{dataFile.map((item, index) => (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={`${item.id}-${index}`}
|
|
||||||
borderType="bottom"
|
|
||||||
icon={<MaterialCommunityIcons
|
|
||||||
name={isImageFile(item.extension) ? "file-image-outline" : "file-document-outline"}
|
|
||||||
size={25}
|
|
||||||
color="black"
|
|
||||||
/>}
|
|
||||||
title={item.name + '.' + item.extension}
|
|
||||||
titleWeight="normal"
|
|
||||||
onPress={() => {
|
|
||||||
isImageFile(item.extension) ?
|
|
||||||
handleChooseFile(item)
|
|
||||||
: openFile(item)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</View>
|
</View>
|
||||||
)
|
)}
|
||||||
}
|
|
||||||
<View style={[Styles.wrapPaper, Styles.mt10]}>
|
|
||||||
{
|
|
||||||
loading ?
|
|
||||||
arrSkeleton.map((item, index) => {
|
|
||||||
return (
|
|
||||||
<View key={index}>
|
|
||||||
<Skeleton width={30} widthType="percent" height={10} borderRadius={10} />
|
|
||||||
<Skeleton width={100} widthType="percent" height={10} borderRadius={10} />
|
|
||||||
<Skeleton width={100} widthType="percent" height={10} borderRadius={10} />
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
:
|
|
||||||
Object.keys(dataMember).map((v: any, i: any) => {
|
|
||||||
return (
|
|
||||||
<View key={i} style={[Styles.mb05]}>
|
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>{dataMember[v]?.[0].group}</Text>
|
|
||||||
{
|
|
||||||
dataMember[v].map((item: any, x: any) => {
|
|
||||||
return (
|
|
||||||
<View key={x} style={[Styles.rowItemsCenter, Styles.w90]}>
|
|
||||||
<Entypo name="dot-single" size={24} color="black" />
|
|
||||||
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{item.division}</Text>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
{/* Recipients */}
|
||||||
|
<View>
|
||||||
|
<View style={[Styles.rowItemsCenter, Styles.announcementDetailSectionLabelRow]}>
|
||||||
|
<MaterialIcons name="groups" size={14} color={colors.dimmed} />
|
||||||
|
<Text style={[Styles.textInformation, themed.sectionLabel]}>
|
||||||
|
Ditujukan Kepada
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.sectionCard, Styles.announcementDetailCard, themed.card]}>
|
||||||
|
{loading ? (
|
||||||
|
<View style={Styles.announcementDetailRecipientGap}>
|
||||||
|
<Skeleton width={40} widthType="percent" height={10} borderRadius={6} />
|
||||||
|
<Skeleton width={100} widthType="percent" height={10} borderRadius={6} />
|
||||||
|
<Skeleton width={60} widthType="percent" height={10} borderRadius={6} />
|
||||||
|
<Skeleton width={100} widthType="percent" height={10} borderRadius={6} />
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
Object.keys(dataMember).map((v, i) => (
|
||||||
|
<View key={i} style={i > 0 ? [Styles.announcementDetailGroupSeparator, themed.groupSeparator] : undefined}>
|
||||||
|
<Text style={[Styles.textInformation, Styles.announcementDetailGroupLabel, themed.sectionLabel]}>
|
||||||
|
{dataMember[v]?.[0].group}
|
||||||
|
</Text>
|
||||||
|
<View>
|
||||||
|
{dataMember[v].map((item, x) => (
|
||||||
|
<View key={x} style={[Styles.rowItemsCenter, Styles.announcementDetailDivisionRow]}>
|
||||||
|
<View style={[Styles.announcementDetailDivisionIconCircle, themed.divisionIconBg]}>
|
||||||
|
<MaterialIcons name="group" size={14} color={colors.icon} />
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.textDefault, Styles.flex1, themed.titleText]}>
|
||||||
|
{item.division}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
)
|
))
|
||||||
})
|
)}
|
||||||
}
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<ImageViewing
|
<ImageViewing
|
||||||
@@ -307,38 +302,26 @@ export default function DetailAnnouncement() {
|
|||||||
visible={preview}
|
visible={preview}
|
||||||
onRequestClose={() => setPreview(false)}
|
onRequestClose={() => setPreview(false)}
|
||||||
doubleTapToZoomEnabled
|
doubleTapToZoomEnabled
|
||||||
HeaderComponent={({ imageIndex }) => (
|
HeaderComponent={() => (
|
||||||
<View style={[Styles.headerModalViewImg]}>
|
<View style={Styles.headerModalViewImg}>
|
||||||
{/* CLOSE */}
|
<Pressable onPress={() => setPreview(false)} accessibilityRole="button">
|
||||||
<Pressable
|
<Text style={[Styles.textWhite, Styles.font26]}>✕</Text>
|
||||||
onPress={() => setPreview(false)}
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityLabel="Close image viewer"
|
|
||||||
>
|
|
||||||
<Text style={{ color: 'white', fontSize: 26 }}>✕</Text>
|
|
||||||
</Pressable>
|
</Pressable>
|
||||||
|
|
||||||
{/* MENU */}
|
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() => chooseFile && openFile(chooseFile)}
|
onPress={() => chooseFile && openFile(chooseFile)}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel="Download or share image"
|
|
||||||
disabled={loadingOpen}
|
disabled={loadingOpen}
|
||||||
>
|
>
|
||||||
<Text style={{ color: loadingOpen ? 'gray' : 'white', fontSize: 22 }}>⋯</Text>
|
<Text style={[Styles.font26, { color: loadingOpen ? 'gray' : 'white' }]}>⋯</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
FooterComponent={({ imageIndex }) => (
|
FooterComponent={() => (
|
||||||
<View style={{
|
<View style={[Styles.pb20, Styles.ph16, Styles.alignCenter]}>
|
||||||
paddingBottom: 20,
|
<Text style={[Styles.textWhite, Styles.font16]}>{chooseFile?.name}.{chooseFile?.extension}</Text>
|
||||||
paddingHorizontal: 16,
|
|
||||||
alignItems: 'center',
|
|
||||||
}}>
|
|
||||||
<Text style={{ color: 'white', fontSize: 16 }}>{chooseFile?.name}.{chooseFile?.extension}</Text>
|
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import ButtonSelect from "@/components/buttonSelect";
|
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import LoadingOverlay from "@/components/loadingOverlay";
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
import ModalSelectMultiple from "@/components/modalSelectMultiple";
|
import ModalSelectMultiple from "@/components/modalSelectMultiple";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -12,242 +10,265 @@ import Styles from "@/constants/Styles";
|
|||||||
import { setUpdateAnnouncement } from "@/lib/announcementUpdate";
|
import { setUpdateAnnouncement } from "@/lib/announcementUpdate";
|
||||||
import { apiCreateAnnouncement } from "@/lib/api";
|
import { apiCreateAnnouncement } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { Entypo, Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
||||||
import * as DocumentPicker from "expo-document-picker";
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, StyleSheet, View } from "react-native";
|
import { Pressable, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
|
function getFileIcon(ext: string): keyof typeof MaterialCommunityIcons.glyphMap {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return 'image-outline'
|
||||||
|
if (ext === 'pdf') return 'file-pdf-box'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return 'video-outline'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return 'file-word-outline'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return 'file-excel-outline'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return 'zip-box-outline'
|
||||||
|
return 'file-outline'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileColor(ext: string): string {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return '#339AF0'
|
||||||
|
if (ext === 'pdf') return '#F03E3E'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return '#AE3EC9'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return '#1C7ED6'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return '#2F9E44'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return '#E8590C'
|
||||||
|
return '#868E96'
|
||||||
|
}
|
||||||
|
|
||||||
export default function CreateAnnouncement() {
|
export default function CreateAnnouncement() {
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.announcementUpdate)
|
const update = useSelector((state: any) => state.announcementUpdate)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const [disableBtn, setDisableBtn] = useState(true);
|
const [disableBtn, setDisableBtn] = useState(true);
|
||||||
const [modalDivisi, setModalDivisi] = useState(false);
|
const [modalDivisi, setModalDivisi] = useState(false);
|
||||||
const [divisionMember, setDivisionMember] = useState<any>([])
|
const [divisionMember, setDivisionMember] = useState<any[]>([])
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [fileForm, setFileForm] = useState<any[]>([])
|
const [fileForm, setFileForm] = useState<any[]>([])
|
||||||
const [isModalFile, setModalFile] = useState(false)
|
const [isModalFile, setModalFile] = useState(false)
|
||||||
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
||||||
const [dataForm, setDataForm] = useState({
|
const [dataForm, setDataForm] = useState({ title: "", desc: "" });
|
||||||
title: "",
|
const [error, setError] = useState({ title: false, desc: false });
|
||||||
desc: "",
|
|
||||||
});
|
const totalDivisi = divisionMember.reduce((acc: number, g: any) => acc + g.Division.length, 0)
|
||||||
const [error, setError] = useState({
|
|
||||||
title: false,
|
|
||||||
desc: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
function validationForm(cat: string, val: any) {
|
function validationForm(cat: string, val: any) {
|
||||||
if (cat == "title") {
|
if (cat === "title") {
|
||||||
setDataForm({ ...dataForm, title: val });
|
setDataForm({ ...dataForm, title: val });
|
||||||
if (val == "" || val == "null") {
|
setError({ ...error, title: val === "" || val === "null" });
|
||||||
setError({ ...error, title: true });
|
} else if (cat === "desc") {
|
||||||
} else {
|
|
||||||
setError({ ...error, title: false });
|
|
||||||
}
|
|
||||||
} else if (cat == "desc") {
|
|
||||||
setDataForm({ ...dataForm, desc: val });
|
setDataForm({ ...dataForm, desc: val });
|
||||||
if (val == "" || val == "null") {
|
setError({ ...error, desc: val === "" || val === "null" });
|
||||||
setError({ ...error, desc: true });
|
|
||||||
} else {
|
|
||||||
setError({ ...error, desc: false });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForm() {
|
function checkForm() {
|
||||||
if (
|
const hasError = Object.values(error).some(v => v)
|
||||||
Object.values(error).some((v) => v == true) ||
|
const hasEmpty = Object.values(dataForm).some(v => v === "")
|
||||||
Object.values(dataForm).some((v) => v == "")
|
setDisableBtn(hasError || hasEmpty);
|
||||||
) {
|
|
||||||
setDisableBtn(true);
|
|
||||||
} else {
|
|
||||||
setDisableBtn(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { checkForm() }, [error, dataForm]);
|
||||||
checkForm();
|
|
||||||
}, [error, dataForm]);
|
|
||||||
|
|
||||||
async function handleCreate() {
|
async function handleCreate() {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const fd = new FormData()
|
const fd = new FormData()
|
||||||
|
|
||||||
for (let i = 0; i < fileForm.length; i++) {
|
for (let i = 0; i < fileForm.length; i++) {
|
||||||
fd.append(`file${i}`, {
|
fd.append(`file${i}`, { uri: fileForm[i].uri, type: 'application/octet-stream', name: fileForm[i].name } as any);
|
||||||
uri: fileForm[i].uri,
|
|
||||||
type: 'application/octet-stream',
|
|
||||||
name: fileForm[i].name,
|
|
||||||
} as any);
|
|
||||||
}
|
}
|
||||||
|
fd.append("data", JSON.stringify({ user: hasil, groups: divisionMember, ...dataForm }))
|
||||||
fd.append("data", JSON.stringify(
|
|
||||||
{ user: hasil, groups: divisionMember, ...dataForm }
|
|
||||||
))
|
|
||||||
|
|
||||||
const response = await apiCreateAnnouncement(fd)
|
const response = await apiCreateAnnouncement(fd)
|
||||||
|
|
||||||
// const response = await apiCreateAnnouncement({
|
|
||||||
// data: { ...dataForm, user: hasil, groups: divisionMember },
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
dispatch(setUpdateAnnouncement(!update))
|
dispatch(setUpdateAnnouncement(!update))
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data' })
|
||||||
router.back();
|
router.back();
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: 'small', text1: response.message })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Tidak dapat terhubung ke server" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pickDocumentAsync = async () => {
|
const pickDocumentAsync = async () => {
|
||||||
let result = await DocumentPicker.getDocumentAsync({
|
const result = await DocumentPicker.getDocumentAsync({ type: ["*/*"], multiple: true });
|
||||||
type: ["*/*"],
|
|
||||||
multiple: true
|
|
||||||
});
|
|
||||||
if (!result.canceled) {
|
if (!result.canceled) {
|
||||||
for (let i = 0; i < result.assets?.length; i++) {
|
let skipped = 0
|
||||||
if (result.assets[i].uri) {
|
for (const asset of result.assets) {
|
||||||
setFileForm((prev) => [...prev, result.assets[i]])
|
if (!asset.uri) continue
|
||||||
|
if (fileForm.some(f => f.name === asset.name)) {
|
||||||
|
skipped++
|
||||||
|
} else {
|
||||||
|
setFileForm(prev => [...prev, asset])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (skipped > 0) Toast.show({ type: 'small', text1: 'Beberapa file sudah ditambahkan' })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function deleteFile(index: number) {
|
function deleteFile(index: number) {
|
||||||
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
setFileForm(fileForm.filter((_, i) => i !== index))
|
||||||
setModalFile(false)
|
setModalFile(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
|
||||||
// <ButtonBackHeader
|
|
||||||
// onPress={() => {
|
|
||||||
// router.back();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
headerTitle: "Tambah Pengumuman",
|
|
||||||
headerTitleAlign: "center",
|
|
||||||
// headerRight: () => (
|
|
||||||
// <ButtonSaveHeader
|
|
||||||
// disable={disableBtn || divisionMember.length == 0 || loading ? true : false}
|
|
||||||
// category="create"
|
|
||||||
// onPress={() => {
|
|
||||||
// divisionMember.length == 0
|
|
||||||
// ? Toast.show({ type: 'small', text1: "Anda belum memilih divisi", })
|
|
||||||
// : handleCreate();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Tambah Pengumuman"
|
title="Tambah Pengumuman"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={
|
right={
|
||||||
<ButtonSaveHeader
|
<ButtonSaveHeader
|
||||||
disable={disableBtn || divisionMember.length == 0 || loading ? true : false}
|
disable={disableBtn || divisionMember.length === 0 || loading}
|
||||||
category="create"
|
category="create"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
divisionMember.length == 0
|
divisionMember.length === 0
|
||||||
? Toast.show({ type: 'small', text1: "Anda belum memilih divisi", })
|
? Toast.show({ type: 'small', text1: "Anda belum memilih divisi" })
|
||||||
: handleCreate();
|
: handleCreate()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<LoadingOverlay visible={loading} />
|
{loading && <LoadingCenter />}
|
||||||
<ScrollView
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, { backgroundColor: colors.background }]}>
|
||||||
showsVerticalScrollIndicator={false}
|
<View style={Styles.p15}>
|
||||||
style={[Styles.h100]}
|
|
||||||
>
|
|
||||||
<View style={[Styles.p15]}>
|
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul"
|
label="Judul"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul Pengumuman"
|
placeholder="Judul Pengumuman"
|
||||||
required
|
required
|
||||||
error={error.title}
|
error={error.title}
|
||||||
|
bg={colors.card}
|
||||||
errorText="Judul harus diisi"
|
errorText="Judul harus diisi"
|
||||||
onChange={(val) => validationForm("title", val)}
|
onChange={(val) => validationForm("title", val)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Pengumuman"
|
label="Pengumuman"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Deskripsi Pengumuman"
|
placeholder="Deskripsi Pengumuman"
|
||||||
required
|
required
|
||||||
error={error.desc}
|
error={error.desc}
|
||||||
|
bg={colors.card}
|
||||||
errorText="Pengumuman harus diisi"
|
errorText="Pengumuman harus diisi"
|
||||||
onChange={(val) => validationForm("desc", val)}
|
onChange={(val) => validationForm("desc", val)}
|
||||||
multiline
|
multiline
|
||||||
/>
|
/>
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
|
||||||
{
|
|
||||||
fileForm.length > 0
|
|
||||||
&&
|
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10]}>
|
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
|
|
||||||
{
|
|
||||||
fileForm.map((item, index) => (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={index}
|
|
||||||
borderType={fileForm.length > 1 ? "bottom" : "none"}
|
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
|
||||||
title={item.name}
|
|
||||||
titleWeight="normal"
|
|
||||||
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
|
|
||||||
<ButtonSelect
|
{/* File */}
|
||||||
value="Pilih divisi penerima pengumuman"
|
<View style={[Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
onPress={() => {
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
setModalDivisi(true)
|
<Pressable
|
||||||
}}
|
onPress={pickDocumentAsync}
|
||||||
/>
|
style={[Styles.sectionActionRow, { marginBottom: fileForm.length > 0 ? 12 : 0 }]}
|
||||||
|
>
|
||||||
{
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '15' }]}>
|
||||||
divisionMember.length > 0
|
<MaterialCommunityIcons name="paperclip" size={18} color={colors.dimmed} />
|
||||||
&&
|
</View>
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10]}>
|
<View style={Styles.flex1}>
|
||||||
{
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>File</Text>
|
||||||
divisionMember.map((item: { name: any; Division: any }, index: any) => {
|
{fileForm.length === 0 && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Opsional — ketuk untuk upload</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{fileForm.length > 0 && (
|
||||||
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{fileForm.length} file</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{fileForm.length > 0 && (
|
||||||
|
<View style={Styles.fileGrid}>
|
||||||
|
{fileForm.map((item, index) => {
|
||||||
|
const ext = item.name.split('.').pop()?.toLowerCase() ?? ''
|
||||||
|
const baseName = item.name.includes('.') ? item.name.split('.').slice(0, -1).join('.') : item.name
|
||||||
|
const iconName = getFileIcon(ext)
|
||||||
|
const iconColor = getFileColor(ext)
|
||||||
return (
|
return (
|
||||||
<View key={index}>
|
<Pressable
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>{item.name}</Text>
|
key={index}
|
||||||
{
|
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
|
||||||
item.Division.map((division: any, i: any) => (
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
<View key={i} style={[Styles.rowItemsCenter, Styles.w90]}>
|
>
|
||||||
<Entypo name="dot-single" size={24} color="black" />
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{division.name}</Text>
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
</View>
|
</View>
|
||||||
))
|
<View style={Styles.flex1}>
|
||||||
}
|
<Text style={Styles.textDefault} numberOfLines={1}>{baseName}</Text>
|
||||||
</View>
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
)
|
)
|
||||||
})
|
})}
|
||||||
}
|
</View>
|
||||||
</View>
|
)}
|
||||||
}
|
</View>
|
||||||
|
|
||||||
|
{/* Divisi Penerima */}
|
||||||
|
<View style={[Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => setModalDivisi(true)}
|
||||||
|
style={[Styles.sectionActionRow, { marginBottom: divisionMember.length > 0 ? 12 : 0 }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<MaterialIcons name="groups" size={18} color={colors.tabActive} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Divisi Penerima</Text>
|
||||||
|
{divisionMember.length === 0 && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Belum ada divisi dipilih</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{divisionMember.length > 0 && (
|
||||||
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.tabActive }]}>{totalDivisi} divisi</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{divisionMember.length > 0 && (
|
||||||
|
<View style={{ gap: 10 }}>
|
||||||
|
{divisionMember.map((item: any, index: number) => (
|
||||||
|
<View key={index}>
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed, marginBottom: 4 }]}>
|
||||||
|
{item.name}
|
||||||
|
</Text>
|
||||||
|
<View style={{ gap: 6 }}>
|
||||||
|
{item.Division.map((division: any, i: number) => (
|
||||||
|
<View key={i} style={[Styles.listItemCard, { borderColor: colors.icon + '18' }]}>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.tabActive + '18', width: 28, height: 28, borderRadius: 8 }]}>
|
||||||
|
<MaterialIcons name="group" size={14} color={colors.tabActive} />
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.textDefault, Styles.flex1, { color: colors.text }]} numberOfLines={1}>
|
||||||
|
{division.name}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
@@ -266,25 +287,12 @@ export default function CreateAnnouncement() {
|
|||||||
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile) }}
|
onPress={() => deleteFile(indexDelFile)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
padding: 20,
|
|
||||||
},
|
|
||||||
textArea: {
|
|
||||||
height: 100, // Or use flex-based sizing
|
|
||||||
borderColor: 'gray',
|
|
||||||
borderWidth: 1,
|
|
||||||
padding: 10,
|
|
||||||
textAlignVertical: 'top', // Important for Android to align text at the top
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import ButtonSelect from "@/components/buttonSelect";
|
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import LoadingOverlay from "@/components/loadingOverlay";
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
import ModalSelectMultiple from "@/components/modalSelectMultiple";
|
import ModalSelectMultiple from "@/components/modalSelectMultiple";
|
||||||
import Text from '@/components/Text';
|
import Text from '@/components/Text';
|
||||||
@@ -12,22 +10,39 @@ import Styles from "@/constants/Styles";
|
|||||||
import { setUpdateAnnouncement } from "@/lib/announcementUpdate";
|
import { setUpdateAnnouncement } from "@/lib/announcementUpdate";
|
||||||
import { apiEditAnnouncement, apiGetAnnouncementOne } from "@/lib/api";
|
import { apiEditAnnouncement, apiGetAnnouncementOne } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { Entypo, Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
||||||
import * as DocumentPicker from "expo-document-picker";
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { Pressable, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
|
function getFileIcon(ext: string): keyof typeof MaterialCommunityIcons.glyphMap {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return 'image-outline'
|
||||||
|
if (ext === 'pdf') return 'file-pdf-box'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return 'video-outline'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return 'file-word-outline'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return 'file-excel-outline'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return 'zip-box-outline'
|
||||||
|
return 'file-outline'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileColor(ext: string): string {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return '#339AF0'
|
||||||
|
if (ext === 'pdf') return '#F03E3E'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return '#AE3EC9'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return '#1C7ED6'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return '#2F9E44'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return '#E8590C'
|
||||||
|
return '#868E96'
|
||||||
|
}
|
||||||
|
|
||||||
type GroupDivision = {
|
type GroupDivision = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
Division: {
|
Division: { id: string; name: string }[];
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
}[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function EditAnnouncement() {
|
export default function EditAnnouncement() {
|
||||||
@@ -35,45 +50,32 @@ export default function EditAnnouncement() {
|
|||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.announcementUpdate)
|
const update = useSelector((state: any) => state.announcementUpdate)
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
|
const { colors } = useTheme();
|
||||||
const [modalDivisi, setModalDivisi] = useState(false);
|
const [modalDivisi, setModalDivisi] = useState(false);
|
||||||
const [disableBtn, setDisableBtn] = useState(true);
|
const [disableBtn, setDisableBtn] = useState(true);
|
||||||
const [dataMember, setDataMember] = useState<any>([]);
|
const [dataMember, setDataMember] = useState<GroupDivision[]>([]);
|
||||||
const [fileForm, setFileForm] = useState<any[]>([])
|
const [fileForm, setFileForm] = useState<any[]>([])
|
||||||
const [dataFile, setDataFile] = useState<{ id: string; idStorage: string; name: string; extension: string; delete?: boolean }[]>([])
|
const [dataFile, setDataFile] = useState<{ id: string; idStorage: string; name: string; extension: string; delete?: boolean }[]>([])
|
||||||
const [indexDelFile, setIndexDelFile] = useState<{ id: string | number; cat: "newFile" | "oldFile" }>({ id: "", cat: "newFile" })
|
const [indexDelFile, setIndexDelFile] = useState<{ id: string | number; cat: "newFile" | "oldFile" }>({ id: "", cat: "newFile" })
|
||||||
const [isModalFile, setModalFile] = useState(false)
|
const [isModalFile, setModalFile] = useState(false)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [dataForm, setDataForm] = useState({
|
const [dataForm, setDataForm] = useState({ title: "", desc: "" });
|
||||||
title: "",
|
const [error, setError] = useState({ title: false, desc: false });
|
||||||
desc: "",
|
|
||||||
});
|
const visibleOldFiles = dataFile.filter(v => !v.delete)
|
||||||
const [error, setError] = useState({
|
const totalFiles = fileForm.length + visibleOldFiles.length
|
||||||
title: false,
|
const totalDivisi = dataMember.reduce((acc: number, g: any) => acc + g.Division.length, 0)
|
||||||
desc: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
async function handleLoad() {
|
async function handleLoad() {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiGetAnnouncementOne({ id: id, user: hasil });
|
const response = await apiGetAnnouncementOne({ id: id, user: hasil });
|
||||||
setDataForm(response.data);
|
setDataForm(response.data);
|
||||||
|
const arrNew: GroupDivision[] = Object.keys(response.member).map((v) => ({
|
||||||
const arrNew: GroupDivision[] = []
|
id: response.member[v][0].idGroup,
|
||||||
const coba = Object.keys(response.member).map((v: any, i: any) => {
|
name: v,
|
||||||
const newObject = {
|
Division: response.member[v].map((m: any) => ({ id: m.idDivision, name: m.division }))
|
||||||
"id": response.member[v][0].idGroup,
|
}))
|
||||||
"name": v,
|
|
||||||
"Division": response.member[v]
|
|
||||||
}
|
|
||||||
|
|
||||||
response.member[v].map((v: any, i: any) => {
|
|
||||||
newObject["Division"][i] = {
|
|
||||||
"id": v.idDivision,
|
|
||||||
"name": v.division
|
|
||||||
}
|
|
||||||
})
|
|
||||||
arrNew.push(newObject)
|
|
||||||
})
|
|
||||||
setDataMember(arrNew);
|
setDataMember(arrNew);
|
||||||
setDataFile(response.file);
|
setDataFile(response.file);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -81,42 +83,25 @@ export default function EditAnnouncement() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { handleLoad() }, []);
|
||||||
handleLoad();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
function validationForm(cat: string, val: any) {
|
function validationForm(cat: string, val: any) {
|
||||||
if (cat == "title") {
|
if (cat === "title") {
|
||||||
setDataForm({ ...dataForm, title: val });
|
setDataForm({ ...dataForm, title: val });
|
||||||
if (val == "" || val == "null") {
|
setError({ ...error, title: val === "" || val === "null" });
|
||||||
setError({ ...error, title: true });
|
} else if (cat === "desc") {
|
||||||
} else {
|
|
||||||
setError({ ...error, title: false });
|
|
||||||
}
|
|
||||||
} else if (cat == "desc") {
|
|
||||||
setDataForm({ ...dataForm, desc: val });
|
setDataForm({ ...dataForm, desc: val });
|
||||||
if (val == "" || val == "null") {
|
setError({ ...error, desc: val === "" || val === "null" });
|
||||||
setError({ ...error, desc: true });
|
|
||||||
} else {
|
|
||||||
setError({ ...error, desc: false });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForm() {
|
function checkForm() {
|
||||||
if (
|
const hasError = Object.values(error).some(v => v)
|
||||||
Object.values(error).some((v) => v == true) ||
|
const hasEmpty = Object.values(dataForm).some(v => v === "")
|
||||||
Object.values(dataForm).some((v) => v == "")
|
setDisableBtn(hasError || hasEmpty);
|
||||||
) {
|
|
||||||
setDisableBtn(true);
|
|
||||||
} else {
|
|
||||||
setDisableBtn(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { checkForm() }, [error, dataForm]);
|
||||||
checkForm();
|
|
||||||
}, [error, dataForm]);
|
|
||||||
|
|
||||||
async function handleEdit() {
|
async function handleEdit() {
|
||||||
try {
|
try {
|
||||||
@@ -124,85 +109,56 @@ export default function EditAnnouncement() {
|
|||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const fd = new FormData()
|
const fd = new FormData()
|
||||||
for (let i = 0; i < fileForm.length; i++) {
|
for (let i = 0; i < fileForm.length; i++) {
|
||||||
fd.append(`file${i}`, {
|
fd.append(`file${i}`, { uri: fileForm[i].uri, type: 'application/octet-stream', name: fileForm[i].name } as any);
|
||||||
uri: fileForm[i].uri,
|
|
||||||
type: 'application/octet-stream',
|
|
||||||
name: fileForm[i].name,
|
|
||||||
} as any);
|
|
||||||
}
|
}
|
||||||
|
fd.append("data", JSON.stringify({ ...dataForm, user: hasil, groups: dataMember, oldFile: dataFile }))
|
||||||
fd.append("data", JSON.stringify(
|
|
||||||
{
|
|
||||||
...dataForm, user: hasil, groups: dataMember, oldFile: dataFile
|
|
||||||
}
|
|
||||||
))
|
|
||||||
|
|
||||||
const response = await apiEditAnnouncement(fd, id);
|
const response = await apiEditAnnouncement(fd, id);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
dispatch(setUpdateAnnouncement(!update))
|
dispatch(setUpdateAnnouncement(!update))
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil mengubah data', })
|
Toast.show({ type: 'small', text1: 'Berhasil mengubah data' })
|
||||||
router.back();
|
router.back();
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: 'small', text1: 'Gagal mengubah data' })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal mengubah data" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pickDocumentAsync = async () => {
|
const pickDocumentAsync = async () => {
|
||||||
let result = await DocumentPicker.getDocumentAsync({
|
const result = await DocumentPicker.getDocumentAsync({ type: ["*/*"], multiple: true });
|
||||||
type: ["*/*"],
|
|
||||||
multiple: true
|
|
||||||
});
|
|
||||||
if (!result.canceled) {
|
if (!result.canceled) {
|
||||||
for (let i = 0; i < result.assets?.length; i++) {
|
let skipped = 0
|
||||||
if (result.assets[i].uri) {
|
for (const asset of result.assets) {
|
||||||
setFileForm((prev) => [...prev, result.assets[i]])
|
if (!asset.uri) continue
|
||||||
|
const isDup = fileForm.some(f => f.name === asset.name) ||
|
||||||
|
visibleOldFiles.some(f => `${f.name}.${f.extension}` === asset.name)
|
||||||
|
if (isDup) {
|
||||||
|
skipped++
|
||||||
|
} else {
|
||||||
|
setFileForm(prev => [...prev, asset])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (skipped > 0) Toast.show({ type: 'small', text1: 'Beberapa file sudah ditambahkan' })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function deleteFile(index: number | string, cat: "newFile" | "oldFile" | null) {
|
function deleteFile(index: number | string, cat: "newFile" | "oldFile" | null) {
|
||||||
if (cat == "newFile") {
|
if (cat === "newFile") {
|
||||||
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
setFileForm(fileForm.filter((_, i) => i !== index))
|
||||||
} else {
|
} else {
|
||||||
setDataFile(prev =>
|
setDataFile(prev => prev.map(item => item.id === index ? { ...item, delete: true } : item))
|
||||||
prev.map(item =>
|
|
||||||
item.id === index
|
|
||||||
? { ...item, delete: true }
|
|
||||||
: item
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
setModalFile(false)
|
setModalFile(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
|
||||||
// <ButtonBackHeader
|
|
||||||
// onPress={() => {
|
|
||||||
// router.back();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
headerTitle: "Edit Pengumuman",
|
|
||||||
headerTitleAlign: "center",
|
|
||||||
// headerRight: () => (
|
|
||||||
// <ButtonSaveHeader
|
|
||||||
// disable={disableBtn || loading ? true : false}
|
|
||||||
// category="update"
|
|
||||||
// onPress={() => {
|
|
||||||
// dataMember.length == 0
|
|
||||||
// ? Toast.show({ type: 'small', text1: "Anda belum memilih divisi", })
|
|
||||||
// : handleEdit();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Edit Pengumuman"
|
title="Edit Pengumuman"
|
||||||
@@ -210,12 +166,12 @@ export default function EditAnnouncement() {
|
|||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={
|
right={
|
||||||
<ButtonSaveHeader
|
<ButtonSaveHeader
|
||||||
disable={disableBtn || loading ? true : false}
|
disable={disableBtn || dataMember.length === 0 || loading}
|
||||||
category="update"
|
category="update"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
dataMember.length == 0
|
dataMember.length === 0
|
||||||
? Toast.show({ type: 'small', text1: "Anda belum memilih divisi", })
|
? Toast.show({ type: 'small', text1: "Anda belum memilih divisi" })
|
||||||
: handleEdit();
|
: handleEdit()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -223,94 +179,153 @@ export default function EditAnnouncement() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<LoadingOverlay visible={loading} />
|
{loading && <LoadingCenter />}
|
||||||
<ScrollView
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, { backgroundColor: colors.background }]}>
|
||||||
showsVerticalScrollIndicator={false}
|
<View style={Styles.p15}>
|
||||||
style={[Styles.h100]}
|
|
||||||
>
|
|
||||||
<View style={[Styles.p15]}>
|
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul"
|
label="Judul"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul Pengumuman"
|
placeholder="Judul Pengumuman"
|
||||||
required
|
required
|
||||||
error={error.title}
|
error={error.title}
|
||||||
|
bg={colors.card}
|
||||||
errorText="Judul harus diisi"
|
errorText="Judul harus diisi"
|
||||||
onChange={(val) => validationForm("title", val)}
|
onChange={(val) => validationForm("title", val)}
|
||||||
value={dataForm.title}
|
value={dataForm.title}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Pengumuman"
|
label="Pengumuman"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Deskripsi Pengumuman"
|
placeholder="Deskripsi Pengumuman"
|
||||||
required
|
required
|
||||||
error={error.desc}
|
error={error.desc}
|
||||||
|
bg={colors.card}
|
||||||
errorText="Pengumuman harus diisi"
|
errorText="Pengumuman harus diisi"
|
||||||
onChange={(val) => validationForm("desc", val)}
|
onChange={(val) => validationForm("desc", val)}
|
||||||
value={dataForm.desc}
|
value={dataForm.desc}
|
||||||
multiline
|
multiline
|
||||||
/>
|
/>
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
|
||||||
{
|
{/* File */}
|
||||||
(fileForm.length > 0 || dataFile.filter((val) => !val.delete).length > 0)
|
<View style={[Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
&&
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10]}>
|
<Pressable
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
|
onPress={pickDocumentAsync}
|
||||||
{
|
style={[Styles.sectionActionRow, { marginBottom: totalFiles > 0 ? 12 : 0 }]}
|
||||||
dataFile.filter((val) => !val.delete).map((item, index) => (
|
>
|
||||||
<BorderBottomItem
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '15' }]}>
|
||||||
key={index}
|
<MaterialCommunityIcons name="paperclip" size={18} color={colors.dimmed} />
|
||||||
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
|
</View>
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
<View style={Styles.flex1}>
|
||||||
title={item.name + '.' + item.extension}
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>File</Text>
|
||||||
titleWeight="normal"
|
{totalFiles === 0 && (
|
||||||
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Opsional — ketuk untuk upload</Text>
|
||||||
/>
|
)}
|
||||||
))
|
</View>
|
||||||
}
|
{totalFiles > 0 && (
|
||||||
{
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
fileForm.map((item, index) => (
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{totalFiles} file</Text>
|
||||||
<BorderBottomItem
|
</View>
|
||||||
key={index}
|
)}
|
||||||
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
</Pressable>
|
||||||
title={item.name}
|
{totalFiles > 0 && (
|
||||||
titleWeight="normal"
|
<View style={Styles.fileGrid}>
|
||||||
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
|
{visibleOldFiles.map((item, index) => {
|
||||||
/>
|
const ext = item.extension.toLowerCase()
|
||||||
))
|
const iconName = getFileIcon(ext)
|
||||||
}
|
const iconColor = getFileColor(ext)
|
||||||
</View>
|
|
||||||
}
|
|
||||||
<ButtonSelect
|
|
||||||
value="Pilih divisi penerima pengumuman"
|
|
||||||
onPress={() => {
|
|
||||||
setModalDivisi(true)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{
|
|
||||||
dataMember.length > 0
|
|
||||||
&&
|
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10]}>
|
|
||||||
{
|
|
||||||
dataMember.map((item: { name: any; Division: any }, index: any) => {
|
|
||||||
return (
|
return (
|
||||||
<View key={index}>
|
<Pressable
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>{item.name}</Text>
|
key={`old-${index}`}
|
||||||
{
|
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
|
||||||
item.Division.map((division: any, i: any) => (
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
<View key={i} style={[Styles.rowItemsCenter, Styles.w90]}>
|
>
|
||||||
<Entypo name="dot-single" size={24} color="black" />
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{division.name}</Text>
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
</View>
|
</View>
|
||||||
))
|
<View style={Styles.flex1}>
|
||||||
}
|
<Text style={Styles.textDefault} numberOfLines={1}>{item.name}</Text>
|
||||||
</View>
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
)
|
)
|
||||||
})
|
})}
|
||||||
}
|
{fileForm.map((item, index) => {
|
||||||
</View>
|
const ext = item.name.split('.').pop()?.toLowerCase() ?? ''
|
||||||
}
|
const baseName = item.name.includes('.') ? item.name.split('.').slice(0, -1).join('.') : item.name
|
||||||
|
const iconName = getFileIcon(ext)
|
||||||
|
const iconColor = getFileColor(ext)
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={`new-${index}`}
|
||||||
|
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
|
||||||
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={Styles.textDefault} numberOfLines={1}>{baseName}</Text>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* Divisi Penerima */}
|
||||||
|
<View style={[Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => setModalDivisi(true)}
|
||||||
|
style={[Styles.sectionActionRow, { marginBottom: dataMember.length > 0 ? 12 : 0 }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<MaterialIcons name="groups" size={18} color={colors.tabActive} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Divisi Penerima</Text>
|
||||||
|
{dataMember.length === 0 && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Belum ada divisi dipilih</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{dataMember.length > 0 && (
|
||||||
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.tabActive }]}>{totalDivisi} divisi</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{dataMember.length > 0 && (
|
||||||
|
<View style={{ gap: 10 }}>
|
||||||
|
{dataMember.map((item, index) => (
|
||||||
|
<View key={index}>
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed, marginBottom: 4 }]}>
|
||||||
|
{item.name}
|
||||||
|
</Text>
|
||||||
|
<View style={{ gap: 6 }}>
|
||||||
|
{item.Division.map((division, i) => (
|
||||||
|
<View key={i} style={[Styles.listItemCard, { borderColor: colors.icon + '18' }]}>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.tabActive + '18', width: 28, height: 28, borderRadius: 8 }]}>
|
||||||
|
<MaterialIcons name="group" size={14} color={colors.tabActive} />
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.textDefault, Styles.flex1, { color: colors.text }]} numberOfLines={1}>
|
||||||
|
{division.name}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
@@ -330,9 +345,9 @@ export default function EditAnnouncement() {
|
|||||||
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile.id, indexDelFile.cat) }}
|
onPress={() => deleteFile(indexDelFile.id, indexDelFile.cat)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|||||||
@@ -1,139 +1,155 @@
|
|||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
import InputSearch from "@/components/inputSearch";
|
import InputSearch from "@/components/inputSearch";
|
||||||
import SkeletonContent from "@/components/skeletonContent";
|
import Skeleton from "@/components/skeleton";
|
||||||
import Text from '@/components/Text';
|
import Text from '@/components/Text';
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetAnnouncement } from "@/lib/api";
|
import { apiGetAnnouncement } from "@/lib/api";
|
||||||
|
import { GUIDE_ANNOUNCEMENT } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { MaterialIcons } from "@expo/vector-icons";
|
import { MaterialIcons } from "@expo/vector-icons";
|
||||||
|
import { useInfiniteQuery } from "@tanstack/react-query";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { RefreshControl, View, VirtualizedList } from "react-native";
|
import { Pressable, RefreshControl, View, VirtualizedList } from "react-native";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: string,
|
id: string
|
||||||
title: string,
|
title: string
|
||||||
desc: string,
|
desc: string
|
||||||
createdAt: string
|
createdAt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default function Announcement() {
|
export default function Announcement() {
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const [data, setData] = useState<Props[]>([])
|
const { colors } = useTheme();
|
||||||
const [search, setSearch] = useState('')
|
const [search, setSearch] = useState('')
|
||||||
const update = useSelector((state: any) => state.announcementUpdate)
|
const update = useSelector((state: any) => state.announcementUpdate)
|
||||||
const [loading, setLoading] = useState(true)
|
const isFirstRender = useRef(true)
|
||||||
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('announcement')
|
||||||
const [page, setPage] = useState(1)
|
const arrSkeleton = Array.from({ length: 5 }, (_, i) => i)
|
||||||
const [waiting, setWaiting] = useState(false)
|
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
|
||||||
|
|
||||||
async function handleLoad(loading: boolean, thisPage: number) {
|
const themed = {
|
||||||
try {
|
background: { backgroundColor: colors.background },
|
||||||
setWaiting(true)
|
card: { backgroundColor: colors.card, borderColor: colors.icon + '18' },
|
||||||
setLoading(loading)
|
iconBox: { backgroundColor: colors.icon + '18' },
|
||||||
setPage(thisPage)
|
title: { color: colors.text },
|
||||||
const hasil = await decryptToken(String(token?.current))
|
desc: { color: colors.dimmed },
|
||||||
const response = await apiGetAnnouncement({ user: hasil, search: search, page: thisPage })
|
date: { color: colors.dimmed },
|
||||||
if (thisPage == 1) {
|
cardPressed: { backgroundColor: colors.icon + '08' },
|
||||||
setData(response.data)
|
|
||||||
} else if (thisPage > 1 && response.data.length > 0) {
|
|
||||||
setData([...data, ...response.data])
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
setWaiting(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
const {
|
||||||
handleLoad(false, 1)
|
data,
|
||||||
}, [update])
|
fetchNextPage,
|
||||||
|
hasNextPage,
|
||||||
useEffect(() => {
|
isFetchingNextPage,
|
||||||
handleLoad(true, 1)
|
isLoading,
|
||||||
}, [search])
|
refetch,
|
||||||
|
isRefetching
|
||||||
const loadMoreData = () => {
|
} = useInfiniteQuery({
|
||||||
if (waiting) return
|
queryKey: ['announcements', search],
|
||||||
setTimeout(() => {
|
queryFn: async ({ pageParam = 1 }) => {
|
||||||
handleLoad(false, page + 1)
|
const hasil = await decryptToken(String(token?.current))
|
||||||
}, 1000);
|
const response = await apiGetAnnouncement({ user: hasil, search, page: pageParam })
|
||||||
};
|
return response.data
|
||||||
|
},
|
||||||
const handleRefresh = async () => {
|
initialPageParam: 1,
|
||||||
setRefreshing(true)
|
getNextPageParam: (lastPage, allPages) => {
|
||||||
handleLoad(false, 1)
|
return lastPage.length > 0 ? allPages.length + 1 : undefined
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
},
|
||||||
setRefreshing(false)
|
|
||||||
};
|
|
||||||
|
|
||||||
const getItem = (_data: unknown, index: number): Props => ({
|
|
||||||
id: data[index].id,
|
|
||||||
title: data[index].title,
|
|
||||||
desc: data[index].desc,
|
|
||||||
createdAt: data[index].createdAt,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
useEffect(() => {
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
if (isFirstRender.current) { isFirstRender.current = false; return }
|
||||||
<View>
|
refetch()
|
||||||
<InputSearch onChange={setSearch} />
|
}, [update])
|
||||||
|
|
||||||
|
const flattenedData = useMemo(() => data?.pages.flat() || [], [data])
|
||||||
|
|
||||||
|
const getItem = (_data: unknown, index: number): Props => ({
|
||||||
|
id: flattenedData[index].id,
|
||||||
|
title: flattenedData[index].title,
|
||||||
|
desc: flattenedData[index].desc,
|
||||||
|
createdAt: flattenedData[index].createdAt,
|
||||||
|
})
|
||||||
|
|
||||||
|
const renderSkeleton = () => (
|
||||||
|
<View style={Styles.announcementListSkeletonCard}>
|
||||||
|
<View style={[Styles.rowSpaceBetween, Styles.rowItemsCenter, Styles.announcementListSkeletonHeader]}>
|
||||||
|
<View style={[Styles.rowItemsCenter, Styles.announcementListSkeletonTitleRow]}>
|
||||||
|
<Skeleton width={28} height={28} borderRadius={8} />
|
||||||
|
<Skeleton width={50} widthType="percent" height={12} borderRadius={6} />
|
||||||
|
</View>
|
||||||
|
<Skeleton width={15} widthType="percent" height={10} borderRadius={6} />
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ flex: 2 }, Styles.mt05]}>
|
<Skeleton width={100} widthType="percent" height={10} borderRadius={6} />
|
||||||
{
|
<Skeleton width={80} widthType="percent" height={10} borderRadius={6} />
|
||||||
loading ?
|
</View>
|
||||||
arrSkeleton.map((item, index) => {
|
)
|
||||||
return (
|
|
||||||
<SkeletonContent key={index} />
|
const renderItem = ({ item }: { item: Props }) => (
|
||||||
)
|
<Pressable
|
||||||
})
|
onPress={() => router.push(`/announcement/${item.id}`)}
|
||||||
:
|
style={({ pressed }) => [Styles.announcementListCard, themed.card, pressed && themed.cardPressed]}
|
||||||
data.length > 0
|
>
|
||||||
?
|
<View style={[Styles.rowSpaceBetween, Styles.rowItemsCenter, Styles.announcementListCardHeader]}>
|
||||||
<VirtualizedList
|
<View style={[Styles.rowItemsCenter, Styles.announcementListTitleRow]}>
|
||||||
data={data}
|
<View style={[Styles.announcementListIconBox, themed.iconBox]}>
|
||||||
getItemCount={() => data.length}
|
<MaterialIcons name="campaign" size={16} color={colors.icon} />
|
||||||
getItem={getItem}
|
</View>
|
||||||
renderItem={({ item, index }: { item: Props, index: number }) => {
|
<Text style={[Styles.textDefaultSemiBold, Styles.announcementListTitleText, themed.title]} numberOfLines={1}>
|
||||||
return (
|
{item.title}
|
||||||
<BorderBottomItem
|
</Text>
|
||||||
key={index}
|
</View>
|
||||||
onPress={() => { router.push(`/announcement/${item.id}`) }}
|
<Text style={[Styles.textInformation, Styles.announcementListDateText, themed.date]}>
|
||||||
borderType="bottom"
|
{item.createdAt}
|
||||||
icon={
|
</Text>
|
||||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
</View>
|
||||||
<MaterialIcons name="campaign" size={25} color={'#384288'} />
|
<Text style={[Styles.textMediumNormal, Styles.announcementListDescText, themed.title]} numberOfLines={2}>
|
||||||
</View>
|
{item.desc.replace(/<[^>]*>?/gm, '').replace(/\r?\n|\r/g, ' ')}
|
||||||
}
|
</Text>
|
||||||
title={item.title}
|
</Pressable>
|
||||||
desc={item.desc.replace(/<[^>]*>?/gm, '').replace(/\r?\n|\r/g, ' ')}
|
)
|
||||||
rightTopInfo={item.createdAt}
|
|
||||||
/>
|
return (
|
||||||
)
|
<View style={[Styles.flex1, Styles.announcementListContainer, themed.background]}>
|
||||||
}}
|
<GuideOverlay visible={guideVisible} steps={GUIDE_ANNOUNCEMENT} onDismiss={dismissGuide} />
|
||||||
keyExtractor={(item, index) => String(index)}
|
<InputSearch onChange={setSearch} />
|
||||||
onEndReached={loadMoreData}
|
<View style={[Styles.flex1, Styles.announcementListInner]}>
|
||||||
onEndReachedThreshold={0.5}
|
{isLoading && !flattenedData.length ? (
|
||||||
showsVerticalScrollIndicator={false}
|
arrSkeleton.map((_, i) => (
|
||||||
refreshControl={
|
<View key={i} style={[Styles.announcementListCard, themed.card]}>
|
||||||
<RefreshControl
|
{renderSkeleton()}
|
||||||
refreshing={refreshing}
|
</View>
|
||||||
onRefresh={handleRefresh}
|
))
|
||||||
/>
|
) : flattenedData.length > 0 ? (
|
||||||
}
|
<VirtualizedList
|
||||||
|
data={flattenedData}
|
||||||
|
getItemCount={() => flattenedData.length}
|
||||||
|
getItem={getItem}
|
||||||
|
renderItem={renderItem}
|
||||||
|
keyExtractor={(item, index) => String(item.id || index)}
|
||||||
|
onEndReached={() => { if (hasNextPage && !isFetchingNextPage) fetchNextPage() }}
|
||||||
|
onEndReachedThreshold={0.5}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
ItemSeparatorComponent={() => <View style={Styles.announcementListSeparator} />}
|
||||||
|
refreshControl={
|
||||||
|
<RefreshControl
|
||||||
|
refreshing={isRefetching && !isFetchingNextPage}
|
||||||
|
onRefresh={refetch}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
:
|
}
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada pengumuman</Text>
|
/>
|
||||||
}
|
) : (
|
||||||
|
<Text style={[Styles.textDefault, Styles.textCenter, Styles.mt30, themed.desc]}>
|
||||||
|
Tidak ada pengumuman
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import { ConstEnv } from "@/constants/ConstEnv";
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiEditBanner, apiGetBanner, apiGetBannerOne } from "@/lib/api";
|
import { apiEditBanner, apiGetBanner, apiGetBannerOne } from "@/lib/api";
|
||||||
import { setEntities } from "@/lib/bannerSlice";
|
import { setEntities } from "@/lib/bannerSlice";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Entypo } from "@expo/vector-icons";
|
import { Entypo } from "@expo/vector-icons";
|
||||||
import * as ImagePicker from "expo-image-picker";
|
import * as ImagePicker from "expo-image-picker";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
@@ -24,6 +26,7 @@ import { useDispatch } from "react-redux";
|
|||||||
export default function EditBanner() {
|
export default function EditBanner() {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { decryptToken, token } = useAuthSession();
|
const { decryptToken, token } = useAuthSession();
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const [selectedImage, setSelectedImage] = useState<
|
const [selectedImage, setSelectedImage] = useState<
|
||||||
string | undefined | { uri: string }
|
string | undefined | { uri: string }
|
||||||
@@ -103,16 +106,18 @@ export default function EditBanner() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: 'Gagal mengupdate data', })
|
Toast.show({ type: 'small', text1: 'Gagal mengupdate data', })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Gagal mengupdate data', })
|
const message = error?.response?.data?.message || "Gagal mengupdate data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -143,7 +148,8 @@ export default function EditBanner() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
|
{loading && <LoadingCenter />}
|
||||||
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<View style={[Styles.mb15]}>
|
<View style={[Styles.mb15]}>
|
||||||
{selectedImage != undefined ? (
|
{selectedImage != undefined ? (
|
||||||
@@ -154,7 +160,7 @@ export default function EditBanner() {
|
|||||||
? selectedImage
|
? selectedImage
|
||||||
: selectedImage.uri
|
: selectedImage.uri
|
||||||
}
|
}
|
||||||
style={{ resizeMode: "contain", width: "100%", height: 100 }}
|
style={[Styles.resizeContain, Styles.w100, { height: 100 }]}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
) : (
|
) : (
|
||||||
@@ -163,7 +169,7 @@ export default function EditBanner() {
|
|||||||
style={[Styles.wrapPaper, Styles.contentItemCenter]}
|
style={[Styles.wrapPaper, Styles.contentItemCenter]}
|
||||||
>
|
>
|
||||||
<View
|
<View
|
||||||
style={{ justifyContent: "center", alignItems: "center" }}
|
style={[Styles.contentItemCenter]}
|
||||||
>
|
>
|
||||||
<Entypo name="image" size={50} color={"#aeaeae"} />
|
<Entypo name="image" size={50} color={"#aeaeae"} />
|
||||||
<Text style={[Styles.textInformation, Styles.mt05]}>
|
<Text style={[Styles.textInformation, Styles.mt05]}>
|
||||||
@@ -179,7 +185,7 @@ export default function EditBanner() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul"
|
placeholder="Judul"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={title}
|
value={title}
|
||||||
error={error}
|
error={error}
|
||||||
onChange={onValidate}
|
onChange={onValidate}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiCreateBanner, apiGetBanner } from "@/lib/api";
|
import { apiCreateBanner, apiGetBanner } from "@/lib/api";
|
||||||
import { setEntities } from "@/lib/bannerSlice";
|
import { setEntities } from "@/lib/bannerSlice";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Entypo } from "@expo/vector-icons";
|
import { Entypo } from "@expo/vector-icons";
|
||||||
import * as ImagePicker from "expo-image-picker";
|
import * as ImagePicker from "expo-image-picker";
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
@@ -22,6 +24,7 @@ import { useDispatch } from "react-redux";
|
|||||||
|
|
||||||
export default function CreateBanner() {
|
export default function CreateBanner() {
|
||||||
const { decryptToken, token } = useAuthSession();
|
const { decryptToken, token } = useAuthSession();
|
||||||
|
const { colors } = useTheme();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [selectedImage, setSelectedImage] = useState<string | undefined>(
|
const [selectedImage, setSelectedImage] = useState<string | undefined>(
|
||||||
undefined
|
undefined
|
||||||
@@ -85,36 +88,22 @@ export default function CreateBanner() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: 'Gagal menambahkan data', })
|
Toast.show({ type: 'small', text1: 'Gagal menambahkan data', })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Gagal menambahkan data', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
|
||||||
// <ButtonBackHeader
|
|
||||||
// onPress={() => {
|
|
||||||
// router.back();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
headerTitle: "Tambah Banner",
|
headerTitle: "Tambah Banner",
|
||||||
headerTitleAlign: "center",
|
headerTitleAlign: "center",
|
||||||
// headerRight: () => (
|
|
||||||
// <ButtonSaveHeader
|
|
||||||
// disable={title == "" || selectedImage == undefined || error || loading ? true : false}
|
|
||||||
// category="create"
|
|
||||||
// onPress={() => {
|
|
||||||
// handleCreateEntity();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Fitur"
|
title="Fitur"
|
||||||
@@ -133,26 +122,27 @@ export default function CreateBanner() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
|
{loading && <LoadingCenter />}
|
||||||
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<View style={[Styles.mb15]}>
|
<View style={[Styles.mb15]}>
|
||||||
{selectedImage != undefined ? (
|
{selectedImage != undefined ? (
|
||||||
<Pressable onPress={pickImageAsync}>
|
<Pressable onPress={pickImageAsync}>
|
||||||
<Image
|
<Image
|
||||||
src={selectedImage}
|
src={selectedImage}
|
||||||
style={{ resizeMode: "contain", width: "100%", height: 100 }}
|
style={[Styles.resizeContain, Styles.w100, { height: 100 }]}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
) : (
|
) : (
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={pickImageAsync}
|
onPress={pickImageAsync}
|
||||||
style={[Styles.wrapPaper, Styles.contentItemCenter]}
|
style={[Styles.wrapPaper, Styles.contentItemCenter, Styles.borderAll, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}
|
||||||
>
|
>
|
||||||
<View
|
<View
|
||||||
style={{ justifyContent: "center", alignItems: "center" }}
|
style={[Styles.contentItemCenter]}
|
||||||
>
|
>
|
||||||
<Entypo name="image" size={50} color={"#aeaeae"} />
|
<Entypo name="image" size={50} color={colors.dimmed} />
|
||||||
<Text style={[Styles.textInformation, Styles.mt05]}>
|
<Text style={[Styles.textInformation, Styles.mt05, { color: colors.dimmed }]}>
|
||||||
Mohon unggah gambar dalam resolusi 1650 x 720 pixel untuk
|
Mohon unggah gambar dalam resolusi 1650 x 720 pixel untuk
|
||||||
memastikan
|
memastikan
|
||||||
</Text>
|
</Text>
|
||||||
@@ -165,7 +155,7 @@ export default function CreateBanner() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul"
|
placeholder="Judul"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
onChange={onValidate}
|
onChange={onValidate}
|
||||||
error={error}
|
error={error}
|
||||||
errorText="Judul harus diisi"
|
errorText="Judul harus diisi"
|
||||||
|
|||||||
@@ -1,22 +1,28 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi"
|
|
||||||
import AppHeader from "@/components/AppHeader"
|
import AppHeader from "@/components/AppHeader"
|
||||||
|
import GuideOverlay from "@/components/GuideOverlay"
|
||||||
import HeaderRightBannerList from "@/components/banner/headerBannerList"
|
import HeaderRightBannerList from "@/components/banner/headerBannerList"
|
||||||
import BorderBottomItem from "@/components/borderBottomItem"
|
import BorderBottomItem from "@/components/borderBottomItem"
|
||||||
import DrawerBottom from "@/components/drawerBottom"
|
import DrawerBottom from "@/components/drawerBottom"
|
||||||
import MenuItemRow from "@/components/menuItemRow"
|
import MenuItemRow from "@/components/menuItemRow"
|
||||||
|
import ModalConfirmation from "@/components/ModalConfirmation"
|
||||||
import ModalLoading from "@/components/modalLoading"
|
import ModalLoading from "@/components/modalLoading"
|
||||||
|
import Skeleton from "@/components/skeleton"
|
||||||
import Text from "@/components/Text"
|
import Text from "@/components/Text"
|
||||||
import { ConstEnv } from "@/constants/ConstEnv"
|
import { ConstEnv } from "@/constants/ConstEnv"
|
||||||
import Styles from "@/constants/Styles"
|
import Styles from "@/constants/Styles"
|
||||||
import { apiDeleteBanner, apiGetBanner } from "@/lib/api"
|
import { apiDeleteBanner, apiGetBanner } from "@/lib/api"
|
||||||
import { setEntities } from "@/lib/bannerSlice"
|
import { setEntities } from "@/lib/bannerSlice"
|
||||||
|
import { GUIDE_BANNER } from "@/lib/guideSteps"
|
||||||
|
import { useGuide } from "@/lib/useGuide"
|
||||||
import { useAuthSession } from "@/providers/AuthProvider"
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider"
|
||||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"
|
||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
|
||||||
import * as FileSystem from 'expo-file-system'
|
import * as FileSystem from 'expo-file-system'
|
||||||
import { startActivityAsync } from 'expo-intent-launcher'
|
import { startActivityAsync } from 'expo-intent-launcher'
|
||||||
import { router, Stack } from "expo-router"
|
import { router, Stack } from "expo-router"
|
||||||
import * as Sharing from 'expo-sharing'
|
import * as Sharing from 'expo-sharing'
|
||||||
import { useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { Alert, Image, Platform, RefreshControl, SafeAreaView, ScrollView, View } from "react-native"
|
import { Alert, Image, Platform, RefreshControl, SafeAreaView, ScrollView, View } from "react-native"
|
||||||
import ImageViewing from 'react-native-image-viewing'
|
import ImageViewing from 'react-native-image-viewing'
|
||||||
import * as mime from 'react-native-mime-types'
|
import * as mime from 'react-native-mime-types'
|
||||||
@@ -32,6 +38,7 @@ type Props = {
|
|||||||
|
|
||||||
export default function BannerList() {
|
export default function BannerList() {
|
||||||
const { decryptToken, token } = useAuthSession()
|
const { decryptToken, token } = useAuthSession()
|
||||||
|
const { colors } = useTheme()
|
||||||
const [isModal, setModal] = useState(false)
|
const [isModal, setModal] = useState(false)
|
||||||
const entities = useSelector((state: any) => state.banner)
|
const entities = useSelector((state: any) => state.banner)
|
||||||
const [dataId, setDataId] = useState('')
|
const [dataId, setDataId] = useState('')
|
||||||
@@ -39,35 +46,54 @@ export default function BannerList() {
|
|||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
const [loadingOpen, setLoadingOpen] = useState(false)
|
const [loadingOpen, setLoadingOpen] = useState(false)
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('banner')
|
||||||
const [viewImg, setViewImg] = useState(false)
|
const [viewImg, setViewImg] = useState(false)
|
||||||
|
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
const handleDeleteEntity = async () => {
|
// 1. Fetching logic with useQuery
|
||||||
try {
|
const { data: bannersRes, isLoading } = useQuery({
|
||||||
const hasil = await decryptToken(String(token?.current));
|
queryKey: ['banners'],
|
||||||
const deletedEntity = await apiDeleteBanner({ user: hasil }, dataId);
|
queryFn: async () => {
|
||||||
if (deletedEntity.success) {
|
const hasil = await decryptToken(String(token?.current))
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil menghapus data', })
|
const response = await apiGetBanner({ user: hasil })
|
||||||
apiGetBanner({ user: hasil }).then((data) =>
|
return response.data || []
|
||||||
dispatch(setEntities(data.data))
|
},
|
||||||
);
|
enabled: !!token?.current,
|
||||||
} else {
|
staleTime: 0,
|
||||||
Toast.show({ type: 'small', text1: 'Gagal menghapus data', })
|
})
|
||||||
}
|
|
||||||
} catch (error) {
|
// Sync results with Redux
|
||||||
console.error(error)
|
useEffect(() => {
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
if (bannersRes) {
|
||||||
} finally {
|
dispatch(setEntities(bannersRes))
|
||||||
setModal(false)
|
|
||||||
}
|
}
|
||||||
|
}, [bannersRes, dispatch])
|
||||||
|
|
||||||
|
// 2. Deletion logic with useMutation
|
||||||
|
const deleteMutation = useMutation({
|
||||||
|
mutationFn: async (id: string) => {
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
return await apiDeleteBanner({ user: hasil }, id)
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
Toast.show({ type: 'small', text1: 'Berhasil menghapus data' })
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['banners'] })
|
||||||
|
},
|
||||||
|
onError: (error: any) => {
|
||||||
|
const message = error?.response?.data?.message || "Gagal menghapus data"
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleDeleteEntity = () => {
|
||||||
|
deleteMutation.mutate(dataId)
|
||||||
|
setModal(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
const hasil = await decryptToken(String(token?.current));
|
await queryClient.invalidateQueries({ queryKey: ['banners'] })
|
||||||
apiGetBanner({ user: hasil }).then((data) =>
|
|
||||||
dispatch(setEntities(data.data))
|
|
||||||
);
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,7 +131,7 @@ export default function BannerList() {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -124,53 +150,58 @@ export default function BannerList() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<GuideOverlay visible={guideVisible} steps={GUIDE_BANNER} onDismiss={dismissGuide} />
|
||||||
<ModalLoading isVisible={loadingOpen} setVisible={setLoadingOpen} />
|
<ModalLoading isVisible={loadingOpen} setVisible={setLoadingOpen} />
|
||||||
<ScrollView
|
<ScrollView
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
>
|
>
|
||||||
{
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
entities.length > 0
|
{
|
||||||
?
|
isLoading ? (
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<>
|
||||||
{entities.map((index: any, key: number) => (
|
<Skeleton width={100} height={150} borderRadius={10} widthType="percent" />
|
||||||
<BorderBottomItem
|
<Skeleton width={100} height={150} borderRadius={10} widthType="percent" />
|
||||||
key={key}
|
<Skeleton width={100} height={150} borderRadius={10} widthType="percent" />
|
||||||
onPress={() => {
|
</>
|
||||||
setDataId(index.id)
|
) :
|
||||||
setSelectFile(index)
|
entities.length > 0 ?
|
||||||
setModal(true)
|
entities.map((index: any, key: number) => (
|
||||||
}}
|
<BorderBottomItem
|
||||||
borderType="all"
|
key={key}
|
||||||
icon={
|
onPress={() => {
|
||||||
<Image
|
setDataId(index.id)
|
||||||
source={{ uri: `${ConstEnv.url_storage}/files/${index.image}` }}
|
setSelectFile(index)
|
||||||
style={[Styles.imgListBanner]}
|
setModal(true)
|
||||||
/>
|
}}
|
||||||
}
|
borderType="all"
|
||||||
title={index.title}
|
icon={
|
||||||
width={65}
|
<Image
|
||||||
/>
|
source={{ uri: `${ConstEnv.url_storage}/files/${index.image}` }}
|
||||||
))}
|
style={[Styles.imgListBanner]}
|
||||||
</View>
|
/>
|
||||||
:
|
}
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
title={index.title}
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
|
/>
|
||||||
</View>
|
))
|
||||||
}
|
:
|
||||||
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
|
<Text style={[Styles.textDefault, Styles.textCenter]}>Tidak ada data</Text>
|
||||||
|
</View>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={() => setModal(false)} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={() => setModal(false)} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="pencil-outline" color={colors.text} size={25} />}
|
||||||
title="Edit"
|
title="Edit"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
@@ -178,7 +209,7 @@ export default function BannerList() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="file-eye" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="file-eye" color={colors.text} size={25} />}
|
||||||
title="Lihat"
|
title="Lihat"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
@@ -189,15 +220,13 @@ export default function BannerList() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
AlertKonfirmasi({
|
setTimeout(() => {
|
||||||
title: 'Konfirmasi',
|
setShowDeleteModal(true)
|
||||||
desc: 'Apakah anda yakin ingin menghapus data?',
|
}, 600)
|
||||||
onPress: () => { handleDeleteEntity() }
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
@@ -210,6 +239,19 @@ export default function BannerList() {
|
|||||||
onRequestClose={() => setViewImg(false)}
|
onRequestClose={() => setViewImg(false)}
|
||||||
doubleTapToZoomEnabled
|
doubleTapToZoomEnabled
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message="Apakah anda yakin ingin menghapus data?"
|
||||||
|
onConfirm={() => {
|
||||||
|
setShowDeleteModal(false)
|
||||||
|
handleDeleteEntity()
|
||||||
|
}}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText="Hapus"
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,439 +1,290 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi";
|
|
||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import BorderBottomItem2 from "@/components/borderBottomItem2";
|
import BorderBottomItem2 from "@/components/borderBottomItem2";
|
||||||
|
import DiscussionCommentInput from "@/components/discussion_general/discussionCommentInput";
|
||||||
|
import DiscussionCommentList, { CommentFile, CommentItem } from "@/components/discussion_general/discussionCommentList";
|
||||||
import HeaderRightDiscussionGeneralDetail from "@/components/discussion_general/headerDiscussionDetail";
|
import HeaderRightDiscussionGeneralDetail from "@/components/discussion_general/headerDiscussionDetail";
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import ImageUser from "@/components/imageNew";
|
|
||||||
import { InputForm } from "@/components/inputForm";
|
|
||||||
import LabelStatus from "@/components/labelStatus";
|
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
import Skeleton from "@/components/skeleton";
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
import SkeletonContent from "@/components/skeletonContent";
|
import SkeletonContent from "@/components/skeletonContent";
|
||||||
import Text from '@/components/Text';
|
import Text from '@/components/Text';
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
|
||||||
import { ConstEnv } from "@/constants/ConstEnv";
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
import { regexOnlySpacesOrEnter } from "@/constants/OnlySpaceOrEnter";
|
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiDeleteDiscussionGeneralCommentar, apiGetDiscussionGeneralOne, apiSendDiscussionGeneralCommentar, apiUpdateDiscussionGeneralCommentar } from "@/lib/api";
|
import { apiDeleteDiscussionGeneralCommentar, apiGetDiscussionGeneralOne, apiSendDiscussionGeneralCommentar, apiSendDiscussionGeneralCommentarWithFile, apiUpdateDiscussionGeneralCommentar } from "@/lib/api";
|
||||||
import { getDB } from "@/lib/firebaseDatabase";
|
import { getDB } from "@/lib/firebaseDatabase";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { Feather, Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { Feather, Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
import { ref } from '@react-native-firebase/database';
|
import { ref } from '@react-native-firebase/database';
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import React, { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { KeyboardAvoidingView, Platform, Pressable, RefreshControl, ScrollView, View } from "react-native";
|
import { KeyboardAvoidingView, Platform, RefreshControl, ScrollView, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
type Props = {
|
type DiscussionDetail = {
|
||||||
id: string
|
id: string; isActive: boolean; title: string
|
||||||
isActive: boolean
|
desc: string; status: number; createdAt: string
|
||||||
title: string
|
|
||||||
desc: string
|
|
||||||
status: number
|
|
||||||
createdAt: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PropsKomentar = {
|
type PropsFile = { id: string; idStorage: string; name: string; extension: string }
|
||||||
id: string
|
|
||||||
comment: string
|
|
||||||
createdAt: string
|
|
||||||
idUser: string
|
|
||||||
img: string
|
|
||||||
username: string
|
|
||||||
isEdited: boolean
|
|
||||||
updatedAt: string
|
|
||||||
}
|
|
||||||
|
|
||||||
type PropsFile = {
|
|
||||||
id: string;
|
|
||||||
idStorage: string;
|
|
||||||
name: string;
|
|
||||||
extension: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function DetailDiscussionGeneral() {
|
export default function DetailDiscussionGeneral() {
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme()
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const entities = useSelector((state: any) => state.entities)
|
const entities = useSelector((state: any) => state.entities)
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [data, setData] = useState<Props>()
|
const [data, setData] = useState<DiscussionDetail>()
|
||||||
const [dataKomentar, setDataKomentar] = useState<PropsKomentar[]>([])
|
const [dataKomentar, setDataKomentar] = useState<CommentItem[]>([])
|
||||||
const [memberDiscussion, setMemberDiscussion] = useState(false)
|
const [memberDiscussion, setMemberDiscussion] = useState(false)
|
||||||
const [fileDiscussion, setFileDiscussion] = useState<PropsFile[]>([])
|
const [fileDiscussion, setFileDiscussion] = useState<PropsFile[]>([])
|
||||||
const [komentar, setKomentar] = useState('')
|
const [komentar, setKomentar] = useState('')
|
||||||
|
const [commentFiles, setCommentFiles] = useState<{ uri: string; name: string }[]>([])
|
||||||
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [loadingKomentar, setLoadingKomentar] = useState(true)
|
const [loadingKomentar, setLoadingKomentar] = useState(true)
|
||||||
const arrSkeleton = Array.from({ length: 3 }, (_, index) => index)
|
const [loadingSend, setLoadingSend] = useState(false)
|
||||||
const reference = ref(getDB(), `/discussion-general/${id}`);
|
|
||||||
const headerHeight = useHeaderHeight();
|
|
||||||
const [detailMore, setDetailMore] = useState<any>([])
|
|
||||||
const [loadingSendKomentar, setLoadingSendKomentar] = useState(false)
|
|
||||||
const [isVisible, setVisible] = useState(false)
|
const [isVisible, setVisible] = useState(false)
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
const [selectKomentar, setSelectKomentar] = useState({
|
const [selectKomentar, setSelectKomentar] = useState<{ id: string; comment: string; files: CommentFile[] }>({ id: '', comment: '', files: [] })
|
||||||
id: '',
|
const [removedFileIds, setRemovedFileIds] = useState<string[]>([])
|
||||||
comment: ''
|
|
||||||
})
|
|
||||||
const [viewEdit, setViewEdit] = useState(false)
|
const [viewEdit, setViewEdit] = useState(false)
|
||||||
|
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||||
|
const reference = ref(getDB(), `/discussion-general/${id}`)
|
||||||
|
const headerHeight = useHeaderHeight()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onValueChange = reference.on('value', snapshot => {
|
const onValueChange = reference.on('value', snapshot => {
|
||||||
if (snapshot.val() == null) {
|
if (snapshot.val() == null) reference.set({ trigger: true })
|
||||||
reference.set({ trigger: true })
|
|
||||||
}
|
|
||||||
handleLoad('komentar', false)
|
handleLoad('komentar', false)
|
||||||
});
|
})
|
||||||
|
return () => reference.off('value', onValueChange)
|
||||||
// Stop listening for updates when no longer required
|
}, [])
|
||||||
return () => reference.off('value', onValueChange);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
function updateTrigger() {
|
function updateTrigger() {
|
||||||
reference.once('value', snapshot => {
|
reference.once('value', snapshot => {
|
||||||
const data = snapshot.val();
|
reference.update({ trigger: !snapshot.val().trigger })
|
||||||
reference.update({ trigger: !data.trigger });
|
})
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleLoad(cat: 'detail' | 'komentar' | 'cek-anggota' | 'file', showLoading: boolean) {
|
||||||
async function handleLoad(cat: 'detail' | 'komentar' | 'cek-anggota' | 'file', loading: boolean) {
|
|
||||||
try {
|
try {
|
||||||
if (cat == "detail") {
|
if (cat === 'detail') setLoading(showLoading)
|
||||||
setLoading(loading)
|
else if (cat === 'komentar') setLoadingKomentar(showLoading)
|
||||||
} else if (cat == "komentar") {
|
|
||||||
setLoadingKomentar(loading)
|
|
||||||
}
|
|
||||||
|
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiGetDiscussionGeneralOne({ id: id, user: hasil, cat })
|
const response = await apiGetDiscussionGeneralOne({ id, user: hasil, cat })
|
||||||
|
if (cat === 'detail') setData(response.data)
|
||||||
if (cat == 'detail') {
|
else if (cat === 'komentar') setDataKomentar(response.data)
|
||||||
setData(response.data)
|
else if (cat === 'cek-anggota') setMemberDiscussion(response.data)
|
||||||
} else if (cat == 'komentar') {
|
else if (cat === 'file') setFileDiscussion(response.data)
|
||||||
setDataKomentar(response.data)
|
} catch (error) { console.error(error) }
|
||||||
} else if (cat == 'cek-anggota') {
|
finally { setLoading(false); setLoadingKomentar(false) }
|
||||||
setMemberDiscussion(response.data)
|
|
||||||
} else if (cat == 'file') {
|
|
||||||
setFileDiscussion(response.data)
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
setLoadingKomentar(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLoad('detail', false)
|
handleLoad('detail', true); handleLoad('komentar', true)
|
||||||
handleLoad('komentar', false)
|
handleLoad('cek-anggota', true); handleLoad('file', true)
|
||||||
handleLoad('cek-anggota', false)
|
}, [])
|
||||||
handleLoad('file', false)
|
|
||||||
}, [update]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLoad('detail', true)
|
handleLoad('detail', false); handleLoad('komentar', false)
|
||||||
handleLoad('komentar', true)
|
handleLoad('cek-anggota', false); handleLoad('file', false)
|
||||||
handleLoad('cek-anggota', true)
|
}, [update])
|
||||||
handleLoad('file', true)
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
async function handleKomentar() {
|
async function handleKomentar() {
|
||||||
try {
|
try {
|
||||||
setLoadingSendKomentar(true)
|
setLoadingSend(true)
|
||||||
if (komentar != '') {
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const hasil = await decryptToken(String(token?.current))
|
let response
|
||||||
const response = await apiSendDiscussionGeneralCommentar({ id: id, data: { desc: komentar, user: hasil } })
|
if (commentFiles.length > 0) {
|
||||||
if (response.success) {
|
const fd = new FormData()
|
||||||
setKomentar('')
|
commentFiles.forEach((f, i) =>
|
||||||
updateTrigger()
|
fd.append(`file${i}`, { uri: f.uri, type: 'application/octet-stream', name: f.name } as any)
|
||||||
} else {
|
)
|
||||||
Toast.show({ type: 'small', text1: response.message })
|
fd.append("data", JSON.stringify({ desc: komentar, user: hasil }))
|
||||||
}
|
response = await apiSendDiscussionGeneralCommentarWithFile(id, fd)
|
||||||
|
} else {
|
||||||
|
response = await apiSendDiscussionGeneralCommentar({ id, data: { desc: komentar, user: hasil } })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
if (response.success) {
|
||||||
console.error(error)
|
setKomentar(''); setCommentFiles([])
|
||||||
} finally {
|
updateTrigger()
|
||||||
setLoadingSendKomentar(false)
|
} else {
|
||||||
}
|
Toast.show({ type: 'small', text1: response.message })
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal menambahkan data" })
|
||||||
|
} finally { setLoadingSend(false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleEditKomentar() {
|
async function handleEditKomentar() {
|
||||||
try {
|
try {
|
||||||
setLoadingSendKomentar(true)
|
setLoadingSend(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiUpdateDiscussionGeneralCommentar({ id: selectKomentar.id, data: { desc: selectKomentar.comment, user: hasil } })
|
const response = await apiUpdateDiscussionGeneralCommentar({ id: selectKomentar.id, data: { desc: selectKomentar.comment, user: hasil, filesToRemove: removedFileIds } })
|
||||||
if (response.success) {
|
if (response.success) updateTrigger()
|
||||||
updateTrigger()
|
else Toast.show({ type: 'small', text1: response.message })
|
||||||
} else {
|
} catch (error: any) {
|
||||||
Toast.show({ type: 'small', text1: response.message })
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal mengupdate data" })
|
||||||
}
|
} finally { setLoadingSend(false); handleViewEditKomentar() }
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
} finally {
|
|
||||||
setLoadingSendKomentar(false)
|
|
||||||
handleViewEditKomentar()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleDeleteKomentar() {
|
async function handleDeleteKomentar() {
|
||||||
try {
|
try {
|
||||||
setLoadingSendKomentar(true)
|
setLoadingSend(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiDeleteDiscussionGeneralCommentar({ id: selectKomentar.id, data: { user: hasil } })
|
const response = await apiDeleteDiscussionGeneralCommentar({ id: selectKomentar.id, data: { user: hasil } })
|
||||||
if (response.success) {
|
if (response.success) updateTrigger()
|
||||||
updateTrigger()
|
else Toast.show({ type: 'small', text1: response.message })
|
||||||
} else {
|
} catch (error: any) {
|
||||||
Toast.show({ type: 'small', text1: response.message })
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal menghapus data" })
|
||||||
}
|
} finally { setLoadingSend(false); setVisible(false) }
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
} finally {
|
|
||||||
setLoadingSendKomentar(false)
|
|
||||||
setVisible(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMenuKomentar(id: string, comment: string) {
|
function handleViewEditKomentar() { setVisible(false); setViewEdit(!viewEdit); setRemovedFileIds([]) }
|
||||||
setSelectKomentar({ id, comment })
|
|
||||||
setVisible(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleViewEditKomentar() {
|
const isLocked = data?.status === 2 || !data?.isActive
|
||||||
setVisible(false)
|
const isMember = memberDiscussion || (entityUser.role !== "user" && entityUser.role !== "coadmin")
|
||||||
setViewEdit(!viewEdit)
|
const canComment = !isLocked && isMember
|
||||||
|
|
||||||
|
function lockedReason() {
|
||||||
|
if (data?.status === 2) return "Diskusi telah ditutup"
|
||||||
|
if (!data?.isActive) return "Diskusi telah diarsipkan"
|
||||||
|
return "Hanya anggota diskusi yang dapat memberikan komentar"
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleLoad('detail', false)
|
handleLoad('detail', false); handleLoad('komentar', false)
|
||||||
handleLoad('komentar', false)
|
handleLoad('cek-anggota', false); handleLoad('file', false)
|
||||||
handleLoad('cek-anggota', false)
|
await new Promise(resolve => setTimeout(resolve, 2000))
|
||||||
handleLoad('file', false)
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Diskusi',
|
|
||||||
headerTitleAlign: 'center',
|
|
||||||
// headerRight: () => <HeaderRightDiscussionGeneralDetail id={id} active={data?.isActive !== undefined ? data.isActive : false} status={data?.status !== undefined ? data.status : 0} />,
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Diskusi"
|
title="Diskusi"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={<HeaderRightDiscussionGeneralDetail id={id} active={data?.isActive !== undefined ? data.isActive : false} status={data?.status !== undefined ? data.status : 0} />}
|
right={<HeaderRightDiscussionGeneralDetail id={id} active={data?.isActive ?? false} status={data?.status ?? 0} />}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={{ flex: 1 }}>
|
<View style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
refreshControl={
|
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} tintColor={colors.icon} />}
|
||||||
<RefreshControl
|
|
||||||
refreshing={refreshing}
|
|
||||||
onRefresh={() => handleRefresh()}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15]}>
|
<View style={Styles.p15}>
|
||||||
{
|
{loading ? <SkeletonContent /> : (
|
||||||
loading ?
|
<BorderBottomItem2
|
||||||
<SkeletonContent />
|
dataFile={fileDiscussion}
|
||||||
:
|
descEllipsize={false}
|
||||||
<BorderBottomItem2
|
borderType="all"
|
||||||
dataFile={fileDiscussion}
|
bgColor="white"
|
||||||
descEllipsize={false}
|
icon={
|
||||||
borderType="bottom"
|
<View style={[Styles.discussionIconCircleLg, { backgroundColor: colors.icon + '20' }]}>
|
||||||
icon={
|
<Feather name="message-circle" size={22} color={colors.icon} />
|
||||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
|
||||||
<MaterialIcons name="chat" size={25} color={'#384288'} />
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
title={data?.title}
|
|
||||||
titleShowAll={true}
|
|
||||||
subtitle={
|
|
||||||
!data?.isActive ?
|
|
||||||
<LabelStatus category='warning' text='ARSIP' size="small" />
|
|
||||||
:
|
|
||||||
<LabelStatus category={data.status == 1 ? 'success' : 'error'} text={data.status == 1 ? 'BUKA' : 'TUTUP'} size="small" />
|
|
||||||
}
|
|
||||||
desc={data?.desc}
|
|
||||||
leftBottomInfo={
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>{dataKomentar.length} Komentar</Text>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
rightBottomInfo={
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>{data?.createdAt}</Text>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
<View style={[Styles.p15]}>
|
|
||||||
{
|
|
||||||
loadingKomentar ?
|
|
||||||
arrSkeleton.map((item: any, i: number) => {
|
|
||||||
return (
|
|
||||||
<Skeleton key={i} width={100} widthType="percent" height={40} borderRadius={5} />
|
|
||||||
)
|
|
||||||
})
|
|
||||||
:
|
|
||||||
dataKomentar.map((item, i) => {
|
|
||||||
return (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={i}
|
|
||||||
borderType="bottom"
|
|
||||||
colorPress
|
|
||||||
icon={
|
|
||||||
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
|
|
||||||
}
|
|
||||||
title={item.username}
|
|
||||||
rightTopInfo={item.createdAt}
|
|
||||||
desc={item.comment}
|
|
||||||
rightBottomInfo={item.isEdited ? "Edited" : ""}
|
|
||||||
descEllipsize={detailMore.includes(item.id) ? false : true}
|
|
||||||
onPress={() => {
|
|
||||||
setDetailMore((prev: any) => {
|
|
||||||
if (prev.includes(item.id)) {
|
|
||||||
return prev.filter((id: string) => id !== item.id)
|
|
||||||
} else {
|
|
||||||
return [...prev, item.id]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
onLongPress={() => {
|
|
||||||
item.idUser == entities.id && data?.status != 2 && data?.isActive && handleMenuKomentar(item.id, item.comment)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</ScrollView>
|
|
||||||
<KeyboardAvoidingView
|
|
||||||
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
|
||||||
keyboardVerticalOffset={headerHeight}
|
|
||||||
>
|
|
||||||
<View style={[
|
|
||||||
Styles.contentItemCenter,
|
|
||||||
Styles.w100,
|
|
||||||
{ backgroundColor: "#f4f4f4" },
|
|
||||||
viewEdit && Styles.borderTop
|
|
||||||
]}>
|
|
||||||
{
|
|
||||||
viewEdit ?
|
|
||||||
<>
|
|
||||||
<View style={[Styles.w90, Styles.rowSpaceBetween, Styles.pv05]}>
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Feather name="edit-3" color="black" size={22} style={[Styles.mh05]} />
|
|
||||||
<Text style={[Styles.textMediumSemiBold]}>Edit Komentar</Text>
|
|
||||||
</View>
|
|
||||||
<Pressable onPress={() => handleViewEditKomentar()}>
|
|
||||||
<MaterialIcons name="close" color="black" size={22} />
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
</View>
|
||||||
<InputForm
|
}
|
||||||
disable={(data?.status === 2 || !data?.isActive || (!memberDiscussion && (entityUser.role == "user" || entityUser.role == "coadmin")))}
|
title={data?.title}
|
||||||
type="default"
|
titleShowAll={true}
|
||||||
round
|
subtitle={
|
||||||
placeholder="Kirim Komentar"
|
<View style={[Styles.discussionStatusPill, {
|
||||||
bg="white"
|
borderColor: !data?.isActive ? '#F59E0B' : data?.status === 1 ? '#10B981' : colors.dimmed + '80'
|
||||||
onChange={(val: string) => setSelectKomentar({ ...selectKomentar, comment: val })}
|
}]}>
|
||||||
value={selectKomentar.comment}
|
<Text style={[Styles.discussionStatusText, {
|
||||||
multiline
|
color: !data?.isActive ? '#F59E0B' : data?.status === 1 ? '#10B981' : colors.dimmed
|
||||||
focus={viewEdit}
|
}]}>
|
||||||
itemRight={
|
{!data?.isActive ? 'Arsip' : data?.status === 1 ? 'Buka' : 'Tutup'}
|
||||||
<Pressable onPress={() => {
|
|
||||||
(!loadingSendKomentar && selectKomentar.comment != '' && !regexOnlySpacesOrEnter.test(selectKomentar.comment) && data?.status === 1 && data?.isActive && (memberDiscussion || (entityUser.role != "user" && entityUser.role != "coadmin")))
|
|
||||||
&& handleEditKomentar()
|
|
||||||
}}
|
|
||||||
style={[
|
|
||||||
Platform.OS == 'android' && Styles.mb12,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<MaterialIcons name="send" size={25} style={(loadingSendKomentar || selectKomentar.comment == '' || regexOnlySpacesOrEnter.test(selectKomentar.comment) || data?.status === 2 || !data?.isActive || (!memberDiscussion && (entityUser.role == "user" || entityUser.role == "coadmin"))) ? Styles.cGray : Styles.cDefault} />
|
|
||||||
</Pressable>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
:
|
|
||||||
data?.status != 2 && data?.isActive && ((entityUser.role != "user" && entityUser.role != "coadmin") || memberDiscussion)
|
|
||||||
?
|
|
||||||
<InputForm
|
|
||||||
disable={(data?.status === 2 || !data?.isActive || (!memberDiscussion && (entityUser.role == "user" || entityUser.role == "coadmin")))}
|
|
||||||
type="default"
|
|
||||||
round
|
|
||||||
placeholder="Kirim Komentar"
|
|
||||||
bg="white"
|
|
||||||
onChange={setKomentar}
|
|
||||||
value={komentar}
|
|
||||||
multiline
|
|
||||||
focus={viewEdit}
|
|
||||||
itemRight={
|
|
||||||
<Pressable onPress={() => {
|
|
||||||
(!loadingSendKomentar && komentar != '' && !regexOnlySpacesOrEnter.test(komentar) && data?.status === 1 && data?.isActive && (memberDiscussion || (entityUser.role != "user" && entityUser.role != "coadmin")))
|
|
||||||
&& handleKomentar()
|
|
||||||
}}
|
|
||||||
style={[
|
|
||||||
Platform.OS == 'android' && Styles.mb12,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<MaterialIcons name="send" size={25} style={(loadingSendKomentar || komentar == '' || regexOnlySpacesOrEnter.test(komentar) || data?.status === 2 || !data?.isActive || (!memberDiscussion && (entityUser.role == "user" || entityUser.role == "coadmin"))) ? Styles.cGray : Styles.cDefault} />
|
|
||||||
</Pressable>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
:
|
|
||||||
<View style={[Styles.pv20, { alignItems: 'center' }]}>
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray]}>
|
|
||||||
{
|
|
||||||
data?.status == 2 ? "Diskusi telah ditutup" : data?.isActive == false ? "Diskusi telah diarsipkan" : "Hanya anggota diskusi yang dapat memberikan komentar"
|
|
||||||
}
|
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
|
desc={data?.desc}
|
||||||
|
leftBottomInfo={
|
||||||
|
<View style={Styles.rowItemsCenter}>
|
||||||
|
<Feather name="message-square" size={14} color={colors.dimmed} style={Styles.mr05} />
|
||||||
|
<Text style={[Styles.textInformation, { color: colors.dimmed }]}>{dataKomentar.length} Komentar</Text>
|
||||||
|
</View>
|
||||||
|
}
|
||||||
|
rightBottomInfo={<Text style={[Styles.textInformation, { color: colors.dimmed }]}>{data?.createdAt}</Text>}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<DiscussionCommentList
|
||||||
|
data={dataKomentar}
|
||||||
|
loading={loadingKomentar}
|
||||||
|
myId={entities.id}
|
||||||
|
canInteract={data?.status !== 2 && data?.isActive === true}
|
||||||
|
onLongPress={(commentId, comment, files) => {
|
||||||
|
setSelectKomentar({ id: commentId, comment, files })
|
||||||
|
setRemovedFileIds([])
|
||||||
|
setVisible(true)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} keyboardVerticalOffset={headerHeight}>
|
||||||
|
{canComment ? (
|
||||||
|
<DiscussionCommentInput
|
||||||
|
mode={viewEdit ? 'edit' : 'new'}
|
||||||
|
value={viewEdit ? selectKomentar.comment : komentar}
|
||||||
|
onChange={viewEdit
|
||||||
|
? (val) => setSelectKomentar({ ...selectKomentar, comment: val })
|
||||||
|
: setKomentar
|
||||||
|
}
|
||||||
|
loading={loadingSend}
|
||||||
|
onSend={viewEdit ? handleEditKomentar : handleKomentar}
|
||||||
|
onCancelEdit={handleViewEditKomentar}
|
||||||
|
files={commentFiles}
|
||||||
|
onAddFile={(newFiles) => setCommentFiles(prev => [...prev, ...newFiles])}
|
||||||
|
onRemoveFile={(idx) => setCommentFiles(prev => prev.filter((_, i) => i !== idx))}
|
||||||
|
existingFiles={viewEdit ? selectKomentar.files.filter(f => !removedFileIds.includes(f.id)) : []}
|
||||||
|
onRemoveExistingFile={(fileId) => setRemovedFileIds(prev => [...prev, fileId])}
|
||||||
|
canSend={canComment}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<DiscussionCommentInput
|
||||||
|
mode="locked"
|
||||||
|
lockedReason={lockedReason()}
|
||||||
|
value="" onChange={() => {}} loading={false} onSend={() => {}} canSend={false}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</KeyboardAvoidingView>
|
</KeyboardAvoidingView>
|
||||||
</View >
|
</View>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Komentar">
|
<DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Komentar">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="pencil-outline" color={colors.text} size={25} />}
|
||||||
title="Edit"
|
title="Edit"
|
||||||
onPress={() => { handleViewEditKomentar() }}
|
onPress={() => handleViewEditKomentar()}
|
||||||
/>
|
/>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialIcons name="delete" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => {
|
onPress={() => { setVisible(false); setTimeout(() => setShowDeleteModal(true), 600) }}
|
||||||
AlertKonfirmasi({
|
|
||||||
title: 'Konfirmasi',
|
|
||||||
desc: 'Apakah anda yakin ingin menghapus komentar?',
|
|
||||||
onPress: () => {
|
|
||||||
handleDeleteKomentar()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message="Apakah anda yakin ingin menghapus komentar?"
|
||||||
|
onConfirm={() => { setShowDeleteModal(false); handleDeleteKomentar() }}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText="Hapus"
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,67 +6,159 @@ import InputSearch from "@/components/inputSearch";
|
|||||||
import Text from '@/components/Text';
|
import Text from '@/components/Text';
|
||||||
import { ConstEnv } from "@/constants/ConstEnv";
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiAddMemberDiscussionGeneral, apiGetDiscussionGeneralOne, apiGetUser } from "@/lib/api";
|
import { apiAddMemberDiscussionGeneral, apiGetDiscussionGeneralOne, apiGetDivision, apiGetDivisionMember, apiGetUser } from "@/lib/api";
|
||||||
import { setUpdateDiscussionGeneralDetail } from "@/lib/discussionGeneralDetail";
|
import { setUpdateDiscussionGeneralDetail } from "@/lib/discussionGeneralDetail";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { AntDesign, Ionicons } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Pressable, SafeAreaView, ScrollView, View } from "react-native";
|
import { ActivityIndicator, Pressable, ScrollView, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
type Props = {
|
type Member = { idUser: string; name: string; img: string }
|
||||||
idUser: string,
|
|
||||||
name: string,
|
type DivisionItem = {
|
||||||
img: string
|
id: string
|
||||||
|
name: string
|
||||||
|
expanded: boolean
|
||||||
|
membersLoaded: boolean
|
||||||
|
members: Member[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function AddMemberDiscussionDetail() {
|
export default function AddMemberDiscussionDetail() {
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme()
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [dataOld, setDataOld] = useState<Props[]>([])
|
const [dataOld, setDataOld] = useState<any[]>([])
|
||||||
const [data, setData] = useState<Props[]>([])
|
|
||||||
const [idGroup, setIdGroup] = useState('')
|
const [idGroup, setIdGroup] = useState('')
|
||||||
const [selectMember, setSelectMember] = useState<any[]>([])
|
const [selectMember, setSelectMember] = useState<Member[]>([])
|
||||||
const [search, setSearch] = useState('')
|
const [search, setSearch] = useState('')
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [divisions, setDivisions] = useState<DivisionItem[]>([])
|
||||||
|
const [loadingDivisions, setLoadingDivisions] = useState(false)
|
||||||
|
const [loadingIds, setLoadingIds] = useState<string[]>([])
|
||||||
|
const [searchResults, setSearchResults] = useState<Member[]>([])
|
||||||
|
const [loadingSearch, setLoadingSearch] = useState(false)
|
||||||
|
|
||||||
async function handleLoad() {
|
async function handleLoad() {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiGetDiscussionGeneralOne({ id: id, user: hasil, cat: 'anggota' })
|
const [resAnggota, resDetail] = await Promise.all([
|
||||||
setDataOld(response.data)
|
apiGetDiscussionGeneralOne({ id, user: hasil, cat: 'anggota' }),
|
||||||
const responseGroup = await apiGetDiscussionGeneralOne({ id: id, user: hasil, cat: 'detail' })
|
apiGetDiscussionGeneralOne({ id, user: hasil, cat: 'detail' })
|
||||||
setIdGroup(responseGroup.data.idGroup)
|
])
|
||||||
|
setDataOld(resAnggota.data ?? [])
|
||||||
|
setIdGroup(resDetail.data.idGroup)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleLoadMember() {
|
async function loadDivisions(group: string) {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
if (!group) return
|
||||||
const response = await apiGetUser({ user: hasil, active: "true", search: search, group: String(idGroup) })
|
setLoadingDivisions(true)
|
||||||
setData(response.data.filter((i: any) => i.idUserRole != 'supadmin'))
|
try {
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
const response = await apiGetDivision({ user: hasil, search: '', group, active: 'true', kategori: 'semua', page: 1 })
|
||||||
|
const divisionList: DivisionItem[] = (response.data ?? []).map((d: any) => ({
|
||||||
|
id: d.id, name: d.name, expanded: false, membersLoaded: false, members: []
|
||||||
|
}))
|
||||||
|
const withMembers = await Promise.all(
|
||||||
|
divisionList.map(async (d) => {
|
||||||
|
try {
|
||||||
|
const res = await apiGetDivisionMember({ user: hasil, id: d.id, search: '' })
|
||||||
|
const members: Member[] = (res.data ?? []).map((m: any) => ({ idUser: m.idUser, name: m.name, img: m.img }))
|
||||||
|
return { ...d, members, membersLoaded: true }
|
||||||
|
} catch {
|
||||||
|
return { ...d, membersLoaded: true }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
setDivisions(withMembers)
|
||||||
|
} catch { setDivisions([]) }
|
||||||
|
finally { setLoadingDivisions(false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchMembers(divisionId: string): Promise<Member[]> {
|
||||||
|
setLoadingIds(prev => [...prev, divisionId])
|
||||||
|
try {
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
const response = await apiGetDivisionMember({ user: hasil, id: divisionId, search: '' })
|
||||||
|
const members: Member[] = (response.data ?? []).map((m: any) => ({ idUser: m.idUser, name: m.name, img: m.img }))
|
||||||
|
setDivisions(prev => prev.map(d =>
|
||||||
|
d.id === divisionId ? { ...d, members, membersLoaded: true } : d
|
||||||
|
))
|
||||||
|
return members
|
||||||
|
} catch { return [] }
|
||||||
|
finally { setLoadingIds(prev => prev.filter(i => i !== divisionId)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function searchUsers(query: string) {
|
||||||
|
if (!idGroup) return
|
||||||
|
setLoadingSearch(true)
|
||||||
|
try {
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
const response = await apiGetUser({ user: hasil, active: 'true', search: query, group: idGroup })
|
||||||
|
setSearchResults((response.data ?? [])
|
||||||
|
.filter((i: any) => i.idUserRole !== 'supadmin')
|
||||||
|
.map((i: any) => ({ idUser: i.id, name: i.name, img: i.img }))
|
||||||
|
)
|
||||||
|
} catch { setSearchResults([]) }
|
||||||
|
finally { setLoadingSearch(false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => { handleLoad() }, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLoad()
|
if (idGroup) loadDivisions(idGroup)
|
||||||
}, []);
|
}, [idGroup])
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLoadMember()
|
if (!idGroup) return
|
||||||
|
if (search) {
|
||||||
|
searchUsers(search)
|
||||||
|
} else {
|
||||||
|
setSearchResults([])
|
||||||
|
loadDivisions(idGroup)
|
||||||
|
}
|
||||||
}, [search])
|
}, [search])
|
||||||
|
|
||||||
function onChoose(val: string, label: string, img?: string) {
|
async function handleTapDivision(division: DivisionItem) {
|
||||||
if (selectMember.some((i: any) => i.idUser == val)) {
|
let members = division.members
|
||||||
setSelectMember(selectMember.filter((i: any) => i.idUser != val))
|
if (!division.membersLoaded) members = await fetchMembers(division.id)
|
||||||
|
setDivisions(prev => prev.map(d =>
|
||||||
|
d.id === division.id ? { ...d, expanded: true, members, membersLoaded: true } : d
|
||||||
|
))
|
||||||
|
const eligible = members.filter(m => !dataOld.some((o: any) => o.idUser === m.idUser))
|
||||||
|
const allSelected = eligible.length > 0 && eligible.every(m =>
|
||||||
|
selectMember.some(s => s.idUser === m.idUser)
|
||||||
|
)
|
||||||
|
if (allSelected) {
|
||||||
|
setSelectMember(prev => prev.filter(s => !eligible.some(m => m.idUser === s.idUser)))
|
||||||
} else {
|
} else {
|
||||||
setSelectMember([...selectMember, { idUser: val, name: label, img }])
|
const existingIds = new Set(selectMember.map(s => s.idUser))
|
||||||
|
setSelectMember(prev => [...prev, ...eligible.filter(m => !existingIds.has(m.idUser))])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleToggleExpand(divisionId: string) {
|
||||||
|
const division = divisions.find(d => d.id === divisionId)!
|
||||||
|
if (!division.membersLoaded && !division.expanded) await fetchMembers(divisionId)
|
||||||
|
setDivisions(prev => prev.map(d =>
|
||||||
|
d.id === divisionId ? { ...d, expanded: !d.expanded } : d
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleToggleMember(member: Member) {
|
||||||
|
if (dataOld.some((o: any) => o.idUser === member.idUser)) return
|
||||||
|
if (selectMember.some(s => s.idUser === member.idUser)) {
|
||||||
|
setSelectMember(prev => prev.filter(s => s.idUser !== member.idUser))
|
||||||
|
} else {
|
||||||
|
setSelectMember(prev => [...prev, member])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,39 +166,26 @@ export default function AddMemberDiscussionDetail() {
|
|||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiAddMemberDiscussionGeneral({ id: id, data: { user: hasil, member: selectMember } })
|
const response = await apiAddMemberDiscussionGeneral({ id, data: { user: hasil, member: selectMember } })
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil menambahkan anggota', })
|
Toast.show({ type: 'small', text1: 'Berhasil menambahkan anggota' })
|
||||||
dispatch(setUpdateDiscussionGeneralDetail(!update))
|
dispatch(setUpdateDiscussionGeneralDetail(!update))
|
||||||
router.back()
|
router.back()
|
||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
Toast.show({ type: 'small', text1: 'Gagal menambahkan anggota', })
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal menambahkan anggota" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Tambah Anggota Diskusi',
|
|
||||||
headerTitleAlign: 'center',
|
|
||||||
// headerRight: () => (
|
|
||||||
// <ButtonSaveHeader
|
|
||||||
// category="update"
|
|
||||||
// disable={selectMember.length == 0 || loading ? true : false}
|
|
||||||
// onPress={() => {
|
|
||||||
// handleAddMember()
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// )
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Tambah Anggota Diskusi"
|
title="Tambah Anggota Diskusi"
|
||||||
@@ -115,77 +194,148 @@ export default function AddMemberDiscussionDetail() {
|
|||||||
right={
|
right={
|
||||||
<ButtonSaveHeader
|
<ButtonSaveHeader
|
||||||
category="update"
|
category="update"
|
||||||
disable={selectMember.length == 0 || loading ? true : false}
|
disable={selectMember.length === 0 || loading}
|
||||||
onPress={() => {
|
onPress={handleAddMember}
|
||||||
handleAddMember()
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<InputSearch onChange={setSearch} value={search} />
|
<InputSearch onChange={setSearch} value={search} />
|
||||||
|
{selectMember.length > 0 ? (
|
||||||
{
|
<View>
|
||||||
selectMember.length > 0
|
<ScrollView horizontal style={[Styles.mb10, Styles.pv10]} showsHorizontalScrollIndicator={false}>
|
||||||
?
|
{selectMember.map((item, index) => (
|
||||||
<View>
|
<ImageWithLabel
|
||||||
<ScrollView horizontal style={[Styles.mb10, Styles.pv10]} showsHorizontalScrollIndicator={false}>
|
key={index}
|
||||||
{
|
label={item.name}
|
||||||
selectMember.map((item: any, index: any) => (
|
src={`${ConstEnv.url_storage}/files/${item.img}`}
|
||||||
<ImageWithLabel
|
onClick={() => handleToggleMember(item)}
|
||||||
key={index}
|
/>
|
||||||
label={item.name}
|
))}
|
||||||
src={`${ConstEnv.url_storage}/files/${item.img}`}
|
</ScrollView>
|
||||||
onClick={() => onChoose(item.idUser, item.name, item.img)}
|
</View>
|
||||||
/>
|
) : (
|
||||||
))
|
<Text style={[Styles.textDefault, Styles.pv05, Styles.textCenter, { color: colors.dimmed }]}>
|
||||||
}
|
Tidak ada member yang dipilih
|
||||||
</ScrollView>
|
</Text>
|
||||||
</View>
|
)}
|
||||||
|
<ScrollView showsVerticalScrollIndicator={false}>
|
||||||
:
|
<View>
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.pv05, { textAlign: 'center' }]}>Tidak ada member yang dipilih</Text>
|
{search ? (
|
||||||
}
|
loadingSearch ? (
|
||||||
<ScrollView
|
<ActivityIndicator color={colors.tabActive} style={{ marginTop: 20 }} />
|
||||||
showsVerticalScrollIndicator={false}
|
) : searchResults.length > 0 ? (
|
||||||
>
|
searchResults.map((item, idx) => {
|
||||||
|
const isOld = dataOld.some((o: any) => o.idUser === item.idUser)
|
||||||
{
|
return (
|
||||||
data.length > 0 ?
|
<Pressable
|
||||||
data.map((item: any, index: any) => {
|
key={idx}
|
||||||
const found = dataOld.some((i: any) => i.idUser == item.id)
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
|
||||||
return (
|
onPress={() => !isOld && handleToggleMember(item)}
|
||||||
<Pressable
|
>
|
||||||
key={index}
|
<View style={Styles.rowItemsCenter}>
|
||||||
style={[Styles.itemSelectModal]}
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} border />
|
||||||
onPress={() => {
|
<View style={Styles.ml10}>
|
||||||
!found && onChoose(item.id, item.name, item.img)
|
<Text style={Styles.textDefault}>{item.name}</Text>
|
||||||
}}
|
{isOld && (
|
||||||
>
|
<Text style={[Styles.textInformation, { color: colors.dimmed }]}>sudah menjadi anggota</Text>
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
)}
|
||||||
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} border />
|
</View>
|
||||||
<View style={[Styles.ml10]}>
|
|
||||||
<Text style={[Styles.textDefault]}>{item.name}</Text>
|
|
||||||
{
|
|
||||||
found && <Text style={[Styles.textInformation, Styles.cGray]}>sudah menjadi anggota</Text>
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
{selectMember.some(s => s.idUser === item.idUser) && (
|
||||||
{
|
<AntDesign name="check" size={18} color={colors.tabActive} />
|
||||||
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={'black'} />
|
)}
|
||||||
}
|
</Pressable>
|
||||||
</Pressable>
|
)
|
||||||
)
|
})
|
||||||
}
|
) : (
|
||||||
|
<Text style={[Styles.textDefault, { textAlign: 'center', color: colors.dimmed, marginTop: 20 }]}>
|
||||||
|
Tidak ada hasil
|
||||||
|
</Text>
|
||||||
)
|
)
|
||||||
:
|
) : loadingDivisions ? (
|
||||||
<Text style={[Styles.textDefault, { textAlign: 'center' }]}>Tidak ada data</Text>
|
<ActivityIndicator color={colors.tabActive} style={{ marginTop: 20 }} />
|
||||||
}
|
) : divisions.length > 0 ? (
|
||||||
|
divisions.map((division) => {
|
||||||
|
const eligible = division.members.filter(m => !dataOld.some((o: any) => o.idUser === m.idUser))
|
||||||
|
const selectedCount = eligible.filter(m => selectMember.some(s => s.idUser === m.idUser)).length
|
||||||
|
const allSelected = division.membersLoaded && eligible.length > 0 && selectedCount === eligible.length
|
||||||
|
const someSelected = selectedCount > 0 && !allSelected
|
||||||
|
const isLoadingThis = loadingIds.includes(division.id)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View key={division.id}>
|
||||||
|
<Pressable
|
||||||
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
|
||||||
|
onPress={() => handleTapDivision(division)}
|
||||||
|
>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>{division.name}</Text>
|
||||||
|
{division.membersLoaded && (
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>
|
||||||
|
{selectedCount > 0
|
||||||
|
? `${selectedCount} dari ${eligible.length} dipilih`
|
||||||
|
: `${eligible.length} anggota`}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{isLoadingThis ? (
|
||||||
|
<ActivityIndicator size="small" color={colors.dimmed} />
|
||||||
|
) : allSelected ? (
|
||||||
|
<AntDesign name="checkcircle" size={18} color={colors.tabActive} />
|
||||||
|
) : someSelected ? (
|
||||||
|
<AntDesign name="checkcircleo" size={18} color={colors.tabActive} />
|
||||||
|
) : null}
|
||||||
|
<Pressable
|
||||||
|
onPress={() => handleToggleExpand(division.id)}
|
||||||
|
style={{ paddingLeft: 10 }}
|
||||||
|
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name={division.expanded ? "chevron-up" : "chevron-down"}
|
||||||
|
size={16}
|
||||||
|
color={colors.dimmed}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
|
{division.expanded && division.members.map((member, idx) => {
|
||||||
|
const isOld = dataOld.some((o: any) => o.idUser === member.idUser)
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={idx}
|
||||||
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '15' }]}
|
||||||
|
onPress={() => !isOld && handleToggleMember(member)}
|
||||||
|
>
|
||||||
|
<View style={Styles.rowItemsCenter}>
|
||||||
|
<ImageUser src={`${ConstEnv.url_storage}/files/${member.img}`} border />
|
||||||
|
<View style={Styles.ml10}>
|
||||||
|
<Text style={Styles.textDefault}>{member.name}</Text>
|
||||||
|
{isOld && (
|
||||||
|
<Text style={[Styles.textInformation, { color: colors.dimmed }]}>sudah menjadi anggota</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
{!isOld && selectMember.some(s => s.idUser === member.idUser) && (
|
||||||
|
<AntDesign name="check" size={18} color={colors.tabActive} />
|
||||||
|
)}
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<Text style={[Styles.textDefault, { textAlign: 'center', color: colors.dimmed, marginTop: 20 }]}>
|
||||||
|
Tidak ada divisi
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</View>
|
</View>
|
||||||
</SafeAreaView>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import ButtonSelect from "@/components/buttonSelect";
|
import ModalSelectMemberByDivision from "@/components/discussion_general/modalSelectMemberByDivision";
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import ImageUser from "@/components/imageNew";
|
import ImageUser from "@/components/imageNew";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import LoadingOverlay from "@/components/loadingOverlay";
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
import ModalSelect from "@/components/modalSelect";
|
import ModalSelect from "@/components/modalSelect";
|
||||||
import SelectForm from "@/components/selectForm";
|
import SelectForm from "@/components/selectForm";
|
||||||
@@ -16,109 +15,110 @@ import { apiCreateDiscussionGeneral } from "@/lib/api";
|
|||||||
import { setUpdateDiscussionGeneralDetail } from "@/lib/discussionGeneralDetail";
|
import { setUpdateDiscussionGeneralDetail } from "@/lib/discussionGeneralDetail";
|
||||||
import { setMemberChoose } from "@/lib/memberChoose";
|
import { setMemberChoose } from "@/lib/memberChoose";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
||||||
import * as DocumentPicker from "expo-document-picker";
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { Pressable, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
|
function getFileIcon(ext: string): keyof typeof MaterialCommunityIcons.glyphMap {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return 'image-outline'
|
||||||
|
if (ext === 'pdf') return 'file-pdf-box'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return 'video-outline'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return 'file-word-outline'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return 'file-excel-outline'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return 'zip-box-outline'
|
||||||
|
return 'file-outline'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileColor(ext: string): string {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return '#339AF0'
|
||||||
|
if (ext === 'pdf') return '#F03E3E'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return '#AE3EC9'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return '#1C7ED6'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return '#2F9E44'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return '#E8590C'
|
||||||
|
return '#868E96'
|
||||||
|
}
|
||||||
|
|
||||||
export default function CreateDiscussionGeneral() {
|
export default function CreateDiscussionGeneral() {
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const entityUser = useSelector((state: any) => state.user);
|
const entityUser = useSelector((state: any) => state.user);
|
||||||
const userLogin = useSelector((state: any) => state.entities)
|
const userLogin = useSelector((state: any) => state.entities)
|
||||||
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" });
|
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" });
|
||||||
const [valChoose, setValChoose] = useState("")
|
const [valChoose, setValChoose] = useState("")
|
||||||
const [valSelect, setValSelect] = useState<"group" | "member">("group");
|
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const [disableBtn, setDisableBtn] = useState(true);
|
const [disableBtn, setDisableBtn] = useState(true);
|
||||||
const [isSelect, setSelect] = useState(false);
|
const [isSelect, setSelect] = useState(false);
|
||||||
|
const [isMemberModal, setMemberModal] = useState(false);
|
||||||
const entitiesMember = useSelector((state: any) => state.memberChoose)
|
const entitiesMember = useSelector((state: any) => state.memberChoose)
|
||||||
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [fileForm, setFileForm] = useState<any[]>([])
|
const [fileForm, setFileForm] = useState<any[]>([])
|
||||||
const [isModalFile, setModalFile] = useState(false)
|
const [isModalFile, setModalFile] = useState(false)
|
||||||
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
||||||
const [dataForm, setDataForm] = useState({
|
const [dataForm, setDataForm] = useState({ idGroup: "", title: "", desc: "" });
|
||||||
idGroup: "",
|
const [error, setError] = useState({ group: false, title: false, desc: false });
|
||||||
title: "",
|
|
||||||
desc: "",
|
|
||||||
});
|
|
||||||
const [error, setError] = useState({
|
|
||||||
group: false,
|
|
||||||
title: false,
|
|
||||||
desc: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
function validationForm(cat: string, val: any, label?: string) {
|
function validationForm(cat: string, val: any, label?: string) {
|
||||||
if (cat == "group") {
|
if (cat === "group") {
|
||||||
setChooseGroup({ val, label: String(label) });
|
setChooseGroup({ val, label: String(label) });
|
||||||
dispatch(setMemberChoose([]))
|
dispatch(setMemberChoose([]))
|
||||||
setDataForm({ ...dataForm, idGroup: val });
|
setDataForm({ ...dataForm, idGroup: val });
|
||||||
if (val == "" || val == "null") {
|
setError({ ...error, group: val === "" || val === "null" });
|
||||||
setError({ ...error, group: true });
|
} else if (cat === "title") {
|
||||||
} else {
|
|
||||||
setError({ ...error, group: false });
|
|
||||||
}
|
|
||||||
} else if (cat == "title") {
|
|
||||||
setDataForm({ ...dataForm, title: val });
|
setDataForm({ ...dataForm, title: val });
|
||||||
if (val == "" || val == "null") {
|
setError({ ...error, title: val === "" || val === "null" });
|
||||||
setError({ ...error, title: true });
|
} else if (cat === "desc") {
|
||||||
} else {
|
|
||||||
setError({ ...error, title: false });
|
|
||||||
}
|
|
||||||
} else if (cat == "desc") {
|
|
||||||
setDataForm({ ...dataForm, desc: val });
|
setDataForm({ ...dataForm, desc: val });
|
||||||
if (val == "" || val == "null") {
|
setError({ ...error, desc: val === "" || val === "null" });
|
||||||
setError({ ...error, desc: true });
|
|
||||||
} else {
|
|
||||||
setError({ ...error, desc: false });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForm() {
|
function checkForm() {
|
||||||
if (
|
const hasError = Object.values(error).some(v => v)
|
||||||
Object.values(error).some((v) => v == true) ||
|
const hasEmpty = Object.values(dataForm).some(v => v === "")
|
||||||
Object.values(dataForm).some((v) => v == "")
|
setDisableBtn(hasError || hasEmpty);
|
||||||
) {
|
}
|
||||||
setDisableBtn(true);
|
|
||||||
|
useEffect(() => { checkForm() }, [error, dataForm]);
|
||||||
|
useEffect(() => { dispatch(setMemberChoose([])) }, [])
|
||||||
|
|
||||||
|
function handleOpenMemberPicker() {
|
||||||
|
if (entityUser.role === "supadmin" || entityUser.role === "developer") {
|
||||||
|
if (chooseGroup.val !== "") {
|
||||||
|
setMemberModal(true);
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: 'small', text1: 'Pilih Lembaga Desa terlebih dahulu' })
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setDisableBtn(false);
|
validationForm('group', userLogin.idGroup, userLogin.group);
|
||||||
|
setMemberModal(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
checkForm();
|
|
||||||
}, [error, dataForm]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(setMemberChoose([]))
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
function handleBack() {
|
|
||||||
dispatch(setMemberChoose([]))
|
|
||||||
router.back()
|
|
||||||
}
|
|
||||||
|
|
||||||
const pickDocumentAsync = async () => {
|
const pickDocumentAsync = async () => {
|
||||||
let result = await DocumentPicker.getDocumentAsync({
|
const result = await DocumentPicker.getDocumentAsync({ type: ["*/*"], multiple: true });
|
||||||
type: ["*/*"],
|
|
||||||
multiple: true
|
|
||||||
});
|
|
||||||
if (!result.canceled) {
|
if (!result.canceled) {
|
||||||
for (let i = 0; i < result.assets?.length; i++) {
|
let skipped = 0
|
||||||
if (result.assets[i].uri) {
|
for (const asset of result.assets) {
|
||||||
setFileForm((prev) => [...prev, result.assets[i]])
|
if (!asset.uri) continue
|
||||||
|
if (fileForm.some(f => f.name === asset.name)) {
|
||||||
|
skipped++
|
||||||
|
} else {
|
||||||
|
setFileForm(prev => [...prev, asset])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (skipped > 0) Toast.show({ type: 'small', text1: 'Beberapa file sudah ditambahkan' })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function deleteFile(index: number) {
|
function deleteFile(index: number) {
|
||||||
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
setFileForm(fileForm.filter((_, i) => i !== index))
|
||||||
setModalFile(false)
|
setModalFile(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,75 +127,43 @@ export default function CreateDiscussionGeneral() {
|
|||||||
setLoading(true)
|
setLoading(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const fd = new FormData()
|
const fd = new FormData()
|
||||||
|
|
||||||
for (let i = 0; i < fileForm.length; i++) {
|
for (let i = 0; i < fileForm.length; i++) {
|
||||||
fd.append(`file${i}`, {
|
fd.append(`file${i}`, { uri: fileForm[i].uri, type: 'application/octet-stream', name: fileForm[i].name } as any);
|
||||||
uri: fileForm[i].uri,
|
|
||||||
type: 'application/octet-stream',
|
|
||||||
name: fileForm[i].name,
|
|
||||||
} as any);
|
|
||||||
}
|
}
|
||||||
|
fd.append("data", JSON.stringify({ ...dataForm, user: hasil, member: entitiesMember }))
|
||||||
fd.append("data", JSON.stringify(
|
|
||||||
{ ...dataForm, user: hasil, member: entitiesMember }
|
|
||||||
))
|
|
||||||
|
|
||||||
const response = await apiCreateDiscussionGeneral(fd)
|
const response = await apiCreateDiscussionGeneral(fd)
|
||||||
|
|
||||||
// const response = await apiCreateDiscussionGeneral({
|
|
||||||
// data: { ...dataForm, user: hasil, member: entitiesMember },
|
|
||||||
// })
|
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
dispatch(setMemberChoose([]))
|
dispatch(setMemberChoose([]))
|
||||||
dispatch(setUpdateDiscussionGeneralDetail(!update))
|
dispatch(setUpdateDiscussionGeneralDetail(!update))
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data' })
|
||||||
router.back()
|
router.back()
|
||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal menambahkan data" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
|
||||||
// <ButtonBackHeader
|
|
||||||
// onPress={() => { handleBack() }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
headerTitle: "Tambah Diskusi",
|
|
||||||
headerTitleAlign: "center",
|
|
||||||
// headerRight: () => (
|
|
||||||
// <ButtonSaveHeader
|
|
||||||
// category="create"
|
|
||||||
// disable={disableBtn || loading ? true : false}
|
|
||||||
// onPress={() => {
|
|
||||||
// entitiesMember.length == 0
|
|
||||||
// ? Toast.show({ type: 'small', text1: 'Anda belum memilih anggota', })
|
|
||||||
// : handleCreate()
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Tambah Diskusi"
|
title="Tambah Diskusi"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => { dispatch(setMemberChoose([])); router.back() }}
|
||||||
right={
|
right={
|
||||||
<ButtonSaveHeader
|
<ButtonSaveHeader
|
||||||
category="create"
|
category="create"
|
||||||
disable={disableBtn || loading ? true : false}
|
disable={disableBtn || entitiesMember.length === 0 || loading}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
entitiesMember.length == 0
|
entitiesMember.length === 0
|
||||||
? Toast.show({ type: 'small', text1: 'Anda belum memilih anggota', })
|
? Toast.show({ type: 'small', text1: 'Anda belum memilih anggota' })
|
||||||
: handleCreate()
|
: handleCreate()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -204,132 +172,157 @@ export default function CreateDiscussionGeneral() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<LoadingOverlay visible={loading} />
|
{loading && <LoadingCenter />}
|
||||||
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
{
|
|
||||||
(entityUser.role == "supadmin" ||
|
{(entityUser.role === "supadmin" || entityUser.role === "developer") && (
|
||||||
entityUser.role == "developer") && (
|
<SelectForm
|
||||||
<SelectForm
|
label="Lembaga Desa"
|
||||||
label="Lembaga Desa"
|
placeholder="Pilih Lembaga Desa"
|
||||||
placeholder="Pilih Lembaga Desa"
|
value={chooseGroup.label}
|
||||||
value={chooseGroup.label}
|
required
|
||||||
required
|
bg={colors.card}
|
||||||
onPress={() => {
|
onPress={() => { setValChoose(chooseGroup.val); setSelect(true) }}
|
||||||
setValChoose(chooseGroup.val);
|
error={error.group}
|
||||||
setValSelect("group");
|
errorText="Lembaga Desa tidak boleh kosong"
|
||||||
setSelect(true);
|
/>
|
||||||
}}
|
)}
|
||||||
error={error.group}
|
|
||||||
errorText="Lembaga Desa tidak boleh kosong"
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul"
|
label="Judul"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul"
|
placeholder="Judul"
|
||||||
required
|
required
|
||||||
error={error.title}
|
error={error.title}
|
||||||
|
bg={colors.card}
|
||||||
errorText="Judul tidak boleh kosong"
|
errorText="Judul tidak boleh kosong"
|
||||||
onChange={(val) => { validationForm("title", val) }}
|
onChange={(val) => validationForm("title", val)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Diskusi"
|
label="Diskusi"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Hal yang didiskusikan"
|
placeholder="Hal yang didiskusikan"
|
||||||
required
|
required
|
||||||
error={error.desc}
|
error={error.desc}
|
||||||
|
bg={colors.card}
|
||||||
errorText="Diskusi tidak boleh kosong"
|
errorText="Diskusi tidak boleh kosong"
|
||||||
onChange={(val) => { validationForm("desc", val) }}
|
onChange={(val) => validationForm("desc", val)}
|
||||||
multiline
|
multiline
|
||||||
/>
|
/>
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
|
||||||
{
|
|
||||||
fileForm.length > 0
|
|
||||||
&&
|
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10]}>
|
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
|
|
||||||
{
|
|
||||||
fileForm.map((item, index) => (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={index}
|
|
||||||
borderType={fileForm.length > 1 ? "bottom" : "none"}
|
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
|
||||||
title={item.name}
|
|
||||||
titleWeight="normal"
|
|
||||||
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
<ButtonSelect
|
|
||||||
value="Pilih Anggota"
|
|
||||||
onPress={() => {
|
|
||||||
if (entityUser.role == "supadmin" || entityUser.role == "developer") {
|
|
||||||
if (chooseGroup.val != "") {
|
|
||||||
setSelect(true);
|
|
||||||
setValSelect("member");
|
|
||||||
} else {
|
|
||||||
Toast.show({ type: 'small', text1: 'Pilih Lembaga Desa terlebih dahulu', })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
validationForm('group', userLogin.idGroup, userLogin.group);
|
|
||||||
setValChoose(userLogin.idGroup)
|
|
||||||
setSelect(true);
|
|
||||||
setValSelect("member");
|
|
||||||
}
|
|
||||||
|
|
||||||
}}
|
{/* File */}
|
||||||
/>
|
<View style={[Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
{
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
entitiesMember.length > 0 &&
|
<Pressable
|
||||||
<View>
|
onPress={pickDocumentAsync}
|
||||||
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
|
style={[Styles.sectionActionRow, { marginBottom: fileForm.length > 0 ? 12 : 0 }]}
|
||||||
<Text>Anggota</Text>
|
>
|
||||||
<Text>Total {entitiesMember.length} Anggota</Text>
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '15' }]}>
|
||||||
|
<MaterialCommunityIcons name="paperclip" size={18} color={colors.dimmed} />
|
||||||
</View>
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>File</Text>
|
||||||
|
{fileForm.length === 0 && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Opsional — ketuk untuk upload</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{fileForm.length > 0 && (
|
||||||
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{fileForm.length} file</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{fileForm.length > 0 && (
|
||||||
|
<View style={Styles.fileGrid}>
|
||||||
|
{fileForm.map((item, index) => {
|
||||||
|
const ext = item.name.split('.').pop()?.toLowerCase() ?? ''
|
||||||
|
const baseName = item.name.includes('.') ? item.name.split('.').slice(0, -1).join('.') : item.name
|
||||||
|
const iconName = getFileIcon(ext)
|
||||||
|
const iconColor = getFileColor(ext)
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={index}
|
||||||
|
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
|
||||||
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={Styles.textDefault} numberOfLines={1}>{baseName}</Text>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10]}>
|
{/* Anggota */}
|
||||||
{
|
<View style={[Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
entitiesMember.map((item: { img: any; name: any; }, index: any) => {
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
return (
|
<Pressable
|
||||||
<BorderBottomItem
|
onPress={handleOpenMemberPicker}
|
||||||
key={index}
|
style={[Styles.sectionActionRow, { marginBottom: entitiesMember.length > 0 ? 12 : 0 }]}
|
||||||
borderType="bottom"
|
>
|
||||||
icon={
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="sm" />
|
<MaterialIcons name="people" size={18} color={colors.tabActive} />
|
||||||
}
|
|
||||||
title={item.name}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
<View style={Styles.flex1}>
|
||||||
}
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Anggota</Text>
|
||||||
|
{entitiesMember.length === 0 && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Belum ada anggota dipilih</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{entitiesMember.length > 0 && (
|
||||||
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.tabActive }]}>{entitiesMember.length} anggota</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{entitiesMember.length > 0 && (
|
||||||
|
<View style={{ gap: 6 }}>
|
||||||
|
{entitiesMember.map((item: any, index: number) => (
|
||||||
|
<View key={index} style={[Styles.listItemCard, { borderColor: colors.icon + '18' }]}>
|
||||||
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
|
||||||
|
<Text style={[Styles.textDefault, Styles.flex1, { color: colors.text }]} numberOfLines={1}>
|
||||||
|
{item.name}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<ModalSelect
|
<ModalSelect
|
||||||
category={valSelect}
|
category="group"
|
||||||
close={setSelect}
|
close={setSelect}
|
||||||
onSelect={(value) => {
|
onSelect={(value) => validationForm("group", value.val, value.label)}
|
||||||
validationForm(valSelect, value.val, value.label);
|
title="Lembaga Desa"
|
||||||
}}
|
|
||||||
title={valSelect == "group" ? "Lembaga Desa" : "Pilih Anggota"}
|
|
||||||
open={isSelect}
|
open={isSelect}
|
||||||
idParent={valSelect == "member" ? chooseGroup.val : ""}
|
idParent=""
|
||||||
valChoose={valChoose}
|
valChoose={valChoose}
|
||||||
/>
|
/>
|
||||||
|
<ModalSelectMemberByDivision
|
||||||
|
open={isMemberModal}
|
||||||
|
close={setMemberModal}
|
||||||
|
idGroup={chooseGroup.val || userLogin.idGroup}
|
||||||
|
/>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile) }}
|
onPress={() => deleteFile(indexDelFile)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|||||||
@@ -1,26 +1,46 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import Text from "@/components/Text";
|
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import ButtonSelect from "@/components/buttonSelect";
|
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import LoadingOverlay from "@/components/loadingOverlay";
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
|
import Text from "@/components/Text";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiEditDiscussionGeneral, apiGetDiscussionGeneralOne } from "@/lib/api";
|
import { apiEditDiscussionGeneral, apiGetDiscussionGeneralOne } from "@/lib/api";
|
||||||
import { setUpdateDiscussionGeneralDetail } from "@/lib/discussionGeneralDetail";
|
import { setUpdateDiscussionGeneralDetail } from "@/lib/discussionGeneralDetail";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
import * as DocumentPicker from "expo-document-picker";
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { Pressable, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
|
function getFileIcon(ext: string): keyof typeof MaterialCommunityIcons.glyphMap {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return 'image-outline'
|
||||||
|
if (ext === 'pdf') return 'file-pdf-box'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return 'video-outline'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return 'file-word-outline'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return 'file-excel-outline'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return 'zip-box-outline'
|
||||||
|
return 'file-outline'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileColor(ext: string): string {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return '#339AF0'
|
||||||
|
if (ext === 'pdf') return '#F03E3E'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return '#AE3EC9'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return '#1C7ED6'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return '#2F9E44'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return '#E8590C'
|
||||||
|
return '#868E96'
|
||||||
|
}
|
||||||
|
|
||||||
export default function EditDiscussionGeneral() {
|
export default function EditDiscussionGeneral() {
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const [disableBtn, setDisableBtn] = useState(false)
|
const [disableBtn, setDisableBtn] = useState(false)
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
@@ -30,157 +50,100 @@ export default function EditDiscussionGeneral() {
|
|||||||
const [indexDelFile, setIndexDelFile] = useState<{ id: string | number; cat: "newFile" | "oldFile" }>({ id: "", cat: "newFile" })
|
const [indexDelFile, setIndexDelFile] = useState<{ id: string | number; cat: "newFile" | "oldFile" }>({ id: "", cat: "newFile" })
|
||||||
const [dataFile, setDataFile] = useState<{ id: string; idStorage: string; name: string; extension: string; delete?: boolean }[]>([])
|
const [dataFile, setDataFile] = useState<{ id: string; idStorage: string; name: string; extension: string; delete?: boolean }[]>([])
|
||||||
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
||||||
const [dataForm, setDataForm] = useState({
|
const [dataForm, setDataForm] = useState({ title: "", desc: "" });
|
||||||
title: "",
|
const [error, setError] = useState({ title: false, desc: false })
|
||||||
desc: "",
|
|
||||||
});
|
const visibleOldFiles = dataFile.filter(v => !v.delete)
|
||||||
const [error, setError] = useState({
|
const totalFiles = fileForm.length + visibleOldFiles.length
|
||||||
title: false,
|
|
||||||
desc: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
async function handleLoad() {
|
async function handleLoad() {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiGetDiscussionGeneralOne({
|
const response = await apiGetDiscussionGeneralOne({ id, user: hasil, cat: "detail" });
|
||||||
id: id,
|
const responseFile = await apiGetDiscussionGeneralOne({ id, user: hasil, cat: "file" });
|
||||||
user: hasil,
|
if (response.success) setDataForm(response.data);
|
||||||
cat: "detail",
|
if (responseFile.success) setDataFile(responseFile.data);
|
||||||
});
|
|
||||||
const responseFile = await apiGetDiscussionGeneralOne({
|
|
||||||
id: id,
|
|
||||||
user: hasil,
|
|
||||||
cat: "file",
|
|
||||||
});
|
|
||||||
if (response.success) {
|
|
||||||
setDataForm(response.data);
|
|
||||||
}
|
|
||||||
if (responseFile.success) {
|
|
||||||
setDataFile(responseFile.data);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => { handleLoad() }, []);
|
||||||
useEffect(() => {
|
|
||||||
handleLoad();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
function validationForm(cat: string, val: any) {
|
function validationForm(cat: string, val: any) {
|
||||||
if (cat == "title") {
|
if (cat === "title") {
|
||||||
setDataForm({ ...dataForm, title: val });
|
setDataForm({ ...dataForm, title: val });
|
||||||
if (val == "" || val == "null") {
|
setError({ ...error, title: val === "" || val === "null" });
|
||||||
setError({ ...error, title: true });
|
} else if (cat === "desc") {
|
||||||
} else {
|
|
||||||
setError({ ...error, title: false });
|
|
||||||
}
|
|
||||||
} else if (cat == "desc") {
|
|
||||||
setDataForm({ ...dataForm, desc: val });
|
setDataForm({ ...dataForm, desc: val });
|
||||||
if (val == "" || val == "null") {
|
setError({ ...error, desc: val === "" || val === "null" });
|
||||||
setError({ ...error, desc: true });
|
|
||||||
} else {
|
|
||||||
setError({ ...error, desc: false });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForm() {
|
function checkForm() {
|
||||||
if (Object.values(error).some((v) => v == true) == true || Object.values(dataForm).some((v) => v == "") == true) {
|
const hasError = Object.values(error).some(v => v)
|
||||||
setDisableBtn(true)
|
const hasEmpty = Object.values(dataForm).some(v => v === "")
|
||||||
} else {
|
setDisableBtn(hasError || hasEmpty);
|
||||||
setDisableBtn(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { checkForm() }, [error, dataForm])
|
||||||
checkForm()
|
|
||||||
}, [error, dataForm])
|
|
||||||
|
|
||||||
const pickDocumentAsync = async () => {
|
const pickDocumentAsync = async () => {
|
||||||
let result = await DocumentPicker.getDocumentAsync({
|
const result = await DocumentPicker.getDocumentAsync({ type: ["*/*"], multiple: true });
|
||||||
type: ["*/*"],
|
|
||||||
multiple: true
|
|
||||||
});
|
|
||||||
if (!result.canceled) {
|
if (!result.canceled) {
|
||||||
for (let i = 0; i < result.assets?.length; i++) {
|
let skipped = 0
|
||||||
if (result.assets[i].uri) {
|
for (const asset of result.assets) {
|
||||||
setFileForm((prev) => [...prev, result.assets[i]])
|
if (!asset.uri) continue
|
||||||
|
const isDup = fileForm.some(f => f.name === asset.name) ||
|
||||||
|
visibleOldFiles.some(f => `${f.name}.${f.extension}` === asset.name)
|
||||||
|
if (isDup) {
|
||||||
|
skipped++
|
||||||
|
} else {
|
||||||
|
setFileForm(prev => [...prev, asset])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (skipped > 0) Toast.show({ type: 'small', text1: 'Beberapa file sudah ditambahkan' })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function deleteFile(index: number | string, cat: "newFile" | "oldFile" | null) {
|
function deleteFile(index: number | string, cat: "newFile" | "oldFile" | null) {
|
||||||
if (cat == "newFile") {
|
if (cat === "newFile") {
|
||||||
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
setFileForm(fileForm.filter((_, i) => i !== index))
|
||||||
} else {
|
} else {
|
||||||
setDataFile(prev =>
|
setDataFile(prev => prev.map(item => item.id === index ? { ...item, delete: true } : item))
|
||||||
prev.map(item =>
|
|
||||||
item.id === index
|
|
||||||
? { ...item, delete: true }
|
|
||||||
: item
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
setModalFile(false)
|
setModalFile(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function handleEdit() {
|
async function handleEdit() {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const fd = new FormData()
|
const fd = new FormData()
|
||||||
for (let i = 0; i < fileForm.length; i++) {
|
for (let i = 0; i < fileForm.length; i++) {
|
||||||
fd.append(`file${i}`, {
|
fd.append(`file${i}`, { uri: fileForm[i].uri, type: 'application/octet-stream', name: fileForm[i].name } as any);
|
||||||
uri: fileForm[i].uri,
|
|
||||||
type: 'application/octet-stream',
|
|
||||||
name: fileForm[i].name,
|
|
||||||
} as any);
|
|
||||||
}
|
}
|
||||||
|
fd.append("data", JSON.stringify({ user: hasil, title: dataForm.title, desc: dataForm.desc, oldFile: dataFile }))
|
||||||
fd.append("data", JSON.stringify(
|
|
||||||
{
|
|
||||||
user: hasil, title: dataForm.title, desc: dataForm.desc, oldFile: dataFile
|
|
||||||
}
|
|
||||||
))
|
|
||||||
|
|
||||||
const response = await apiEditDiscussionGeneral(fd, id);
|
const response = await apiEditDiscussionGeneral(fd, id);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
dispatch(setUpdateDiscussionGeneralDetail(!update))
|
dispatch(setUpdateDiscussionGeneralDetail(!update))
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil mengubah data', })
|
Toast.show({ type: 'small', text1: 'Berhasil mengubah data' })
|
||||||
router.back();
|
router.back();
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: 'small', text1: 'Gagal mengubah data' })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal mengubah data" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
|
||||||
// <ButtonBackHeader
|
|
||||||
// onPress={() => {
|
|
||||||
// router.back();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
headerTitle: "Edit Diskusi",
|
|
||||||
headerTitleAlign: "center",
|
|
||||||
// headerRight: () => (
|
|
||||||
// <ButtonSaveHeader
|
|
||||||
// disable={disableBtn || loading ? true : false}
|
|
||||||
// category="update"
|
|
||||||
// onPress={() => { handleEdit() }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Edit Diskusi"
|
title="Edit Diskusi"
|
||||||
@@ -188,80 +151,123 @@ export default function EditDiscussionGeneral() {
|
|||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={
|
right={
|
||||||
<ButtonSaveHeader
|
<ButtonSaveHeader
|
||||||
disable={disableBtn || loading ? true : false}
|
disable={disableBtn || loading}
|
||||||
category="update"
|
category="update"
|
||||||
onPress={() => { handleEdit() }}
|
onPress={() => handleEdit()}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<LoadingOverlay visible={loading} />
|
{loading && <LoadingCenter />}
|
||||||
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15]}>
|
<View style={Styles.p15}>
|
||||||
|
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul"
|
label="Judul"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul"
|
placeholder="Judul"
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
value={dataForm.title}
|
value={dataForm.title}
|
||||||
errorText="Judul tidak boleh kosong"
|
errorText="Judul tidak boleh kosong"
|
||||||
onChange={(val) => validationForm("title", val)}
|
onChange={(val) => validationForm("title", val)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Diskusi"
|
label="Diskusi"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Hal yang didiskusikan"
|
placeholder="Hal yang didiskusikan"
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
error={error.desc}
|
error={error.desc}
|
||||||
value={dataForm.desc}
|
value={dataForm.desc}
|
||||||
errorText="Diskusi tidak boleh kosong"
|
errorText="Diskusi tidak boleh kosong"
|
||||||
onChange={(val) => validationForm("desc", val)}
|
onChange={(val) => validationForm("desc", val)}
|
||||||
multiline
|
multiline
|
||||||
/>
|
/>
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
|
||||||
{
|
{/* File */}
|
||||||
(fileForm.length > 0 || dataFile.filter((val) => !val.delete).length > 0)
|
<View style={[Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
&&
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10]}>
|
<Pressable
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
|
onPress={pickDocumentAsync}
|
||||||
{
|
style={[Styles.sectionActionRow, { marginBottom: totalFiles > 0 ? 12 : 0 }]}
|
||||||
dataFile.filter((val) => !val.delete).map((item, index) => (
|
>
|
||||||
<BorderBottomItem
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '15' }]}>
|
||||||
key={index}
|
<MaterialCommunityIcons name="paperclip" size={18} color={colors.dimmed} />
|
||||||
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
|
</View>
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
<View style={Styles.flex1}>
|
||||||
title={item.name + '.' + item.extension}
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>File</Text>
|
||||||
titleWeight="normal"
|
{totalFiles === 0 && (
|
||||||
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Opsional — ketuk untuk upload</Text>
|
||||||
/>
|
)}
|
||||||
))
|
</View>
|
||||||
}
|
{totalFiles > 0 && (
|
||||||
{
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
fileForm.map((item, index) => (
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{totalFiles} file</Text>
|
||||||
<BorderBottomItem
|
</View>
|
||||||
key={index}
|
)}
|
||||||
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
</Pressable>
|
||||||
title={item.name}
|
{totalFiles > 0 && (
|
||||||
titleWeight="normal"
|
<View style={Styles.fileGrid}>
|
||||||
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
|
{visibleOldFiles.map((item, index) => {
|
||||||
/>
|
const ext = item.extension.toLowerCase()
|
||||||
))
|
const iconName = getFileIcon(ext)
|
||||||
}
|
const iconColor = getFileColor(ext)
|
||||||
</View>
|
return (
|
||||||
}
|
<Pressable
|
||||||
|
key={`old-${index}`}
|
||||||
|
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
|
||||||
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={Styles.textDefault} numberOfLines={1}>{item.name}</Text>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
{fileForm.map((item, index) => {
|
||||||
|
const ext = item.name.split('.').pop()?.toLowerCase() ?? ''
|
||||||
|
const baseName = item.name.includes('.') ? item.name.split('.').slice(0, -1).join('.') : item.name
|
||||||
|
const iconName = getFileIcon(ext)
|
||||||
|
const iconColor = getFileColor(ext)
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={`new-${index}`}
|
||||||
|
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
|
||||||
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={Styles.textDefault} numberOfLines={1}>{baseName}</Text>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile.id, indexDelFile.cat) }}
|
onPress={() => deleteFile(indexDelFile.id, indexDelFile.cat)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|||||||
@@ -1,20 +1,23 @@
|
|||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
import ButtonTab from "@/components/buttonTab";
|
import ButtonTab from "@/components/buttonTab";
|
||||||
import InputSearch from "@/components/inputSearch";
|
import InputSearch from "@/components/inputSearch";
|
||||||
import LabelStatus from "@/components/labelStatus";
|
import LabelStatus from "@/components/labelStatus";
|
||||||
import SkeletonContent from "@/components/skeletonContent";
|
import SkeletonContent from "@/components/skeletonContent";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
import WrapTab from "@/components/wrapTab";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetDiscussionGeneral } from "@/lib/api";
|
import { apiGetDiscussionGeneral } from "@/lib/api";
|
||||||
|
import { GUIDE_DISCUSSION } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { AntDesign, Feather, Ionicons, MaterialIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { AntDesign, Feather } from "@expo/vector-icons";
|
||||||
|
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { router, useLocalSearchParams } from "expo-router";
|
import { router, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { RefreshControl, View, VirtualizedList } from "react-native";
|
import { FlatList, Pressable, RefreshControl, View } from "react-native";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: string
|
id: string
|
||||||
title: string
|
title: string
|
||||||
@@ -27,164 +30,196 @@ type Props = {
|
|||||||
export default function Discussion() {
|
export default function Discussion() {
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const { active, group } = useLocalSearchParams<{ active?: string, group?: string }>()
|
const { active, group } = useLocalSearchParams<{ active?: string, group?: string }>()
|
||||||
const [search, setSearch] = useState('')
|
const [search, setSearch] = useState('')
|
||||||
const [nameGroup, setNameGroup] = useState('')
|
|
||||||
const [data, setData] = useState<Props[]>([])
|
|
||||||
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
||||||
const [loading, setLoading] = useState(true)
|
const queryClient = useQueryClient()
|
||||||
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
const [status, setStatus] = useState<'true' | 'false'>(active == 'false' ? 'false' : 'true')
|
||||||
const [status, setStatus] = useState<'true' | 'false'>('true')
|
|
||||||
const [page, setPage] = useState(1)
|
|
||||||
const [waiting, setWaiting] = useState(false)
|
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('discussion')
|
||||||
|
|
||||||
async function handleLoad(loading: boolean, thisPage: number) {
|
const {
|
||||||
try {
|
data,
|
||||||
setWaiting(true)
|
fetchNextPage,
|
||||||
setLoading(loading)
|
hasNextPage,
|
||||||
setPage(thisPage)
|
isFetchingNextPage,
|
||||||
|
isLoading,
|
||||||
|
refetch
|
||||||
|
} = useInfiniteQuery({
|
||||||
|
queryKey: ['discussions', { status, search, group }],
|
||||||
|
queryFn: async ({ pageParam = 1 }) => {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiGetDiscussionGeneral({ user: hasil, active: status, search: search, group: String(group), page: thisPage })
|
const response = await apiGetDiscussionGeneral({
|
||||||
if (thisPage == 1) {
|
user: hasil,
|
||||||
setData(response.data)
|
active: status,
|
||||||
} else if (thisPage > 1 && response.data.length > 0) {
|
search: search,
|
||||||
setData([...data, ...response.data])
|
group: String(group),
|
||||||
} else {
|
page: pageParam
|
||||||
return;
|
})
|
||||||
}
|
return response;
|
||||||
setNameGroup(response.filter.name)
|
},
|
||||||
} catch (error) {
|
initialPageParam: 1,
|
||||||
console.error(error)
|
getNextPageParam: (lastPage, allPages) => {
|
||||||
} finally {
|
return lastPage.data.length > 0 ? allPages.length + 1 : undefined;
|
||||||
setLoading(false)
|
},
|
||||||
setWaiting(false)
|
enabled: !!token?.current,
|
||||||
}
|
staleTime: 0,
|
||||||
}
|
})
|
||||||
|
|
||||||
|
const flatData = useMemo(() => {
|
||||||
|
return data?.pages.flatMap(page => page.data) || [];
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
const nameGroup = useMemo(() => {
|
||||||
|
return data?.pages[0]?.filter?.name || "";
|
||||||
|
}, [data])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLoad(false, 1)
|
refetch()
|
||||||
}, [update])
|
}, [update, refetch])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(true, 1)
|
|
||||||
}, [status, search, group])
|
|
||||||
|
|
||||||
|
|
||||||
const loadMoreData = () => {
|
|
||||||
if (waiting) return
|
|
||||||
setTimeout(() => {
|
|
||||||
handleLoad(false, page + 1)
|
|
||||||
}, 1000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleLoad(false, 1)
|
await queryClient.invalidateQueries({ queryKey: ['discussions'] })
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
const getItem = (_data: unknown, index: number): Props => ({
|
const isOpen = (item: Props) => item.status === 1
|
||||||
id: data[index].id,
|
|
||||||
title: data[index].title,
|
const themed = {
|
||||||
desc: data[index].desc,
|
background: { backgroundColor: colors.background },
|
||||||
status: data[index].status,
|
card: { backgroundColor: colors.card, borderColor: colors.icon + '20' },
|
||||||
total_komentar: data[index].total_komentar,
|
cardPressed: { backgroundColor: colors.icon + '10' },
|
||||||
createdAt: data[index].createdAt,
|
iconCircle: { backgroundColor: colors.icon + '20' },
|
||||||
})
|
title: { color: colors.text },
|
||||||
|
dimmed: { color: colors.dimmed },
|
||||||
|
statusOpen: { borderColor: '#10B981' as const },
|
||||||
|
statusClosed: { borderColor: colors.dimmed + '80' },
|
||||||
|
statusTextOpen: { color: '#10B981' as const },
|
||||||
|
statusTextClosed: { color: colors.dimmed },
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.flex1, themed.background]}>
|
||||||
<View>
|
<GuideOverlay visible={guideVisible} steps={GUIDE_DISCUSSION} onDismiss={dismissGuide} />
|
||||||
{
|
{/* Header controls */}
|
||||||
entityUser.role != "user" && entityUser.role != "coadmin" &&
|
<View style={[Styles.ph15, Styles.discussionHeaderPadding]}>
|
||||||
<View style={[Styles.wrapBtnTab]}>
|
{entityUser.role != "user" && entityUser.role != "coadmin" && (
|
||||||
|
<WrapTab>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="true"
|
value="true"
|
||||||
onPress={() => { setStatus("true") }}
|
onPress={() => setStatus("true")}
|
||||||
label="Aktif"
|
label="Aktif"
|
||||||
icon={<Feather name="check-circle" color={status == "false" ? 'black' : 'white'} size={20} />}
|
icon={<Feather name="check-circle" color={status == "false" ? colors.dimmed : 'white'} size={20} />}
|
||||||
n={2} />
|
n={2}
|
||||||
|
/>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="false"
|
value="false"
|
||||||
onPress={() => { setStatus("false") }}
|
onPress={() => setStatus("false")}
|
||||||
label="Arsip"
|
label="Arsip"
|
||||||
icon={<AntDesign name="closecircleo" color={status == "true" ? 'black' : 'white'} size={20} />}
|
icon={<AntDesign name="closecircleo" color={status == "true" ? colors.dimmed : 'white'} size={20} />}
|
||||||
n={2} />
|
n={2}
|
||||||
</View>
|
/>
|
||||||
}
|
</WrapTab>
|
||||||
|
)}
|
||||||
<InputSearch onChange={setSearch} />
|
<InputSearch onChange={setSearch} />
|
||||||
{
|
{(entityUser.role == "supadmin" || entityUser.role == "developer") && (
|
||||||
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
<View style={[Styles.mt10, Styles.rowOnly]}>
|
||||||
<View style={[Styles.mv05, Styles.rowOnly]}>
|
|
||||||
<Text>Filter :</Text>
|
<Text>Filter :</Text>
|
||||||
<LabelStatus size="small" category="secondary" text={nameGroup} style={[Styles.mh05]} />
|
<LabelStatus size="small" category="secondary" text={nameGroup} style={[Styles.mh05]} />
|
||||||
</View>
|
</View>
|
||||||
}
|
)}
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ flex: 2 }, Styles.mt05]}>
|
|
||||||
{
|
|
||||||
loading ?
|
|
||||||
arrSkeleton.map((item: any, i: number) => {
|
|
||||||
return (
|
|
||||||
<SkeletonContent key={i} />
|
|
||||||
)
|
|
||||||
})
|
|
||||||
:
|
|
||||||
data.length > 0
|
|
||||||
?
|
|
||||||
<VirtualizedList
|
|
||||||
data={data}
|
|
||||||
getItemCount={() => data.length}
|
|
||||||
getItem={getItem}
|
|
||||||
renderItem={({ item, index }: { item: Props, index: number }) => {
|
|
||||||
return (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={index}
|
|
||||||
onPress={() => { router.push(`/discussion/${item.id}`) }}
|
|
||||||
borderType="bottom"
|
|
||||||
icon={
|
|
||||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
|
||||||
<MaterialIcons name="chat" size={25} color={'#384288'} />
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
title={item.title}
|
|
||||||
subtitle={
|
|
||||||
status != "false" && <LabelStatus category={item.status === 1 ? "success" : "error"} text={item.status === 1 ? "BUKA" : "TUTUP"} size="small" />
|
|
||||||
}
|
|
||||||
rightTopInfo={item.createdAt}
|
|
||||||
desc={item.desc.replace(/<[^>]*>?/gm, ' ').replace(/\r?\n|\r/g, ' ')}
|
|
||||||
leftBottomInfo={
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>Diskusikan</Text>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
rightBottomInfo={`${item.total_komentar} Komentar`}
|
|
||||||
|
|
||||||
/>
|
{/* List */}
|
||||||
)
|
<View style={[Styles.flex1, Styles.ph15, Styles.discussionListPadding]}>
|
||||||
}}
|
{isLoading ? (
|
||||||
keyExtractor={(item, index) => String(index)}
|
[0, 1, 2, 3, 4].map((_, i) => <SkeletonContent key={i} />)
|
||||||
onEndReached={loadMoreData}
|
) : flatData.length === 0 ? (
|
||||||
onEndReachedThreshold={0.5}
|
<View style={[Styles.contentItemCenter, Styles.mt30]}>
|
||||||
showsVerticalScrollIndicator={false}
|
<Feather name="message-circle" size={42} color={colors.icon + '40'} />
|
||||||
refreshControl={
|
<Text style={[Styles.mt10, Styles.discussionEmptyText, themed.dimmed]}>
|
||||||
<RefreshControl
|
Tidak ada diskusi
|
||||||
refreshing={refreshing}
|
</Text>
|
||||||
onRefresh={handleRefresh}
|
</View>
|
||||||
/>
|
) : (
|
||||||
}
|
<FlatList
|
||||||
|
data={flatData}
|
||||||
|
keyExtractor={(_, i) => String(i)}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
onEndReached={() => {
|
||||||
|
if (hasNextPage && !isFetchingNextPage) fetchNextPage()
|
||||||
|
}}
|
||||||
|
onEndReachedThreshold={0.5}
|
||||||
|
refreshControl={
|
||||||
|
<RefreshControl
|
||||||
|
refreshing={refreshing}
|
||||||
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
:
|
}
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
|
ItemSeparatorComponent={() => <View style={Styles.discussionSeparator} />}
|
||||||
}
|
renderItem={({ item }: { item: Props }) => (
|
||||||
|
<Pressable
|
||||||
|
onPress={() => router.push(`/discussion/${item.id}`)}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
Styles.discussionCard,
|
||||||
|
themed.card,
|
||||||
|
pressed && themed.cardPressed,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{/* Top row: icon + title + status badge */}
|
||||||
|
<View style={[Styles.rowItemsCenter, Styles.mb08]}>
|
||||||
|
{/* Discussion icon */}
|
||||||
|
<View style={[Styles.discussionIconCircle, themed.iconCircle]}>
|
||||||
|
<Feather name="message-circle" size={20} color={colors.icon} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* Title + status badge */}
|
||||||
|
<View style={[Styles.flex1, Styles.discussionTitleCol]}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, themed.title]} numberOfLines={1}>
|
||||||
|
{item.title}
|
||||||
|
</Text>
|
||||||
|
{status !== "false" && (
|
||||||
|
<View style={[Styles.discussionStatusPill, isOpen(item) ? themed.statusOpen : themed.statusClosed]}>
|
||||||
|
<Text style={[Styles.discussionStatusText, isOpen(item) ? themed.statusTextOpen : themed.statusTextClosed]}>
|
||||||
|
{isOpen(item) ? 'Buka' : 'Tutup'}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* Description */}
|
||||||
|
{item.desc ? (
|
||||||
|
<Text
|
||||||
|
style={[Styles.textMediumNormal, Styles.discussionCardIndent, Styles.discussionDescMargin, themed.title]}
|
||||||
|
numberOfLines={2}
|
||||||
|
>
|
||||||
|
{item.desc.replace(/<[^>]*>?/gm, ' ').replace(/\r?\n|\r/g, ' ')}
|
||||||
|
</Text>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{/* Bottom row: comment count + date */}
|
||||||
|
<View style={[Styles.rowItemsCenter, Styles.rowSpaceBetween, Styles.discussionCardIndent]}>
|
||||||
|
<View style={Styles.rowItemsCenter}>
|
||||||
|
<Feather name="message-square" size={14} color={colors.dimmed} />
|
||||||
|
<Text style={[Styles.discussionCommentText, themed.dimmed]}>
|
||||||
|
{item.total_komentar} Komentar
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.discussionDateText, themed.dimmed]}>
|
||||||
|
{item.createdAt}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi";
|
|
||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import ImageUser from "@/components/imageNew";
|
import ImageUser from "@/components/imageNew";
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
import Text from '@/components/Text';
|
import Text from '@/components/Text';
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
|
||||||
import { ConstEnv } from "@/constants/ConstEnv";
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiDeleteMemberDiscussionGeneral, apiGetDiscussionGeneralOne } from "@/lib/api";
|
import { apiDeleteMemberDiscussionGeneral, apiGetDiscussionGeneralOne } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { Feather, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { Pressable, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
@@ -24,8 +22,11 @@ type Props = {
|
|||||||
img: string
|
img: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SKELETON_COUNT = 5
|
||||||
|
|
||||||
export default function MemberDiscussionDetail() {
|
export default function MemberDiscussionDetail() {
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [data, setData] = useState<Props[]>([])
|
const [data, setData] = useState<Props[]>([])
|
||||||
@@ -33,11 +34,12 @@ export default function MemberDiscussionDetail() {
|
|||||||
const [chooseUser, setChooseUser] = useState({ idUser: '', name: '', img: '' })
|
const [chooseUser, setChooseUser] = useState({ idUser: '', name: '', img: '' })
|
||||||
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||||
|
const canManage = entityUser.role !== "user" && entityUser.role !== "coadmin"
|
||||||
|
|
||||||
async function handleLoad(loading: boolean) {
|
async function handleLoad(showLoadingIndicator: boolean) {
|
||||||
try {
|
try {
|
||||||
setLoading(loading)
|
setLoading(showLoadingIndicator)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiGetDiscussionGeneralOne({ id: id, user: hasil, cat: 'anggota' })
|
const response = await apiGetDiscussionGeneralOne({ id: id, user: hasil, cat: 'anggota' })
|
||||||
setData(response.data)
|
setData(response.data)
|
||||||
@@ -48,35 +50,27 @@ export default function MemberDiscussionDetail() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { handleLoad(false) }, [update]);
|
||||||
handleLoad(false)
|
useEffect(() => { handleLoad(true) }, []);
|
||||||
}, [update]);
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(true)
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
async function handleDeleteUser() {
|
async function handleDeleteUser() {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
await apiDeleteMemberDiscussionGeneral({ user: hasil, idUser: chooseUser.idUser }, id)
|
await apiDeleteMemberDiscussionGeneral({ user: hasil, idUser: chooseUser.idUser }, id)
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil mengeluarkan anggota dari diskusi', })
|
Toast.show({ type: 'small', text1: 'Berhasil mengeluarkan anggota dari diskusi' })
|
||||||
handleLoad(false)
|
handleLoad(false)
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal mengeluarkan anggota" })
|
||||||
} finally {
|
} finally {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Anggota Diskusi',
|
|
||||||
headerTitleAlign: 'center',
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Anggota Diskusi"
|
title="Anggota Diskusi"
|
||||||
@@ -86,83 +80,117 @@ export default function MemberDiscussionDetail() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView>
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<Text style={[Styles.textDefault, Styles.mv05]}>{data.length} Anggota</Text>
|
|
||||||
<View style={[Styles.wrapPaper, Styles.mb100]}>
|
{/* Tombol tambah anggota */}
|
||||||
{
|
{canManage && (
|
||||||
entityUser.role != "user" && entityUser.role != "coadmin" &&
|
<View style={[Styles.wrapPaper, Styles.sectionCard, Styles.mb15,
|
||||||
<BorderBottomItem
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
onPress={() => { router.push(`/discussion/add-member/${id}`) }}
|
<Pressable
|
||||||
borderType="none"
|
onPress={() => router.push(`/discussion/add-member/${id}`)}
|
||||||
icon={
|
style={Styles.sectionActionRow}
|
||||||
<View style={[Styles.iconContent, ColorsStatus.gray]}>
|
>
|
||||||
<Feather name="user-plus" size={25} color={'#384288'} />
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '18' }]}>
|
||||||
|
<MaterialCommunityIcons name="account-plus-outline" size={18} color={colors.icon} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Tambah Anggota</Text>
|
||||||
|
</View>
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Full list */}
|
||||||
|
<View style={[Styles.wrapPaper, Styles.sectionCard,
|
||||||
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18', padding: 0, overflow: 'hidden' }]}>
|
||||||
|
<View style={[Styles.sectionActionRow, { padding: 16, borderBottomWidth: 1, borderBottomColor: colors.icon + '14' }]}>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<MaterialIcons name="people" size={18} color={colors.dimmed} />
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, Styles.flex1, { color: colors.text }]}>Anggota</Text>
|
||||||
|
{!loading && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>{data.length} anggota</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{loading
|
||||||
|
? Array.from({ length: SKELETON_COUNT }).map((_, i) => (
|
||||||
|
<View
|
||||||
|
key={i}
|
||||||
|
style={[Styles.rowItemsCenter, Styles.ph15,
|
||||||
|
{ paddingVertical: 14, gap: 14, borderBottomWidth: i < SKELETON_COUNT - 1 ? 1 : 0, borderBottomColor: colors.icon + '14' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.userProfileExtraSmall, { backgroundColor: colors.icon + '20', borderRadius: 100 }]} />
|
||||||
|
<View style={{ height: 13, borderRadius: 6, flex: 1, backgroundColor: colors.icon + '20', maxWidth: 140 + (i % 3) * 30 }} />
|
||||||
|
</View>
|
||||||
|
))
|
||||||
|
: data.length === 0
|
||||||
|
? (
|
||||||
|
<View style={[Styles.contentItemCenter, { paddingVertical: 40 }]}>
|
||||||
|
<MaterialIcons name="people-outline" size={34} color={colors.icon + '50'} />
|
||||||
|
<Text style={[Styles.textMediumNormal, Styles.mt10, { color: colors.dimmed }]}>Belum ada anggota</Text>
|
||||||
</View>
|
</View>
|
||||||
}
|
)
|
||||||
title="Tambah Anggota"
|
: data.map((item, index) => (
|
||||||
/>
|
<Pressable
|
||||||
}
|
key={index}
|
||||||
{
|
onPress={() => { setChooseUser(item); setModal(true) }}
|
||||||
loading ?
|
style={({ pressed }) => [
|
||||||
arrSkeleton.map((item, index) => {
|
Styles.rowItemsCenter, Styles.ph15,
|
||||||
return (
|
{
|
||||||
<SkeletonTwoItem key={index} />
|
paddingVertical: 13, gap: 14,
|
||||||
)
|
borderBottomWidth: index < data.length - 1 ? 1 : 0,
|
||||||
})
|
borderBottomColor: colors.icon + '14',
|
||||||
:
|
backgroundColor: pressed ? colors.icon + '0E' : 'transparent',
|
||||||
data.map((item, index) => {
|
},
|
||||||
return (
|
]}
|
||||||
<BorderBottomItem
|
>
|
||||||
key={index}
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
|
||||||
borderType="bottom"
|
<Text style={[Styles.textDefault, Styles.flex1, { color: colors.text }]} numberOfLines={1}>
|
||||||
icon={
|
{item.name}
|
||||||
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="sm" />
|
</Text>
|
||||||
}
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.icon + '60'} />
|
||||||
title={item.name}
|
</Pressable>
|
||||||
onPress={() => {
|
))
|
||||||
setChooseUser(item)
|
|
||||||
setModal(true)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title={chooseUser.name}>
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title={chooseUser.name}>
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="account-eye" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="account-eye" color={colors.text} size={25} />}
|
||||||
title="Lihat Profil"
|
title="Lihat Profil"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
router.push(`/member/${chooseUser.idUser}`)
|
router.push(`/member/${chooseUser.idUser}`)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{
|
{canManage && (
|
||||||
entityUser.role != "user" && entityUser.role != "coadmin" &&
|
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="account-remove" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="account-remove" color={colors.text} size={25} />}
|
||||||
title="Keluarkan"
|
title="Keluarkan"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
AlertKonfirmasi({
|
setTimeout(() => setShowDeleteModal(true), 600)
|
||||||
title: 'Konfirmasi',
|
|
||||||
desc: 'Apakah Anda yakin ingin mengeluarkan anggota?',
|
|
||||||
onPress: () => {
|
|
||||||
handleDeleteUser()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
)}
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message="Apakah anda yakin ingin mengeluarkan anggota?"
|
||||||
|
onConfirm={() => { setShowDeleteModal(false); handleDeleteUser() }}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText="Hapus"
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiAddMemberCalendar, apiGetCalendarOne, apiGetDivisionMember } from "@/lib/api";
|
import { apiAddMemberCalendar, apiGetCalendarOne, apiGetDivisionMember } from "@/lib/api";
|
||||||
import { setUpdateCalendar } from "@/lib/calendarUpdate";
|
import { setUpdateCalendar } from "@/lib/calendarUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { AntDesign } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -23,6 +24,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AddMemberCalendarEvent() {
|
export default function AddMemberCalendarEvent() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.calendarUpdate)
|
const update = useSelector((state: any) => state.calendarUpdate)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
@@ -90,9 +92,11 @@ export default function AddMemberCalendarEvent() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan anggota"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -100,7 +104,7 @@ export default function AddMemberCalendarEvent() {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -154,7 +158,7 @@ export default function AddMemberCalendarEvent() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.pv05, { textAlign: 'center' }]}>Tidak ada member yang dipilih</Text>
|
<Text style={[Styles.textDefault, Styles.pv05, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada member yang dipilih</Text>
|
||||||
}
|
}
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
@@ -167,7 +171,7 @@ export default function AddMemberCalendarEvent() {
|
|||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={index}
|
key={index}
|
||||||
style={[Styles.itemSelectModal]}
|
style={[Styles.itemSelectModal, {borderColor: colors.icon + '20'}]}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
!found && onChoose(item.idUser, item.name, item.img)
|
!found && onChoose(item.idUser, item.name, item.img)
|
||||||
}}
|
}}
|
||||||
@@ -177,12 +181,12 @@ export default function AddMemberCalendarEvent() {
|
|||||||
<View style={[Styles.ml10, { width: '80%' }]}>
|
<View style={[Styles.ml10, { width: '80%' }]}>
|
||||||
<Text numberOfLines={1} ellipsizeMode="tail" style={[Styles.textDefault]}>{item.name}</Text>
|
<Text numberOfLines={1} ellipsizeMode="tail" style={[Styles.textDefault]}>{item.name}</Text>
|
||||||
{
|
{
|
||||||
found && <Text style={[Styles.textInformation, Styles.cGray]}>sudah menjadi anggota</Text>
|
found && <Text style={[Styles.textInformation, { color: colors.dimmed }]}>sudah menjadi anggota</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
selectMember.some((i: any) => i.idUser == item.idUser) && <AntDesign name="check" size={20} color={'black'} />
|
selectMember.some((i: any) => i.idUser == item.idUser) && <AntDesign name="check" size={20} color={colors.text} />
|
||||||
}
|
}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { valueTypeEventRepeat } from "@/constants/TypeEventRepeat"
|
|||||||
import { apiGetCalendarOne, apiUpdateCalendar } from "@/lib/api"
|
import { apiGetCalendarOne, apiUpdateCalendar } from "@/lib/api"
|
||||||
import { stringToDateTime } from "@/lib/fun_stringToDate"
|
import { stringToDateTime } from "@/lib/fun_stringToDate"
|
||||||
import { useAuthSession } from "@/providers/AuthProvider"
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { useHeaderHeight } from "@react-navigation/elements"
|
import { useHeaderHeight } from "@react-navigation/elements"
|
||||||
import { Stack, router, useLocalSearchParams } from "expo-router"
|
import { Stack, router, useLocalSearchParams } from "expo-router"
|
||||||
import moment from "moment"
|
import moment from "moment"
|
||||||
@@ -17,6 +18,7 @@ import { KeyboardAvoidingView, Platform, SafeAreaView, ScrollView, View } from "
|
|||||||
import Toast from "react-native-toast-message"
|
import Toast from "react-native-toast-message"
|
||||||
|
|
||||||
export default function EditEventCalendar() {
|
export default function EditEventCalendar() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const [choose, setChoose] = useState({ val: "", label: "" })
|
const [choose, setChoose] = useState({ val: "", label: "" })
|
||||||
const [isSelect, setSelect] = useState(false)
|
const [isSelect, setSelect] = useState(false)
|
||||||
@@ -55,9 +57,11 @@ export default function EditEventCalendar() {
|
|||||||
setData({ ...response.data, dateStart: moment(response.data.dateStartFormat, 'DD-MM-YYYY').format('DD-MM-YYYY') })
|
setData({ ...response.data, dateStart: moment(response.data.dateStartFormat, 'DD-MM-YYYY').format('DD-MM-YYYY') })
|
||||||
setIdCalendar(response.data.idCalendar)
|
setIdCalendar(response.data.idCalendar)
|
||||||
setChoose({ val: response.data.repeatEventTyper, label: valueTypeEventRepeat.find((item) => item.id == response.data.repeatEventTyper)?.name || "" })
|
setChoose({ val: response.data.repeatEventTyper, label: valueTypeEventRepeat.find((item) => item.id == response.data.repeatEventTyper)?.name || "" })
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Gagal mendapatkan data', })
|
const message = error?.response?.data?.message || "Gagal mendapatkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,9 +156,11 @@ export default function EditEventCalendar() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengubah acara"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -162,7 +168,7 @@ export default function EditEventCalendar() {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -205,7 +211,7 @@ export default function EditEventCalendar() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Nama Acara"
|
placeholder="Nama Acara"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={data.title}
|
value={data.title}
|
||||||
onChange={(val) => validationForm("title", val)}
|
onChange={(val) => validationForm("title", val)}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
@@ -251,12 +257,12 @@ export default function EditEventCalendar() {
|
|||||||
label="Link Meet"
|
label="Link Meet"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Link Meet"
|
placeholder="Link Meet"
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={data.linkMeet}
|
value={data.linkMeet}
|
||||||
onChange={(val) => validationForm("linkMeet", val)}
|
onChange={(val) => validationForm("linkMeet", val)}
|
||||||
/>
|
/>
|
||||||
<SelectForm
|
<SelectForm
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
label="Ulangi Acara"
|
label="Ulangi Acara"
|
||||||
placeholder="Ulangi Acara"
|
placeholder="Ulangi Acara"
|
||||||
value={choose.label}
|
value={choose.label}
|
||||||
@@ -268,7 +274,7 @@ export default function EditEventCalendar() {
|
|||||||
type="numeric"
|
type="numeric"
|
||||||
placeholder="Jumlah Pengulangan"
|
placeholder="Jumlah Pengulangan"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={String(data.repeatValue)}
|
value={String(data.repeatValue)}
|
||||||
onChange={(val) => validationForm("repeatValue", val)}
|
onChange={(val) => validationForm("repeatValue", val)}
|
||||||
error={error.repeatValue}
|
error={error.repeatValue}
|
||||||
@@ -279,7 +285,7 @@ export default function EditEventCalendar() {
|
|||||||
label="Deskripsi"
|
label="Deskripsi"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Deskripsi"
|
placeholder="Deskripsi"
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={data.desc}
|
value={data.desc}
|
||||||
onChange={(val) => validationForm("desc", val)}
|
onChange={(val) => validationForm("desc", val)}
|
||||||
multiline
|
multiline
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi"
|
|
||||||
import AppHeader from "@/components/AppHeader"
|
import AppHeader from "@/components/AppHeader"
|
||||||
import BorderBottomItem from "@/components/borderBottomItem"
|
|
||||||
import ButtonBackHeader from "@/components/buttonBackHeader"
|
|
||||||
import HeaderRightCalendarDetail from "@/components/calendar/headerCalendarDetail"
|
|
||||||
import DrawerBottom from "@/components/drawerBottom"
|
import DrawerBottom from "@/components/drawerBottom"
|
||||||
|
import HeaderRightCalendarDetail from "@/components/calendar/headerCalendarDetail"
|
||||||
import ImageUser from "@/components/imageNew"
|
import ImageUser from "@/components/imageNew"
|
||||||
import MenuItemRow from "@/components/menuItemRow"
|
import MenuItemRow from "@/components/menuItemRow"
|
||||||
import Skeleton from "@/components/skeleton"
|
import ModalConfirmation from "@/components/ModalConfirmation"
|
||||||
import Text from "@/components/Text"
|
import Text from "@/components/Text"
|
||||||
import { ConstEnv } from "@/constants/ConstEnv"
|
import { ConstEnv } from "@/constants/ConstEnv"
|
||||||
import Styles from "@/constants/Styles"
|
import Styles from "@/constants/Styles"
|
||||||
import { apiDeleteCalendarMember, apiGetCalendarOne, apiGetDivisionOneFeature } from "@/lib/api"
|
import { apiDeleteCalendarMember, apiGetCalendarOne, apiGetDivisionOneFeature } from "@/lib/api"
|
||||||
import { setUpdateCalendar } from "@/lib/calendarUpdate"
|
import { setUpdateCalendar } from "@/lib/calendarUpdate"
|
||||||
import { useAuthSession } from "@/providers/AuthProvider"
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
import { MaterialCommunityIcons } from "@expo/vector-icons"
|
import { useTheme } from "@/providers/ThemeProvider"
|
||||||
|
import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
|
||||||
import Clipboard from "@react-native-clipboard/clipboard"
|
import Clipboard from "@react-native-clipboard/clipboard"
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router"
|
import { router, Stack, useLocalSearchParams } from "expo-router"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
@@ -45,6 +43,7 @@ type PropsMember = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function DetailEventCalendar() {
|
export default function DetailEventCalendar() {
|
||||||
|
const { colors } = useTheme()
|
||||||
const { id, detail } = useLocalSearchParams<{ id: string, detail: string }>();
|
const { id, detail } = useLocalSearchParams<{ id: string, detail: string }>();
|
||||||
const [data, setData] = useState<Props>()
|
const [data, setData] = useState<Props>()
|
||||||
const [member, setMember] = useState<PropsMember[]>([])
|
const [member, setMember] = useState<PropsMember[]>([])
|
||||||
@@ -55,6 +54,7 @@ export default function DetailEventCalendar() {
|
|||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const entityUser = useSelector((state: any) => state.user);
|
const entityUser = useSelector((state: any) => state.user);
|
||||||
const [isMemberDivision, setIsMemberDivision] = useState(false);
|
const [isMemberDivision, setIsMemberDivision] = useState(false);
|
||||||
|
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
|
||||||
@@ -134,9 +134,11 @@ export default function DetailEventCalendar() {
|
|||||||
dispatch(setUpdateCalendar({ ...update, member: !update.member }));
|
dispatch(setUpdateCalendar({ ...update, member: !update.member }));
|
||||||
}
|
}
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menghapus anggota"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setModalMember(false)
|
setModalMember(false)
|
||||||
}
|
}
|
||||||
@@ -151,134 +153,142 @@ export default function DetailEventCalendar() {
|
|||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const canManage = !((entityUser.role === "user" || entityUser.role === "coadmin") && !isMemberDivision)
|
||||||
|
|
||||||
|
const repeatLabel: Record<string, string> = {
|
||||||
|
once: 'Acara 1 Kali',
|
||||||
|
daily: 'Setiap Hari',
|
||||||
|
weekly: 'Mingguan',
|
||||||
|
monthly: 'Bulanan',
|
||||||
|
yearly: 'Tahunan',
|
||||||
|
}
|
||||||
|
|
||||||
|
function InfoRow({ icon, label, value, onCopy }: { icon: string, label: string, value?: string, onCopy?: () => void }) {
|
||||||
|
return (
|
||||||
|
<View style={[Styles.sectionActionRow, { paddingVertical: 10, borderBottomWidth: 1, borderBottomColor: colors.icon + '14' }]}>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<MaterialCommunityIcons name={icon as any} size={18} color={colors.dimmed} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed, marginBottom: 2 }]}>{label}</Text>
|
||||||
|
{loading
|
||||||
|
? <View style={{ height: 13, borderRadius: 6, backgroundColor: colors.icon + '20', width: '70%' }} />
|
||||||
|
: <Text style={[Styles.textDefault, { color: colors.text }]}>{value || '-'}</Text>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
{onCopy && !loading && value && (
|
||||||
|
<Pressable onPress={onCopy} style={{ padding: 4 }}>
|
||||||
|
<MaterialCommunityIcons name="content-copy" size={16} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
header: () => (
|
||||||
headerTitle: 'Detail Acara',
|
|
||||||
headerTitleAlign: 'center',
|
|
||||||
// headerRight: () => (entityUser.role == "user" || entityUser.role == "coadmin") && !isMemberDivision ? <></> : <HeaderRightCalendarDetail id={String(data?.idCalendar)} idReminder={String(detail)} />
|
|
||||||
header:()=>(
|
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Detail Acara"
|
title="Detail Acara"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={
|
right={
|
||||||
(entityUser.role == "user" || entityUser.role == "coadmin") && !isMemberDivision ? <></> : <HeaderRightCalendarDetail id={String(data?.idCalendar)} idReminder={String(detail)} />
|
(entityUser.role === "user" || entityUser.role === "coadmin") && !isMemberDivision
|
||||||
|
? <></> : <HeaderRightCalendarDetail id={String(data?.idCalendar)} idReminder={String(detail)} />
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
style={[Styles.h100]}
|
showsVerticalScrollIndicator={false}
|
||||||
refreshControl={
|
style={Styles.h100}
|
||||||
<RefreshControl
|
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} tintColor={colors.icon} />}
|
||||||
refreshing={refreshing}
|
|
||||||
onRefresh={handleRefresh}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<View style={[Styles.wrapPaper, Styles.mb15]}>
|
|
||||||
<View style={[Styles.rowItemsCenter, { alignItems: 'flex-start' }]}>
|
|
||||||
<MaterialCommunityIcons name="calendar-text" size={30} color="black" style={Styles.mr10} />
|
|
||||||
{
|
|
||||||
loading ?
|
|
||||||
<Skeleton width={80} height={10} borderRadius={10} widthType="percent" />
|
|
||||||
: <Text style={[Styles.textDefault, Styles.w90]}>{data?.title}</Text>
|
|
||||||
}
|
|
||||||
|
|
||||||
|
{/* Info acara */}
|
||||||
|
<View style={[Styles.wrapPaper, Styles.sectionCard, Styles.noShadow, Styles.mb15,
|
||||||
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18', padding: 0, overflow: 'hidden' }]}>
|
||||||
|
<View style={{ padding: 16, borderBottomWidth: 1, borderBottomColor: colors.icon + '14' }}>
|
||||||
|
<View style={Styles.sectionActionRow}>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<MaterialCommunityIcons name="calendar-text" size={18} color={colors.dimmed} />
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, Styles.flex1, { color: colors.text }]}>Detail Acara</Text>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={[Styles.rowItemsCenter, Styles.mt10]}>
|
<View style={{ paddingHorizontal: 16 }}>
|
||||||
<MaterialCommunityIcons name="calendar-month-outline" size={30} color="black" style={Styles.mr10} />
|
<InfoRow icon="format-title" label="Judul" value={data?.title} />
|
||||||
{
|
<InfoRow icon="calendar-month-outline" label="Tanggal" value={data?.dateStart} />
|
||||||
loading ?
|
<InfoRow icon="clock-outline" label="Waktu" value={data ? `${data.timeStart} – ${data.timeEnd}` : undefined} />
|
||||||
<Skeleton width={80} height={10} borderRadius={10} widthType="percent" />
|
<InfoRow icon="repeat" label="Pengulangan" value={data?.repeatEventTyper ? repeatLabel[data.repeatEventTyper] : undefined} />
|
||||||
:
|
<InfoRow icon="link-variant" label="Link Meet" value={data?.linkMeet} onCopy={data?.linkMeet ? () => handleCopy(data.linkMeet) : undefined} />
|
||||||
<Text style={[Styles.textDefault]}>{data?.dateStart}</Text>
|
<View style={[Styles.sectionActionRow, { paddingVertical: 10, alignItems: 'flex-start' }]}>
|
||||||
}
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<MaterialCommunityIcons name="card-text-outline" size={18} color={colors.dimmed} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed, marginBottom: 2 }]}>Deskripsi</Text>
|
||||||
|
{loading
|
||||||
|
? <View style={{ height: 13, borderRadius: 6, backgroundColor: colors.icon + '20', width: '80%' }} />
|
||||||
|
: <Text style={[Styles.textDefault, { color: colors.text, lineHeight: 22 }]}>{data?.desc || '-'}</Text>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={[Styles.rowItemsCenter, Styles.mt10]}>
|
</View>
|
||||||
<MaterialCommunityIcons name="clock-outline" size={30} color="black" style={Styles.mr10} />
|
|
||||||
{
|
{/* Daftar anggota */}
|
||||||
loading ?
|
<View style={[Styles.wrapPaper, Styles.sectionCard, Styles.noShadow,
|
||||||
<Skeleton width={80} height={10} borderRadius={10} widthType="percent" />
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18', padding: 0, overflow: 'hidden' }]}>
|
||||||
:
|
|
||||||
<Text style={[Styles.textDefault]}>{data?.timeStart} | {data?.timeEnd}</Text>
|
<View style={[Styles.sectionActionRow, { padding: 16, borderBottomWidth: 1, borderBottomColor: colors.icon + '14' }]}>
|
||||||
}
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<MaterialIcons name="people" size={18} color={colors.dimmed} />
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, Styles.flex1, { color: colors.text }]}>Anggota</Text>
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>{member.length} anggota</Text>
|
||||||
</View>
|
</View>
|
||||||
<View style={[Styles.rowItemsCenter, Styles.mt10]}>
|
|
||||||
<MaterialCommunityIcons name="repeat" size={30} color="black" style={Styles.mr10} />
|
{member.length === 0
|
||||||
{
|
? (
|
||||||
loading ?
|
<View style={[Styles.contentItemCenter, { paddingVertical: 40 }]}>
|
||||||
<Skeleton width={80} height={10} borderRadius={10} widthType="percent" />
|
<MaterialIcons name="people-outline" size={34} color={colors.icon + '50'} />
|
||||||
:
|
<Text style={[Styles.textMediumNormal, Styles.mt10, { color: colors.dimmed }]}>Belum ada anggota</Text>
|
||||||
<Text style={[Styles.textDefault]}>
|
</View>
|
||||||
|
)
|
||||||
|
: member.map((item, index) => (
|
||||||
|
<Pressable
|
||||||
|
key={index}
|
||||||
|
onPress={() => {
|
||||||
|
if (!canManage) return
|
||||||
|
setMemberChoose({ id: item.idUser, name: item.name })
|
||||||
|
setModalMember(true)
|
||||||
|
}}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
Styles.rowItemsCenter, Styles.ph15,
|
||||||
{
|
{
|
||||||
data?.repeatEventTyper.toString() === 'once' ? 'Acara 1 Kali' :
|
paddingVertical: 12, gap: 14,
|
||||||
data?.repeatEventTyper.toString() === 'daily' ? 'Setiap Hari' :
|
borderBottomWidth: index < member.length - 1 ? 1 : 0,
|
||||||
data?.repeatEventTyper.toString() === 'weekly' ? 'Mingguan' :
|
borderBottomColor: colors.icon + '14',
|
||||||
data?.repeatEventTyper.toString() === 'monthly' ? 'Bulanan' :
|
backgroundColor: pressed && canManage ? colors.icon + '0E' : 'transparent',
|
||||||
data?.repeatEventTyper.toString() === 'yearly' ? 'Tahunan' :
|
},
|
||||||
''
|
]}
|
||||||
}
|
>
|
||||||
</Text>
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
|
||||||
}
|
<View style={Styles.flex1}>
|
||||||
</View>
|
<Text style={[Styles.textDefault, { color: colors.text }]} numberOfLines={1}>{item.name}</Text>
|
||||||
<View style={[Styles.rowItemsCenter, Styles.mt10]}>
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]} numberOfLines={1}>{item.email}</Text>
|
||||||
<MaterialCommunityIcons name="link-variant" size={30} color="black" style={Styles.mr10} />
|
</View>
|
||||||
{
|
{canManage && <MaterialCommunityIcons name="chevron-right" size={18} color={colors.icon + '60'} />}
|
||||||
loading ?
|
</Pressable>
|
||||||
<Skeleton width={80} height={10} borderRadius={10} widthType="percent" />
|
))
|
||||||
:
|
}
|
||||||
data?.linkMeet ?
|
|
||||||
<Pressable onPress={() => { handleCopy(data.linkMeet) }}>
|
|
||||||
<Text style={[Styles.textDefault]}>{data.linkMeet}</Text>
|
|
||||||
</Pressable>
|
|
||||||
: <Text style={[Styles.textDefault]}>-</Text>
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
<View style={[Styles.rowItemsCenter, Styles.mt10, { alignItems: 'flex-start' }]}>
|
|
||||||
<MaterialCommunityIcons name="card-text-outline" size={30} color="black" style={Styles.mr10} />
|
|
||||||
{
|
|
||||||
loading ?
|
|
||||||
<Skeleton width={80} height={10} borderRadius={10} widthType="percent" />
|
|
||||||
:
|
|
||||||
<Text style={[Styles.textDefault, Styles.w90]}>{data?.desc}</Text>
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={[Styles.mb15]}>
|
|
||||||
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
|
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>Anggota</Text>
|
|
||||||
<Text style={[Styles.textDefault]}>Total {member.length} Anggota</Text>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={[Styles.wrapPaper]}>
|
|
||||||
{
|
|
||||||
member.map((item, index) => (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={index}
|
|
||||||
borderType="bottom"
|
|
||||||
icon={<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} />}
|
|
||||||
title={item.name}
|
|
||||||
subtitle={item.email}
|
|
||||||
onPress={() => {
|
|
||||||
if ((entityUser.role == "user" || entityUser.role == "coadmin") && !isMemberDivision) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
setMemberChoose({ id: item.idUser, name: item.name })
|
|
||||||
setModalMember(true)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
@@ -286,7 +296,7 @@ export default function DetailEventCalendar() {
|
|||||||
<DrawerBottom animation="slide" isVisible={isModalMember} setVisible={setModalMember} title={memberChoose.name}>
|
<DrawerBottom animation="slide" isVisible={isModalMember} setVisible={setModalMember} title={memberChoose.name}>
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="account-eye" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="account-eye" color={colors.text} size={25} />}
|
||||||
title="Lihat Profil"
|
title="Lihat Profil"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModalMember(false)
|
setModalMember(false)
|
||||||
@@ -295,22 +305,30 @@ export default function DetailEventCalendar() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="account-remove" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="account-remove" color={colors.text} size={25} />}
|
||||||
title="Keluarkan"
|
title="Keluarkan"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModalMember(false)
|
setModalMember(false)
|
||||||
AlertKonfirmasi({
|
setTimeout(() => {
|
||||||
title: 'Konfirmasi',
|
setShowDeleteModal(true)
|
||||||
desc: 'Apakah Anda yakin ingin mengeluarkan anggota?',
|
}, 600)
|
||||||
onPress: () => {
|
|
||||||
handleDeleteUser()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message="Apakah Anda yakin ingin mengeluarkan anggota?"
|
||||||
|
onConfirm={() => {
|
||||||
|
setShowDeleteModal(false)
|
||||||
|
handleDeleteUser()
|
||||||
|
}}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText="Keluar"
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import { apiCreateCalendar, apiGetDivisionMember } from "@/lib/api";
|
|||||||
import { setFormCreateCalendar } from "@/lib/calendarCreate";
|
import { setFormCreateCalendar } from "@/lib/calendarCreate";
|
||||||
import { setUpdateCalendar } from "@/lib/calendarUpdate";
|
import { setUpdateCalendar } from "@/lib/calendarUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { AntDesign } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -24,6 +25,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function CreateCalendarAddMember() {
|
export default function CreateCalendarAddMember() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [data, setData] = useState<Props[]>([])
|
const [data, setData] = useState<Props[]>([])
|
||||||
@@ -81,16 +83,18 @@ export default function CreateCalendarAddMember() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal membuat acara"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -141,7 +145,7 @@ export default function CreateCalendarAddMember() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.pv05, { textAlign: 'center' }]}>Tidak ada member yang dipilih</Text>
|
<Text style={[Styles.textDefault, Styles.pv05, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada member yang dipilih</Text>
|
||||||
}
|
}
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
@@ -154,7 +158,7 @@ export default function CreateCalendarAddMember() {
|
|||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={index}
|
key={index}
|
||||||
style={[Styles.itemSelectModal]}
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
|
||||||
onPress={() => { onChoose(item.idUser, item.name, item.img) }}
|
onPress={() => { onChoose(item.idUser, item.name, item.img) }}
|
||||||
>
|
>
|
||||||
<View style={[Styles.rowItemsCenter, Styles.w70]}>
|
<View style={[Styles.rowItemsCenter, Styles.w70]}>
|
||||||
@@ -164,7 +168,7 @@ export default function CreateCalendarAddMember() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
selectMember.some((i: any) => i.idUser == item.idUser) && <AntDesign name="check" size={20} color={'black'} />
|
selectMember.some((i: any) => i.idUser == item.idUser) && <AntDesign name="check" size={20} color={colors.text} />
|
||||||
}
|
}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { setFormCreateCalendar } from "@/lib/calendarCreate";
|
import { setFormCreateCalendar } from "@/lib/calendarCreate";
|
||||||
import { stringToDateTime } from "@/lib/fun_stringToDate";
|
import { stringToDateTime } from "@/lib/fun_stringToDate";
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Stack, router, useLocalSearchParams } from "expo-router";
|
import { Stack, router, useLocalSearchParams } from "expo-router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import {
|
import {
|
||||||
@@ -21,6 +22,7 @@ import {
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function CalendarDivisionCreate() {
|
export default function CalendarDivisionCreate() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [choose, setChoose] = useState({ val: "", label: "" })
|
const [choose, setChoose] = useState({ val: "", label: "" })
|
||||||
const [isSelect, setSelect] = useState(false)
|
const [isSelect, setSelect] = useState(false)
|
||||||
@@ -126,7 +128,7 @@ export default function CalendarDivisionCreate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -144,7 +146,7 @@ export default function CalendarDivisionCreate() {
|
|||||||
// disable={Object.values(error).some((val) => val == true) || data.title == "" || data.dateStart == "" || data.timeStart == "" || data.timeEnd == "" || data.repeatEventType == ""}
|
// disable={Object.values(error).some((val) => val == true) || data.title == "" || data.dateStart == "" || data.timeStart == "" || data.timeEnd == "" || data.repeatEventType == ""}
|
||||||
// />
|
// />
|
||||||
// ),
|
// ),
|
||||||
header:()=>(
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Tambah Acara"
|
title="Tambah Acara"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
@@ -173,7 +175,7 @@ export default function CalendarDivisionCreate() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Nama Acara"
|
placeholder="Nama Acara"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={data.title}
|
value={data.title}
|
||||||
onChange={(val) => validationForm("title", val)}
|
onChange={(val) => validationForm("title", val)}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
@@ -219,12 +221,12 @@ export default function CalendarDivisionCreate() {
|
|||||||
label="Link Meet"
|
label="Link Meet"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Link Meet"
|
placeholder="Link Meet"
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={data.linkMeet}
|
value={data.linkMeet}
|
||||||
onChange={(val) => validationForm("linkMeet", val)}
|
onChange={(val) => validationForm("linkMeet", val)}
|
||||||
/>
|
/>
|
||||||
<SelectForm
|
<SelectForm
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
label="Ulangi Acara"
|
label="Ulangi Acara"
|
||||||
placeholder="Ulangi Acara"
|
placeholder="Ulangi Acara"
|
||||||
value={choose.label}
|
value={choose.label}
|
||||||
@@ -236,7 +238,7 @@ export default function CalendarDivisionCreate() {
|
|||||||
type="numeric"
|
type="numeric"
|
||||||
placeholder="Jumlah Pengulangan"
|
placeholder="Jumlah Pengulangan"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={String(data.repeatValue)}
|
value={String(data.repeatValue)}
|
||||||
onChange={(val) => validationForm("repeatValue", val)}
|
onChange={(val) => validationForm("repeatValue", val)}
|
||||||
error={error.repeatValue}
|
error={error.repeatValue}
|
||||||
@@ -247,7 +249,7 @@ export default function CalendarDivisionCreate() {
|
|||||||
label="Deskripsi"
|
label="Deskripsi"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Deskripsi"
|
placeholder="Deskripsi"
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={data.desc}
|
value={data.desc}
|
||||||
onChange={(val) => validationForm("desc", val)}
|
onChange={(val) => validationForm("desc", val)}
|
||||||
multiline
|
multiline
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import InputSearch from "@/components/inputSearch";
|
import InputSearch from "@/components/inputSearch";
|
||||||
import Skeleton from "@/components/skeleton";
|
import Skeleton from "@/components/skeleton";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetCalendarHistory } from "@/lib/api";
|
import { apiGetCalendarHistory } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { useLocalSearchParams } from "expo-router";
|
import { useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { FlatList, View, VirtualizedList } from "react-native";
|
import { FlatList, View, VirtualizedList } from "react-native";
|
||||||
@@ -15,6 +15,7 @@ type Props = {
|
|||||||
data: []
|
data: []
|
||||||
}
|
}
|
||||||
export default function CalendarHistory() {
|
export default function CalendarHistory() {
|
||||||
|
const { colors, activeTheme } = useTheme();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const [data, setData] = useState<Props[]>([])
|
const [data, setData] = useState<Props[]>([])
|
||||||
@@ -64,11 +65,11 @@ export default function CalendarHistory() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
<View>
|
<View>
|
||||||
<InputSearch onChange={(val) => setSearch(val)} />
|
<InputSearch onChange={(val) => setSearch(val)} />
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ flex: 2, }]}>
|
<View style={[{ flex: 2 }, Styles.mt10]}>
|
||||||
{
|
{
|
||||||
loading ?
|
loading ?
|
||||||
arrSkeleton.map((item, index) => (
|
arrSkeleton.map((item, index) => (
|
||||||
@@ -81,7 +82,7 @@ export default function CalendarHistory() {
|
|||||||
getItem={getItem}
|
getItem={getItem}
|
||||||
renderItem={({ item, index }: { item: Props, index: number }) => {
|
renderItem={({ item, index }: { item: Props, index: number }) => {
|
||||||
return (
|
return (
|
||||||
<View key={index} style={[{ flexDirection: 'row' }, Styles.mv05, ColorsStatus.lightGreen, Styles.p10, Styles.round10]}>
|
<View key={index} style={[{ flexDirection: 'row' }, Styles.mb05, Styles.borderAll, { backgroundColor: colors.card }, Styles.p10, Styles.round05, { borderColor: colors.icon + '20' }]}>
|
||||||
<View style={[Styles.mr10, Styles.ph05]}>
|
<View style={[Styles.mr10, Styles.ph05]}>
|
||||||
<Text style={[Styles.textSubtitle]}>{String(item.dateStart)}</Text>
|
<Text style={[Styles.textSubtitle]}>{String(item.dateStart)}</Text>
|
||||||
<Text style={[Styles.textDefault, { textAlign: 'center' }]}>{item.year}</Text>
|
<Text style={[Styles.textDefault, { textAlign: 'center' }]}>{item.year}</Text>
|
||||||
@@ -89,7 +90,7 @@ export default function CalendarHistory() {
|
|||||||
<View style={[{ flex: 1 }]}>
|
<View style={[{ flex: 1 }]}>
|
||||||
<FlatList data={item.data}
|
<FlatList data={item.data}
|
||||||
renderItem={({ item, index }: { item: { title: string, timeStart: string, timeEnd: string }, index: number }) => (
|
renderItem={({ item, index }: { item: { title: string, timeStart: string, timeEnd: string }, index: number }) => (
|
||||||
<View key={index} style={[Styles.mb05, Styles.w80]}>
|
<View key={index} style={[Styles.mb05]}>
|
||||||
<Text style={[Styles.textDefaultSemiBold]} numberOfLines={1} ellipsizeMode="tail">{item.title}</Text>
|
<Text style={[Styles.textDefaultSemiBold]} numberOfLines={1} ellipsizeMode="tail">{item.title}</Text>
|
||||||
<Text style={[Styles.textDefault]}>{item.timeStart} | {item.timeEnd}</Text>
|
<Text style={[Styles.textDefault]}>{item.timeStart} | {item.timeEnd}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
import HeaderRightCalendarList from "@/components/calendar/headerCalendarList";
|
import HeaderRightCalendarList from "@/components/calendar/headerCalendarList";
|
||||||
import ItemDateCalendar from "@/components/calendar/itemDateCalendar";
|
import ItemDateCalendar from "@/components/calendar/itemDateCalendar";
|
||||||
import EventItem from "@/components/eventItem";
|
import EventItem from "@/components/eventItem";
|
||||||
@@ -6,7 +7,10 @@ import Skeleton from "@/components/skeleton";
|
|||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetCalendarByDateDivision, apiGetIndicatorCalendar } from "@/lib/api";
|
import { apiGetCalendarByDateDivision, apiGetIndicatorCalendar } from "@/lib/api";
|
||||||
|
import { GUIDE_DIVISION_CALENDAR } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Feather } from "@expo/vector-icons";
|
import { Feather } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import 'intl';
|
import 'intl';
|
||||||
@@ -34,6 +38,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function CalendarDivision() {
|
export default function CalendarDivision() {
|
||||||
|
const { colors, activeTheme } = useTheme();
|
||||||
const [selected, setSelected] = useState<any>(new Date())
|
const [selected, setSelected] = useState<any>(new Date())
|
||||||
const [data, setData] = useState<Props[]>([])
|
const [data, setData] = useState<Props[]>([])
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
@@ -44,6 +49,7 @@ export default function CalendarDivision() {
|
|||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [loadingBtn, setLoadingBtn] = useState(false)
|
const [loadingBtn, setLoadingBtn] = useState(false)
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('division-calendar')
|
||||||
|
|
||||||
|
|
||||||
async function handleLoad(loading: boolean) {
|
async function handleLoad(loading: boolean) {
|
||||||
@@ -117,15 +123,15 @@ export default function CalendarDivision() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
IconNext: <Pressable onPress={() => !loadingBtn ? setMonth(month + 1) : null}>
|
IconNext: <Pressable onPress={() => !loadingBtn ? setMonth(month + 1) : null}>
|
||||||
<Feather name="chevron-right" size={20} color={loadingBtn ? 'gray' : 'black'} />
|
<Feather name="chevron-right" size={20} color={loadingBtn ? 'gray' : colors.text} />
|
||||||
</Pressable>,
|
</Pressable>,
|
||||||
IconPrev: <Pressable onPress={() => !loadingBtn ? setMonth(month - 1) : null}>
|
IconPrev: <Pressable onPress={() => !loadingBtn ? setMonth(month - 1) : null}>
|
||||||
<Feather name="chevron-left" size={20} color={loadingBtn ? 'gray' : 'black'} />
|
<Feather name="chevron-left" size={20} color={loadingBtn ? 'gray' : colors.text} />
|
||||||
</Pressable>,
|
</Pressable>,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -148,17 +154,19 @@ export default function CalendarDivision() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<GuideOverlay visible={guideVisible} steps={GUIDE_DIVISION_CALENDAR} onDismiss={dismissGuide} />
|
||||||
<ScrollView
|
<ScrollView
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100]}
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
<Datepicker
|
<Datepicker
|
||||||
components={components}
|
components={components}
|
||||||
mode="single"
|
mode="single"
|
||||||
@@ -167,19 +175,19 @@ export default function CalendarDivision() {
|
|||||||
onMonthChange={(month) => setMonth(month)}
|
onMonthChange={(month) => setMonth(month)}
|
||||||
styles={{
|
styles={{
|
||||||
selected: Styles.selectedDate,
|
selected: Styles.selectedDate,
|
||||||
month_label: Styles.cBlack,
|
month_label: { color: colors.text },
|
||||||
month_selector_label: Styles.cBlack,
|
month_selector_label: { color: colors.text },
|
||||||
year_label: Styles.cBlack,
|
year_label: { color: colors.text },
|
||||||
year_selector_label: Styles.cBlack,
|
year_selector_label: { color: colors.text },
|
||||||
day_label: Styles.cBlack,
|
day_label: { color: colors.text },
|
||||||
time_label: Styles.cBlack,
|
time_label: { color: colors.text },
|
||||||
weekday_label: Styles.cBlack,
|
weekday_label: { color: colors.text },
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={[Styles.mb15, Styles.mt15]}>
|
<View style={[Styles.mb15, Styles.mt15]}>
|
||||||
<Text style={[Styles.textDefaultSemiBold, Styles.mb05]}>Acara</Text>
|
<Text style={[Styles.textDefaultSemiBold, Styles.mb05]}>Acara</Text>
|
||||||
<View style={[Styles.wrapPaper]}>
|
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
{
|
{
|
||||||
loading ?
|
loading ?
|
||||||
<>
|
<>
|
||||||
@@ -202,7 +210,7 @@ export default function CalendarDivision() {
|
|||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada acara</Text>
|
<Text style={[Styles.textDefault, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada acara</Text>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -1,25 +1,45 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import ButtonSelect from "@/components/buttonSelect";
|
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import LoadingOverlay from "@/components/loadingOverlay";
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiEditDiscussion, apiGetDiscussionOne } from "@/lib/api";
|
import { apiEditDiscussion, apiGetDiscussionOne } from "@/lib/api";
|
||||||
import { setUpdateDiscussion } from "@/lib/discussionUpdate";
|
import { setUpdateDiscussion } from "@/lib/discussionUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
import * as DocumentPicker from "expo-document-picker";
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { Pressable, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
|
function getFileIcon(ext: string): keyof typeof MaterialCommunityIcons.glyphMap {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return 'image-outline'
|
||||||
|
if (ext === 'pdf') return 'file-pdf-box'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return 'video-outline'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return 'file-word-outline'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return 'file-excel-outline'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return 'zip-box-outline'
|
||||||
|
return 'file-outline'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileColor(ext: string): string {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return '#339AF0'
|
||||||
|
if (ext === 'pdf') return '#F03E3E'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return '#AE3EC9'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return '#1C7ED6'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return '#2F9E44'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return '#E8590C'
|
||||||
|
return '#868E96'
|
||||||
|
}
|
||||||
|
|
||||||
export default function DiscussionDivisionEdit() {
|
export default function DiscussionDivisionEdit() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const [data, setData] = useState("");
|
const [data, setData] = useState("");
|
||||||
@@ -31,30 +51,49 @@ export default function DiscussionDivisionEdit() {
|
|||||||
const [indexDelFile, setIndexDelFile] = useState<{ id: string | number; cat: "newFile" | "oldFile" }>({ id: "", cat: "newFile" })
|
const [indexDelFile, setIndexDelFile] = useState<{ id: string | number; cat: "newFile" | "oldFile" }>({ id: "", cat: "newFile" })
|
||||||
const [dataFile, setDataFile] = useState<{ id: string; idStorage: string; name: string; extension: string; delete?: boolean }[]>([])
|
const [dataFile, setDataFile] = useState<{ id: string; idStorage: string; name: string; extension: string; delete?: boolean }[]>([])
|
||||||
|
|
||||||
|
const visibleOldFiles = dataFile.filter(v => !v.delete)
|
||||||
|
const totalFiles = fileForm.length + visibleOldFiles.length
|
||||||
|
|
||||||
async function handleLoad() {
|
async function handleLoad() {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiGetDiscussionOne({
|
const response = await apiGetDiscussionOne({ id: detail, user: hasil, cat: "data" });
|
||||||
id: detail,
|
const response2 = await apiGetDiscussionOne({ id: detail, user: hasil, cat: "file" });
|
||||||
user: hasil,
|
|
||||||
cat: "data",
|
|
||||||
});
|
|
||||||
const response2 = await apiGetDiscussionOne({
|
|
||||||
id: detail,
|
|
||||||
user: hasil,
|
|
||||||
cat: "file",
|
|
||||||
});
|
|
||||||
setDataFile(response2.data);
|
|
||||||
setData(response.data.desc);
|
setData(response.data.desc);
|
||||||
|
setDataFile(response2.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { handleLoad() }, []);
|
||||||
handleLoad();
|
|
||||||
}, []);
|
const pickDocumentAsync = async () => {
|
||||||
|
const result = await DocumentPicker.getDocumentAsync({ type: ["*/*"], multiple: true });
|
||||||
|
if (!result.canceled) {
|
||||||
|
let skipped = 0
|
||||||
|
for (const asset of result.assets) {
|
||||||
|
if (!asset.uri) continue
|
||||||
|
const isDup = fileForm.some(f => f.name === asset.name) ||
|
||||||
|
visibleOldFiles.some(f => `${f.name}.${f.extension}` === asset.name)
|
||||||
|
if (isDup) {
|
||||||
|
skipped++
|
||||||
|
} else {
|
||||||
|
setFileForm(prev => [...prev, asset])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (skipped > 0) Toast.show({ type: 'small', text1: 'Beberapa file sudah ditambahkan' })
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function deleteFile(index: number | string, cat: "newFile" | "oldFile" | null) {
|
||||||
|
if (cat === "newFile") {
|
||||||
|
setFileForm(fileForm.filter((_, i) => i !== index))
|
||||||
|
} else {
|
||||||
|
setDataFile(prev => prev.map(item => item.id === index ? { ...item, delete: true } : item))
|
||||||
|
}
|
||||||
|
setModalFile(false)
|
||||||
|
}
|
||||||
|
|
||||||
async function handleUpdate() {
|
async function handleUpdate() {
|
||||||
try {
|
try {
|
||||||
@@ -62,92 +101,29 @@ export default function DiscussionDivisionEdit() {
|
|||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const fd = new FormData()
|
const fd = new FormData()
|
||||||
for (let i = 0; i < fileForm.length; i++) {
|
for (let i = 0; i < fileForm.length; i++) {
|
||||||
fd.append(`file${i}`, {
|
fd.append(`file${i}`, { uri: fileForm[i].uri, type: 'application/octet-stream', name: fileForm[i].name } as any);
|
||||||
uri: fileForm[i].uri,
|
|
||||||
type: 'application/octet-stream',
|
|
||||||
name: fileForm[i].name,
|
|
||||||
} as any);
|
|
||||||
}
|
}
|
||||||
|
fd.append("data", JSON.stringify({ user: hasil, desc: data, oldFile: dataFile }))
|
||||||
fd.append("data", JSON.stringify(
|
|
||||||
{
|
|
||||||
user: hasil, desc: data, oldFile: dataFile
|
|
||||||
}
|
|
||||||
))
|
|
||||||
const response = await apiEditDiscussion(fd, detail);
|
const response = await apiEditDiscussion(fd, detail);
|
||||||
|
|
||||||
// const response = await apiEditDiscussion({
|
|
||||||
// data: { user: hasil, desc: data },
|
|
||||||
// id: detail,
|
|
||||||
// });
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil mengubah data', })
|
Toast.show({ type: 'small', text1: 'Berhasil mengubah data' })
|
||||||
dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
|
dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
|
||||||
router.back();
|
router.back();
|
||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal mengubah data" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pickDocumentAsync = async () => {
|
|
||||||
let result = await DocumentPicker.getDocumentAsync({
|
|
||||||
type: ["*/*"],
|
|
||||||
multiple: true
|
|
||||||
});
|
|
||||||
if (!result.canceled) {
|
|
||||||
for (let i = 0; i < result.assets?.length; i++) {
|
|
||||||
if (result.assets[i].uri) {
|
|
||||||
setFileForm((prev) => [...prev, result.assets[i]])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function deleteFile(index: number | string, cat: "newFile" | "oldFile" | null) {
|
|
||||||
if (cat == "newFile") {
|
|
||||||
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
|
||||||
} else {
|
|
||||||
setDataFile(prev =>
|
|
||||||
prev.map(item =>
|
|
||||||
item.id === index
|
|
||||||
? { ...item, delete: true }
|
|
||||||
: item
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
setModalFile(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
|
||||||
// <ButtonBackHeader
|
|
||||||
// onPress={() => {
|
|
||||||
// router.back();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
headerTitle: "Edit Diskusi",
|
|
||||||
headerTitleAlign: "center",
|
|
||||||
// headerRight: () => (
|
|
||||||
// <ButtonSaveHeader
|
|
||||||
// disable={data == "" || loading}
|
|
||||||
// category="update"
|
|
||||||
// onPress={() => {
|
|
||||||
// handleUpdate();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Edit Diskusi"
|
title="Edit Diskusi"
|
||||||
@@ -157,18 +133,16 @@ export default function DiscussionDivisionEdit() {
|
|||||||
<ButtonSaveHeader
|
<ButtonSaveHeader
|
||||||
disable={data == "" || loading}
|
disable={data == "" || loading}
|
||||||
category="update"
|
category="update"
|
||||||
onPress={() => {
|
onPress={() => handleUpdate()}
|
||||||
handleUpdate();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<LoadingOverlay visible={loading} />
|
{loading && <LoadingCenter />}
|
||||||
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15]}>
|
<View style={Styles.p15}>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Diskusi"
|
label="Diskusi"
|
||||||
type="default"
|
type="default"
|
||||||
@@ -177,54 +151,90 @@ export default function DiscussionDivisionEdit() {
|
|||||||
value={data}
|
value={data}
|
||||||
onChange={setData}
|
onChange={setData}
|
||||||
multiline
|
multiline
|
||||||
|
bg={colors.card}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
{/* File */}
|
||||||
{
|
<View style={[Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
(fileForm.length > 0 || dataFile.filter((val) => !val.delete).length > 0)
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
&&
|
<Pressable
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10]}>
|
onPress={pickDocumentAsync}
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
|
style={[Styles.sectionActionRow, { marginBottom: totalFiles > 0 ? 12 : 0 }]}
|
||||||
{
|
>
|
||||||
dataFile.filter((val) => !val.delete).map((item, index) => (
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '15' }]}>
|
||||||
<BorderBottomItem
|
<MaterialCommunityIcons name="paperclip" size={18} color={colors.dimmed} />
|
||||||
key={index}
|
</View>
|
||||||
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
|
<View style={Styles.flex1}>
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>File</Text>
|
||||||
title={item.name + '.' + item.extension}
|
{totalFiles === 0 && (
|
||||||
titleWeight="normal"
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Opsional — ketuk untuk upload</Text>
|
||||||
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
|
)}
|
||||||
/>
|
</View>
|
||||||
))
|
{totalFiles > 0 && (
|
||||||
}
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
{
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{totalFiles} file</Text>
|
||||||
fileForm.map((item, index) => (
|
</View>
|
||||||
<BorderBottomItem
|
)}
|
||||||
key={index}
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
borderType={fileForm.length > 1 ? "bottom" : "none"}
|
</Pressable>
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
{totalFiles > 0 && (
|
||||||
title={item.name}
|
<View style={Styles.fileGrid}>
|
||||||
titleWeight="normal"
|
{visibleOldFiles.map((item, index) => {
|
||||||
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
|
const ext = item.extension.toLowerCase()
|
||||||
/>
|
const iconName = getFileIcon(ext)
|
||||||
))
|
const iconColor = getFileColor(ext)
|
||||||
}
|
return (
|
||||||
</View>
|
<Pressable
|
||||||
}
|
key={`old-${index}`}
|
||||||
|
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
|
||||||
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={Styles.textDefault} numberOfLines={1}>{item.name}</Text>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
{fileForm.map((item, index) => {
|
||||||
|
const ext = item.name.split('.').pop()?.toLowerCase() ?? ''
|
||||||
|
const baseName = item.name.includes('.') ? item.name.split('.').slice(0, -1).join('.') : item.name
|
||||||
|
const iconName = getFileIcon(ext)
|
||||||
|
const iconColor = getFileColor(ext)
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={`new-${index}`}
|
||||||
|
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
|
||||||
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={Styles.textDefault} numberOfLines={1}>{baseName}</Text>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile.id, indexDelFile.cat) }}
|
onPress={() => deleteFile(indexDelFile.id, indexDelFile.cat)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi";
|
|
||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import BorderBottomItem2 from "@/components/borderBottomItem2";
|
import BorderBottomItem2 from "@/components/borderBottomItem2";
|
||||||
import HeaderRightDiscussionDetail from "@/components/discussion/headerDiscussionDetail";
|
import HeaderRightDiscussionDetail from "@/components/discussion/headerDiscussionDetail";
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import ImageUser from "@/components/imageNew";
|
import ImageUser from "@/components/imageNew";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import LabelStatus from "@/components/labelStatus";
|
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
import Skeleton from "@/components/skeleton";
|
import Skeleton from "@/components/skeleton";
|
||||||
import SkeletonContent from "@/components/skeletonContent";
|
import SkeletonContent from "@/components/skeletonContent";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -23,7 +21,8 @@ import {
|
|||||||
} from "@/lib/api";
|
} from "@/lib/api";
|
||||||
import { getDB } from "@/lib/firebaseDatabase";
|
import { getDB } from "@/lib/firebaseDatabase";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { Feather, Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { Feather, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
||||||
import { ref } from "@react-native-firebase/database";
|
import { ref } from "@react-native-firebase/database";
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
@@ -64,6 +63,7 @@ type PropsFile = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function DiscussionDetail() {
|
export default function DiscussionDetail() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
||||||
const [data, setData] = useState<Props>();
|
const [data, setData] = useState<Props>();
|
||||||
const [dataComment, setDataComment] = useState<PropsComment[]>([]);
|
const [dataComment, setDataComment] = useState<PropsComment[]>([]);
|
||||||
@@ -85,23 +85,15 @@ export default function DiscussionDetail() {
|
|||||||
const [detailMore, setDetailMore] = useState<any>([])
|
const [detailMore, setDetailMore] = useState<any>([])
|
||||||
const entities = useSelector((state: any) => state.entities)
|
const entities = useSelector((state: any) => state.entities)
|
||||||
const [isVisible, setVisible] = useState(false)
|
const [isVisible, setVisible] = useState(false)
|
||||||
const [selectKomentar, setSelectKomentar] = useState({
|
const [selectKomentar, setSelectKomentar] = useState({ id: '', comment: '' })
|
||||||
id: '',
|
|
||||||
comment: ''
|
|
||||||
})
|
|
||||||
const [viewEdit, setViewEdit] = useState(false)
|
const [viewEdit, setViewEdit] = useState(false)
|
||||||
|
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onValueChange = reference.on('value', snapshot => {
|
const onValueChange = reference.on('value', snapshot => {
|
||||||
if (snapshot.val() == null) {
|
if (snapshot.val() == null) { reference.set({ trigger: true }) }
|
||||||
reference.set({ trigger: true })
|
|
||||||
}
|
|
||||||
handleLoadComment(false)
|
handleLoadComment(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Stop listening for updates when no longer required
|
|
||||||
return () => reference.off('value', onValueChange);
|
return () => reference.off('value', onValueChange);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -112,23 +104,12 @@ export default function DiscussionDetail() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function handleLoad(loading: boolean) {
|
async function handleLoad(loading: boolean) {
|
||||||
try {
|
try {
|
||||||
setLoading(loading)
|
setLoading(loading)
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiGetDiscussionOne({
|
const response = await apiGetDiscussionOne({ id: detail, user: hasil, cat: "data" });
|
||||||
id: detail,
|
const responseFile = await apiGetDiscussionOne({ id: detail, user: hasil, cat: "file" });
|
||||||
user: hasil,
|
|
||||||
cat: "data",
|
|
||||||
});
|
|
||||||
|
|
||||||
const responseFile = await apiGetDiscussionOne({
|
|
||||||
id: detail,
|
|
||||||
user: hasil,
|
|
||||||
cat: "file",
|
|
||||||
});
|
|
||||||
|
|
||||||
setData(response.data);
|
setData(response.data);
|
||||||
setFileDiscussion(responseFile.data)
|
setFileDiscussion(responseFile.data)
|
||||||
setIsCreator(response.data.createdBy == hasil);
|
setIsCreator(response.data.createdBy == hasil);
|
||||||
@@ -143,11 +124,7 @@ export default function DiscussionDetail() {
|
|||||||
try {
|
try {
|
||||||
setLoadingKomentar(loading)
|
setLoadingKomentar(loading)
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiGetDiscussionOne({
|
const response = await apiGetDiscussionOne({ id: detail, user: hasil, cat: "comment" });
|
||||||
id: detail,
|
|
||||||
user: hasil,
|
|
||||||
cat: "comment",
|
|
||||||
});
|
|
||||||
setDataComment(response.data);
|
setDataComment(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -159,17 +136,8 @@ export default function DiscussionDetail() {
|
|||||||
async function handleCheckMember() {
|
async function handleCheckMember() {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiGetDivisionOneFeature({
|
const response = await apiGetDivisionOneFeature({ id, user: hasil, cat: "check-member" });
|
||||||
id,
|
const response2 = await apiGetDivisionOneFeature({ id, user: hasil, cat: "check-admin" });
|
||||||
user: hasil,
|
|
||||||
cat: "check-member",
|
|
||||||
});
|
|
||||||
|
|
||||||
const response2 = await apiGetDivisionOneFeature({
|
|
||||||
id,
|
|
||||||
user: hasil,
|
|
||||||
cat: "check-admin",
|
|
||||||
});
|
|
||||||
setIsMemberDivision(response.data);
|
setIsMemberDivision(response.data);
|
||||||
setIsAdminDivision(response2.data);
|
setIsAdminDivision(response2.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -177,30 +145,18 @@ export default function DiscussionDetail() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { handleLoad(false); }, [update.data]);
|
||||||
handleLoad(false);
|
useEffect(() => { handleLoad(true); handleLoadComment(true); handleCheckMember(); }, []);
|
||||||
}, [update.data]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(true)
|
|
||||||
handleLoadComment(true);
|
|
||||||
handleCheckMember();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
async function handleKomentar() {
|
async function handleKomentar() {
|
||||||
try {
|
try {
|
||||||
setLoadingSend(true);
|
setLoadingSend(true);
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiSendDiscussionCommentar({
|
const response = await apiSendDiscussionCommentar({ id: detail, data: { comment: komentar, user: hasil } });
|
||||||
id: detail,
|
if (response.success) { setKomentar(""); updateTrigger() }
|
||||||
data: { comment: komentar, user: hasil },
|
} catch (error: any) {
|
||||||
});
|
|
||||||
if (response.success) {
|
|
||||||
setKomentar("")
|
|
||||||
updateTrigger()
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal menambahkan komentar" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingSend(false);
|
setLoadingSend(false);
|
||||||
}
|
}
|
||||||
@@ -210,17 +166,11 @@ export default function DiscussionDetail() {
|
|||||||
try {
|
try {
|
||||||
setLoadingSend(true);
|
setLoadingSend(true);
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiEditDiscussionCommentar({
|
const response = await apiEditDiscussionCommentar({ id: selectKomentar.id, data: { comment: selectKomentar.comment, user: hasil } });
|
||||||
id: selectKomentar.id,
|
if (response.success) { updateTrigger() } else { Toast.show({ type: 'small', text1: response.message }) }
|
||||||
data: { comment: selectKomentar.comment, user: hasil },
|
} catch (error: any) {
|
||||||
});
|
|
||||||
if (response.success) {
|
|
||||||
updateTrigger()
|
|
||||||
} else {
|
|
||||||
Toast.show({ type: 'small', text1: response.message })
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal mengedit komentar" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingSend(false);
|
setLoadingSend(false);
|
||||||
handleViewEditKomentar()
|
handleViewEditKomentar()
|
||||||
@@ -231,17 +181,11 @@ export default function DiscussionDetail() {
|
|||||||
try {
|
try {
|
||||||
setLoadingSend(true);
|
setLoadingSend(true);
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiDeleteDiscussionCommentar({
|
const response = await apiDeleteDiscussionCommentar({ id: selectKomentar.id, data: { user: hasil } });
|
||||||
id: selectKomentar.id,
|
if (response.success) { updateTrigger() } else { Toast.show({ type: 'small', text1: response.message }) }
|
||||||
data: { user: hasil },
|
} catch (error: any) {
|
||||||
});
|
|
||||||
if (response.success) {
|
|
||||||
updateTrigger()
|
|
||||||
} else {
|
|
||||||
Toast.show({ type: 'small', text1: response.message })
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal menghapus komentar" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingSend(false)
|
setLoadingSend(false)
|
||||||
setVisible(false)
|
setVisible(false)
|
||||||
@@ -253,13 +197,11 @@ export default function DiscussionDetail() {
|
|||||||
setVisible(true)
|
setVisible(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleViewEditKomentar() {
|
function handleViewEditKomentar() {
|
||||||
setVisible(false)
|
setVisible(false)
|
||||||
setViewEdit(!viewEdit)
|
setViewEdit(!viewEdit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleLoad(false)
|
handleLoad(false)
|
||||||
@@ -268,288 +210,205 @@ export default function DiscussionDetail() {
|
|||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const canWrite = data?.status != 2 && data?.isActive && ((entityUser.role != "user" && entityUser.role != "coadmin") || isMemberDivision)
|
||||||
|
const isOpen = data?.status === 1
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
|
||||||
// <ButtonBackHeader
|
|
||||||
// onPress={() => {
|
|
||||||
// router.back();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
headerTitle: "Diskusi",
|
headerTitle: "Diskusi",
|
||||||
headerTitleAlign: "center",
|
headerTitleAlign: "center",
|
||||||
// headerRight: () =>
|
|
||||||
// (entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision || isCreator ?
|
|
||||||
// <HeaderRightDiscussionDetail
|
|
||||||
// id={detail}
|
|
||||||
// status={data?.status}
|
|
||||||
// isActive={data?.isActive}
|
|
||||||
// /> : (<></>)
|
|
||||||
// ,
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Diskusi"
|
title="Diskusi"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={
|
right={
|
||||||
(entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision || isCreator ?
|
((entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision || isCreator) ?
|
||||||
<HeaderRightDiscussionDetail
|
<HeaderRightDiscussionDetail id={detail} status={data?.status} isActive={data?.isActive} /> : undefined
|
||||||
id={detail}
|
|
||||||
status={data?.status}
|
|
||||||
isActive={data?.isActive}
|
|
||||||
/> : (<></>)
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={{ flex: 1 }}>
|
<View style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
refreshControl={
|
showsVerticalScrollIndicator={false}
|
||||||
<RefreshControl
|
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} tintColor={colors.icon} />}
|
||||||
refreshing={refreshing}
|
|
||||||
onRefresh={handleRefresh}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15]}>
|
||||||
{
|
{loading ? (
|
||||||
loading ?
|
<SkeletonContent />
|
||||||
<SkeletonContent />
|
) : (
|
||||||
:
|
<BorderBottomItem2
|
||||||
<BorderBottomItem2
|
dataFile={fileDiscussion}
|
||||||
dataFile={fileDiscussion}
|
descEllipsize={false}
|
||||||
descEllipsize={false}
|
borderType="all"
|
||||||
borderType="bottom"
|
bgColor="white"
|
||||||
icon={
|
icon={
|
||||||
<ImageUser
|
<ImageUser src={`${ConstEnv.url_storage}/files/${data?.user_img}`} size="sm" />
|
||||||
src={`${ConstEnv.url_storage}/files/${data?.user_img}`}
|
}
|
||||||
size="sm"
|
title={data?.username}
|
||||||
/>
|
titleShowAll={true}
|
||||||
}
|
subtitle={
|
||||||
title={data?.username}
|
<View style={[Styles.discussionStatusPill, {
|
||||||
subtitle={
|
borderColor: !data?.isActive ? '#F59E0B' : isOpen ? '#10B981' : colors.dimmed + '80',
|
||||||
data?.isActive ? (
|
}]}>
|
||||||
data?.status == 1 ? (
|
<Text style={[Styles.discussionStatusText, {
|
||||||
<LabelStatus category="success" text="BUKA" size="small" />
|
color: !data?.isActive ? '#F59E0B' : isOpen ? '#10B981' : colors.dimmed,
|
||||||
) : (
|
}]}>
|
||||||
<LabelStatus category="error" text="TUTUP" size="small" />
|
{!data?.isActive ? 'Arsip' : isOpen ? 'Buka' : 'Tutup'}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
}
|
||||||
|
desc={data?.desc}
|
||||||
|
leftBottomInfo={
|
||||||
|
<View style={Styles.rowItemsCenter}>
|
||||||
|
<Feather name="message-square" size={14} color={colors.dimmed} style={Styles.mr05} />
|
||||||
|
<Text style={[Styles.textInformation, { color: colors.dimmed }]}>{dataComment.length} Komentar</Text>
|
||||||
|
</View>
|
||||||
|
}
|
||||||
|
rightBottomInfo={<Text style={[Styles.textInformation, { color: colors.dimmed }]}>{data?.createdAt}</Text>}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<View style={Styles.mt10}>
|
||||||
|
{loadingKomentar ? (
|
||||||
|
arrSkeleton.map((_, i) => (
|
||||||
|
<Skeleton key={i} width={100} widthType="percent" height={40} borderRadius={5} />
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
dataComment.map((item, i) => (
|
||||||
|
<Pressable
|
||||||
|
key={i}
|
||||||
|
onPress={() => {
|
||||||
|
setDetailMore((prev: any) =>
|
||||||
|
prev.includes(item.id) ? prev.filter((id: string) => id !== item.id) : [...prev, item.id]
|
||||||
)
|
)
|
||||||
) : (
|
}}
|
||||||
<LabelStatus category="secondary" text="ARSIP" size="small" />
|
onLongPress={() => {
|
||||||
)
|
item.idUser == entities.id && data?.status != 2 && data?.isActive && handleMenuKomentar(item.id, item.comment)
|
||||||
}
|
}}
|
||||||
rightTopInfo={data?.createdAt}
|
style={({ pressed }) => [
|
||||||
desc={data?.desc}
|
Styles.discussionCommentCard,
|
||||||
leftBottomInfo={
|
{ backgroundColor: pressed ? colors.icon + '10' : colors.card, borderColor: colors.icon + '20' }
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
]}
|
||||||
<Ionicons
|
>
|
||||||
name="chatbox-ellipses-outline"
|
<View style={Styles.flex1}>
|
||||||
size={18}
|
<View style={[Styles.rowSpaceBetween, Styles.itemsCenter, Styles.mb05]}>
|
||||||
color="grey"
|
<View style={[Styles.rowItemsCenter, { gap: 8, flex: 1, marginRight: 8 }]}>
|
||||||
style={Styles.mr05}
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
|
||||||
/>
|
<Text style={[Styles.textMediumSemiBold, { color: colors.text }]} numberOfLines={1}>
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]} >
|
{item.username}
|
||||||
{dataComment.length} Komentar
|
</Text>
|
||||||
|
{item.isEdited && (
|
||||||
|
<Text style={[Styles.discussionEditedText, { color: colors.dimmed }]}>diedit</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.discussionDateText, { color: colors.dimmed, flexShrink: 0 }]}>
|
||||||
|
{item.createdAt}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.textDefault, { color: colors.text }]} numberOfLines={detailMore.includes(item.id) ? 0 : 3}>
|
||||||
|
{item.comment}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
}
|
</Pressable>
|
||||||
/>
|
))
|
||||||
}
|
)}
|
||||||
|
|
||||||
<View style={[Styles.p15]}>
|
|
||||||
{
|
|
||||||
loadingKomentar ?
|
|
||||||
arrSkeleton.map((item, index) => (
|
|
||||||
<Skeleton key={index} width={100} widthType="percent" height={40} borderRadius={5} />
|
|
||||||
))
|
|
||||||
:
|
|
||||||
dataComment.map((item, index) => (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={index}
|
|
||||||
borderType="bottom"
|
|
||||||
colorPress
|
|
||||||
icon={
|
|
||||||
<ImageUser
|
|
||||||
src={`${ConstEnv.url_storage}/files/${item.img}`}
|
|
||||||
size="xs"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
title={item.username}
|
|
||||||
rightTopInfo={item.createdAt}
|
|
||||||
desc={item.comment}
|
|
||||||
rightBottomInfo={item.isEdited ? "Edited" : ""}
|
|
||||||
descEllipsize={detailMore.includes(item.id) ? false : true}
|
|
||||||
onPress={() => {
|
|
||||||
setDetailMore((prev: any) => {
|
|
||||||
if (prev.includes(item.id)) {
|
|
||||||
return prev.filter((id: string) => id !== item.id)
|
|
||||||
} else {
|
|
||||||
return [...prev, item.id]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
onLongPress={() => {
|
|
||||||
item.idUser == entities.id && data?.status != 2 && data?.isActive && handleMenuKomentar(item.id, item.comment)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<KeyboardAvoidingView
|
|
||||||
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
|
||||||
keyboardVerticalOffset={headerHeight}
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
style={[
|
|
||||||
Styles.contentItemCenter,
|
|
||||||
Styles.w100,
|
|
||||||
{ backgroundColor: "#f4f4f4" },
|
|
||||||
viewEdit && Styles.borderTop
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{
|
|
||||||
viewEdit ?
|
|
||||||
<>
|
|
||||||
<View style={[Styles.w90, Styles.rowSpaceBetween, Styles.pv05]}>
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Feather name="edit-3" color="black" size={22} style={[Styles.mh05]} />
|
|
||||||
<Text style={[Styles.textMediumSemiBold]}>Edit Komentar</Text>
|
|
||||||
</View>
|
|
||||||
<Pressable onPress={() => handleViewEditKomentar()}>
|
|
||||||
<MaterialIcons name="close" color="black" size={22} />
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
|
||||||
<InputForm
|
|
||||||
bg="white"
|
|
||||||
type="default"
|
|
||||||
round
|
|
||||||
multiline
|
|
||||||
placeholder="Kirim Komentar"
|
|
||||||
onChange={(val: string) => setSelectKomentar({ ...selectKomentar, comment: val })}
|
|
||||||
value={selectKomentar.comment}
|
|
||||||
itemRight={
|
|
||||||
<Pressable
|
|
||||||
onPress={() => {
|
|
||||||
selectKomentar.comment != "" &&
|
|
||||||
!regexOnlySpacesOrEnter.test(selectKomentar.comment) &&
|
|
||||||
!loadingSend &&
|
|
||||||
data?.status != 2 &&
|
|
||||||
data?.isActive &&
|
|
||||||
(((entityUser.role == "user" ||
|
|
||||||
entityUser.role == "coadmin") &&
|
|
||||||
isMemberDivision) ||
|
|
||||||
entityUser.role == "admin" ||
|
|
||||||
entityUser.role == "supadmin" ||
|
|
||||||
entityUser.role == "developer" ||
|
|
||||||
entityUser.role == "cosupadmin") &&
|
|
||||||
handleEditKomentar();
|
|
||||||
}}
|
|
||||||
style={[
|
|
||||||
Platform.OS == 'android' && Styles.mb12,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<MaterialIcons
|
|
||||||
name="send"
|
|
||||||
size={25}
|
|
||||||
style={
|
|
||||||
[selectKomentar.comment == "" || regexOnlySpacesOrEnter.test(selectKomentar.comment) || loadingSend || ((entityUser.role == "user" || entityUser.role == "coadmin") && !isMemberDivision)
|
|
||||||
? Styles.cGray
|
|
||||||
: Styles.cDefault,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Pressable>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
:
|
|
||||||
data?.status != 2 && data?.isActive && ((entityUser.role != "user" && entityUser.role != "coadmin") ||
|
|
||||||
isMemberDivision)
|
|
||||||
?
|
|
||||||
<InputForm
|
|
||||||
bg="white"
|
|
||||||
type="default"
|
|
||||||
round
|
|
||||||
multiline
|
|
||||||
placeholder="Kirim Komentar"
|
|
||||||
onChange={setKomentar}
|
|
||||||
value={komentar}
|
|
||||||
itemRight={
|
|
||||||
<Pressable
|
|
||||||
onPress={() => {
|
|
||||||
komentar != "" &&
|
|
||||||
!regexOnlySpacesOrEnter.test(komentar) &&
|
|
||||||
!loadingSend &&
|
|
||||||
data?.status != 2 &&
|
|
||||||
data?.isActive &&
|
|
||||||
(((entityUser.role == "user" ||
|
|
||||||
entityUser.role == "coadmin") &&
|
|
||||||
isMemberDivision) ||
|
|
||||||
entityUser.role == "admin" ||
|
|
||||||
entityUser.role == "supadmin" ||
|
|
||||||
entityUser.role == "developer" ||
|
|
||||||
entityUser.role == "cosupadmin") &&
|
|
||||||
handleKomentar();
|
|
||||||
}}
|
|
||||||
style={[
|
|
||||||
Platform.OS == 'android' && Styles.mb12,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<MaterialIcons
|
|
||||||
name="send"
|
|
||||||
size={25}
|
|
||||||
style={
|
|
||||||
[komentar == "" || regexOnlySpacesOrEnter.test(komentar) || loadingSend || ((entityUser.role == "user" || entityUser.role == "coadmin") && !isMemberDivision)
|
|
||||||
? Styles.cGray
|
|
||||||
: Styles.cDefault,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Pressable>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
:
|
|
||||||
<View style={[Styles.pv20, { alignItems: 'center' }]}>
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray]}>
|
|
||||||
{
|
|
||||||
data?.status == 2 ? "Diskusi telah ditutup" : data?.isActive == false ? "Diskusi telah diarsipkan" : "Hanya anggota divisi yang dapat memberikan komentar"
|
|
||||||
}
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
|
|
||||||
|
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} keyboardVerticalOffset={headerHeight}>
|
||||||
|
<View style={[Styles.contentItemCenter, Styles.w100, { backgroundColor: colors.background }, viewEdit && Styles.borderTop]}>
|
||||||
|
{viewEdit ? (
|
||||||
|
<>
|
||||||
|
<View style={[Styles.w90, Styles.rowSpaceBetween, Styles.pv05]}>
|
||||||
|
<View style={Styles.rowItemsCenter}>
|
||||||
|
<Feather name="edit-3" color={colors.text} size={22} style={Styles.mh05} />
|
||||||
|
<Text style={Styles.textMediumSemiBold}>Edit Komentar</Text>
|
||||||
|
</View>
|
||||||
|
<Pressable onPress={() => handleViewEditKomentar()}>
|
||||||
|
<MaterialIcons name="close" color={colors.text} size={22} />
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
<InputForm
|
||||||
|
bg={colors.card}
|
||||||
|
type="default" round multiline
|
||||||
|
placeholder="Kirim Komentar"
|
||||||
|
onChange={(val: string) => setSelectKomentar({ ...selectKomentar, comment: val })}
|
||||||
|
value={selectKomentar.comment}
|
||||||
|
itemRight={
|
||||||
|
<Pressable
|
||||||
|
onPress={() => {
|
||||||
|
selectKomentar.comment != "" && !regexOnlySpacesOrEnter.test(selectKomentar.comment) && !loadingSend && data?.status != 2 && data?.isActive
|
||||||
|
&& (((entityUser.role == "user" || entityUser.role == "coadmin") && isMemberDivision) || entityUser.role == "admin" || entityUser.role == "supadmin" || entityUser.role == "developer" || entityUser.role == "cosupadmin")
|
||||||
|
&& handleEditKomentar();
|
||||||
|
}}
|
||||||
|
style={[Platform.OS == 'android' && Styles.mb12]}
|
||||||
|
>
|
||||||
|
<MaterialIcons name="send" size={25}
|
||||||
|
style={[
|
||||||
|
selectKomentar.comment == "" || regexOnlySpacesOrEnter.test(selectKomentar.comment) || loadingSend || ((entityUser.role == "user" || entityUser.role == "coadmin") && !isMemberDivision)
|
||||||
|
? { color: colors.dimmed } : { color: colors.tint },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : canWrite ? (
|
||||||
|
<InputForm
|
||||||
|
type="default" round multiline
|
||||||
|
placeholder="Kirim Komentar"
|
||||||
|
onChange={setKomentar} value={komentar}
|
||||||
|
itemRight={
|
||||||
|
<Pressable
|
||||||
|
onPress={() => {
|
||||||
|
komentar != "" && !regexOnlySpacesOrEnter.test(komentar) && !loadingSend && data?.status != 2 && data?.isActive
|
||||||
|
&& (((entityUser.role == "user" || entityUser.role == "coadmin") && isMemberDivision) || entityUser.role == "admin" || entityUser.role == "supadmin" || entityUser.role == "developer" || entityUser.role == "cosupadmin")
|
||||||
|
&& handleKomentar();
|
||||||
|
}}
|
||||||
|
style={[Platform.OS == 'android' && Styles.mb12]}
|
||||||
|
>
|
||||||
|
<MaterialIcons name="send" size={25}
|
||||||
|
style={[
|
||||||
|
komentar == "" || regexOnlySpacesOrEnter.test(komentar) || loadingSend || ((entityUser.role == "user" || entityUser.role == "coadmin") && !isMemberDivision)
|
||||||
|
? { color: colors.dimmed } : { color: colors.tint },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<View style={[Styles.pv20, Styles.itemsCenter]}>
|
||||||
|
<Text style={[Styles.textInformation, { color: colors.dimmed }]}>
|
||||||
|
{data?.status == 2 ? "Diskusi telah ditutup" : data?.isActive == false ? "Diskusi telah diarsipkan" : "Hanya anggota divisi yang dapat memberikan komentar"}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
</KeyboardAvoidingView>
|
</KeyboardAvoidingView>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Komentar">
|
<DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Komentar">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow icon={<MaterialCommunityIcons name="pencil-outline" color={colors.text} size={25} />} title="Edit" onPress={() => handleViewEditKomentar()} />
|
||||||
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
|
<MenuItemRow icon={<MaterialIcons name="delete-outline" color={colors.text} size={25} />} title="Hapus" onPress={() => { setVisible(false); setTimeout(() => setShowDeleteModal(true), 600) }} />
|
||||||
title="Edit"
|
|
||||||
onPress={() => { handleViewEditKomentar() }}
|
|
||||||
/>
|
|
||||||
<MenuItemRow
|
|
||||||
icon={<MaterialIcons name="delete" color="black" size={25} />}
|
|
||||||
title="Hapus"
|
|
||||||
onPress={() => {
|
|
||||||
AlertKonfirmasi({
|
|
||||||
title: 'Konfirmasi',
|
|
||||||
desc: 'Apakah anda yakin ingin menghapus komentar?',
|
|
||||||
onPress: () => {
|
|
||||||
handleDeleteKomentar()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message="Apakah anda yakin ingin menghapus komentar?"
|
||||||
|
onConfirm={() => { setShowDeleteModal(false); handleDeleteKomentar() }}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText="Hapus"
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,45 @@
|
|||||||
import AppHeader from "@/components/AppHeader"
|
import AppHeader from "@/components/AppHeader"
|
||||||
import BorderBottomItem from "@/components/borderBottomItem"
|
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader"
|
import ButtonSaveHeader from "@/components/buttonSaveHeader"
|
||||||
import ButtonSelect from "@/components/buttonSelect"
|
|
||||||
import DrawerBottom from "@/components/drawerBottom"
|
import DrawerBottom from "@/components/drawerBottom"
|
||||||
import { InputForm } from "@/components/inputForm"
|
import { InputForm } from "@/components/inputForm"
|
||||||
import LoadingOverlay from "@/components/loadingOverlay"
|
import LoadingCenter from "@/components/loadingCenter"
|
||||||
import MenuItemRow from "@/components/menuItemRow"
|
import MenuItemRow from "@/components/menuItemRow"
|
||||||
import Text from "@/components/Text"
|
import Text from "@/components/Text"
|
||||||
import Styles from "@/constants/Styles"
|
import Styles from "@/constants/Styles"
|
||||||
import { apiCreateDiscussion } from "@/lib/api"
|
import { apiCreateDiscussion } from "@/lib/api"
|
||||||
import { setUpdateDiscussion } from "@/lib/discussionUpdate"
|
import { setUpdateDiscussion } from "@/lib/discussionUpdate"
|
||||||
import { useAuthSession } from "@/providers/AuthProvider"
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider"
|
||||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"
|
||||||
import * as DocumentPicker from "expo-document-picker"
|
import * as DocumentPicker from "expo-document-picker"
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router"
|
import { router, Stack, useLocalSearchParams } from "expo-router"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native"
|
import { Pressable, SafeAreaView, ScrollView, View } from "react-native"
|
||||||
import Toast from "react-native-toast-message"
|
import Toast from "react-native-toast-message"
|
||||||
import { useDispatch, useSelector } from "react-redux"
|
import { useDispatch, useSelector } from "react-redux"
|
||||||
|
|
||||||
|
function getFileIcon(ext: string): keyof typeof MaterialCommunityIcons.glyphMap {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return 'image-outline'
|
||||||
|
if (ext === 'pdf') return 'file-pdf-box'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return 'video-outline'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return 'file-word-outline'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return 'file-excel-outline'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return 'zip-box-outline'
|
||||||
|
return 'file-outline'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileColor(ext: string): string {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return '#339AF0'
|
||||||
|
if (ext === 'pdf') return '#F03E3E'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return '#AE3EC9'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return '#1C7ED6'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return '#2F9E44'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return '#E8590C'
|
||||||
|
return '#868E96'
|
||||||
|
}
|
||||||
|
|
||||||
export default function CreateDiscussionDivision() {
|
export default function CreateDiscussionDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [desc, setDesc] = useState('')
|
const [desc, setDesc] = useState('')
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
@@ -32,74 +51,55 @@ export default function CreateDiscussionDivision() {
|
|||||||
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
const [indexDelFile, setIndexDelFile] = useState<number>(0)
|
||||||
|
|
||||||
const pickDocumentAsync = async () => {
|
const pickDocumentAsync = async () => {
|
||||||
let result = await DocumentPicker.getDocumentAsync({
|
const result = await DocumentPicker.getDocumentAsync({ type: ["*/*"], multiple: true });
|
||||||
type: ["*/*"],
|
|
||||||
multiple: true
|
|
||||||
});
|
|
||||||
if (!result.canceled) {
|
if (!result.canceled) {
|
||||||
for (let i = 0; i < result.assets?.length; i++) {
|
let skipped = 0
|
||||||
if (result.assets[i].uri) {
|
for (const asset of result.assets) {
|
||||||
setFileForm((prev) => [...prev, result.assets[i]])
|
if (!asset.uri) continue
|
||||||
|
if (fileForm.some(f => f.name === asset.name)) {
|
||||||
|
skipped++
|
||||||
|
} else {
|
||||||
|
setFileForm(prev => [...prev, asset])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (skipped > 0) Toast.show({ type: 'small', text1: 'Beberapa file sudah ditambahkan' })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function deleteFile(index: number) {
|
function deleteFile(index: number) {
|
||||||
setFileForm([...fileForm.filter((val, i) => i !== index)])
|
setFileForm(fileForm.filter((_, i) => i !== index))
|
||||||
setModalFile(false)
|
setModalFile(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function handleCreate() {
|
async function handleCreate() {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const fd = new FormData()
|
const fd = new FormData()
|
||||||
|
|
||||||
for (let i = 0; i < fileForm.length; i++) {
|
for (let i = 0; i < fileForm.length; i++) {
|
||||||
fd.append(`file${i}`, {
|
fd.append(`file${i}`, { uri: fileForm[i].uri, type: 'application/octet-stream', name: fileForm[i].name } as any);
|
||||||
uri: fileForm[i].uri,
|
|
||||||
type: 'application/octet-stream',
|
|
||||||
name: fileForm[i].name,
|
|
||||||
} as any);
|
|
||||||
}
|
}
|
||||||
|
fd.append("data", JSON.stringify({ user: hasil, desc, idDivision: id }))
|
||||||
fd.append("data", JSON.stringify(
|
|
||||||
{ user: hasil, desc, idDivision: id }
|
|
||||||
))
|
|
||||||
|
|
||||||
const response = await apiCreateDiscussion(fd)
|
const response = await apiCreateDiscussion(fd)
|
||||||
|
|
||||||
// const response = await apiCreateDiscussion({ data: { user: hasil, desc, idDivision: id } })
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data' })
|
||||||
dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
|
dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
|
||||||
router.back()
|
router.back()
|
||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal menambahkan data" })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Tambah Diskusi',
|
|
||||||
headerTitleAlign: 'center',
|
|
||||||
// headerRight: () => <ButtonSaveHeader
|
|
||||||
// disable={desc == "" || loading}
|
|
||||||
// category="create"
|
|
||||||
// onPress={() => {
|
|
||||||
// handleCreate()
|
|
||||||
// }} />
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Tambah Diskusi"
|
title="Tambah Diskusi"
|
||||||
@@ -109,16 +109,15 @@ export default function CreateDiscussionDivision() {
|
|||||||
<ButtonSaveHeader
|
<ButtonSaveHeader
|
||||||
disable={desc == "" || loading}
|
disable={desc == "" || loading}
|
||||||
category="create"
|
category="create"
|
||||||
onPress={() => {
|
onPress={() => handleCreate()}
|
||||||
handleCreate()
|
/>
|
||||||
}} />
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<LoadingOverlay visible={loading} />
|
{loading && <LoadingCenter />}
|
||||||
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Diskusi"
|
label="Diskusi"
|
||||||
@@ -127,39 +126,70 @@ export default function CreateDiscussionDivision() {
|
|||||||
required
|
required
|
||||||
onChange={setDesc}
|
onChange={setDesc}
|
||||||
multiline
|
multiline
|
||||||
|
bg={colors.card}
|
||||||
/>
|
/>
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
|
||||||
{
|
{/* File */}
|
||||||
fileForm.length > 0
|
<View style={[Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
&&
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10]}>
|
<Pressable
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
|
onPress={pickDocumentAsync}
|
||||||
{
|
style={[Styles.sectionActionRow, { marginBottom: fileForm.length > 0 ? 12 : 0 }]}
|
||||||
fileForm.map((item, index) => (
|
>
|
||||||
<BorderBottomItem
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '15' }]}>
|
||||||
key={index}
|
<MaterialCommunityIcons name="paperclip" size={18} color={colors.dimmed} />
|
||||||
borderType={fileForm.length > 1 ? "bottom" : "none"}
|
</View>
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
<View style={Styles.flex1}>
|
||||||
title={item.name}
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>File</Text>
|
||||||
titleWeight="normal"
|
{fileForm.length === 0 && (
|
||||||
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Opsional — ketuk untuk upload</Text>
|
||||||
/>
|
)}
|
||||||
))
|
</View>
|
||||||
}
|
{fileForm.length > 0 && (
|
||||||
</View>
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
}
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{fileForm.length} file</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{fileForm.length > 0 && (
|
||||||
|
<View style={Styles.fileGrid}>
|
||||||
|
{fileForm.map((item, index) => {
|
||||||
|
const ext = item.name.split('.').pop()?.toLowerCase() ?? ''
|
||||||
|
const baseName = item.name.includes('.') ? item.name.split('.').slice(0, -1).join('.') : item.name
|
||||||
|
const iconName = getFileIcon(ext)
|
||||||
|
const iconColor = getFileColor(ext)
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={index}
|
||||||
|
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
|
||||||
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={Styles.textDefault} numberOfLines={1}>{baseName}</Text>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModalFile} setVisible={setModalFile} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile) }}
|
onPress={() => deleteFile(indexDelFile)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
import ButtonTab from "@/components/buttonTab";
|
import ButtonTab from "@/components/buttonTab";
|
||||||
import ImageUser from "@/components/imageNew";
|
import ImageUser from "@/components/imageNew";
|
||||||
import InputSearch from "@/components/inputSearch";
|
import InputSearch from "@/components/inputSearch";
|
||||||
import LabelStatus from "@/components/labelStatus";
|
|
||||||
import SkeletonContent from "@/components/skeletonContent";
|
import SkeletonContent from "@/components/skeletonContent";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
|
import WrapTab from "@/components/wrapTab";
|
||||||
import { ConstEnv } from "@/constants/ConstEnv";
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetDiscussion, apiGetDivisionOneFeature } from "@/lib/api";
|
import { apiGetDiscussion, apiGetDivisionOneFeature } from "@/lib/api";
|
||||||
|
import { GUIDE_DIVISION_DISCUSSION } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { AntDesign, Feather, Ionicons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { AntDesign, Feather } from "@expo/vector-icons";
|
||||||
import { router, useLocalSearchParams } from "expo-router";
|
import { router, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { RefreshControl, View, VirtualizedList } from "react-native";
|
import { FlatList, Pressable, RefreshControl, View } from "react-native";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: string,
|
id: string,
|
||||||
title: string,
|
title: string,
|
||||||
@@ -28,8 +30,8 @@ type Props = {
|
|||||||
isActive: boolean
|
isActive: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default function DiscussionDivision() {
|
export default function DiscussionDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id, active } = useLocalSearchParams<{ id: string, active?: string }>()
|
const { id, active } = useLocalSearchParams<{ id: string, active?: string }>()
|
||||||
const [data, setData] = useState<Props[]>([])
|
const [data, setData] = useState<Props[]>([])
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
@@ -44,21 +46,13 @@ export default function DiscussionDivision() {
|
|||||||
const [isMemberDivision, setIsMemberDivision] = useState(false)
|
const [isMemberDivision, setIsMemberDivision] = useState(false)
|
||||||
const [isAdminDivision, setIsAdminDivision] = useState(false)
|
const [isAdminDivision, setIsAdminDivision] = useState(false)
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('division-discussion')
|
||||||
|
|
||||||
async function handleCheckMember() {
|
async function handleCheckMember() {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiGetDivisionOneFeature({
|
const response = await apiGetDivisionOneFeature({ id, user: hasil, cat: "check-member" });
|
||||||
id,
|
const response2 = await apiGetDivisionOneFeature({ id, user: hasil, cat: "check-admin" });
|
||||||
user: hasil,
|
|
||||||
cat: "check-member",
|
|
||||||
});
|
|
||||||
|
|
||||||
const response2 = await apiGetDivisionOneFeature({
|
|
||||||
id,
|
|
||||||
user: hasil,
|
|
||||||
cat: "check-admin",
|
|
||||||
});
|
|
||||||
setIsMemberDivision(response.data);
|
setIsMemberDivision(response.data);
|
||||||
setIsAdminDivision(response2.data);
|
setIsAdminDivision(response2.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -77,8 +71,6 @@ export default function DiscussionDivision() {
|
|||||||
setData(response.data)
|
setData(response.data)
|
||||||
} else if (thisPage > 1 && response.data.length > 0) {
|
} else if (thisPage > 1 && response.data.length > 0) {
|
||||||
setData([...data, ...response.data])
|
setData([...data, ...response.data])
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
@@ -88,26 +80,15 @@ export default function DiscussionDivision() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { handleLoad(false, 1) }, [update.data])
|
||||||
handleLoad(false, 1)
|
useEffect(() => { handleLoad(true, 1) }, [status, search])
|
||||||
}, [update.data])
|
useEffect(() => { handleCheckMember() }, [])
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(true, 1)
|
|
||||||
}, [status, search])
|
|
||||||
|
|
||||||
const loadMoreData = () => {
|
const loadMoreData = () => {
|
||||||
if (waiting) return
|
if (waiting) return
|
||||||
setTimeout(() => {
|
setTimeout(() => { handleLoad(false, page + 1) }, 1000);
|
||||||
handleLoad(false, page + 1)
|
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleCheckMember()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleLoad(false, 1)
|
handleLoad(false, 1)
|
||||||
@@ -115,98 +96,115 @@ export default function DiscussionDivision() {
|
|||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
const getItem = (_data: unknown, index: number): Props => ({
|
const isOpen = (item: Props) => item.status === 1
|
||||||
id: data[index].id,
|
|
||||||
title: data[index].title,
|
const themed = {
|
||||||
desc: data[index].desc,
|
background: { backgroundColor: colors.background },
|
||||||
status: data[index].status,
|
card: { backgroundColor: colors.card, borderColor: colors.icon + '20' },
|
||||||
user_name: data[index].user_name,
|
cardPressed: { backgroundColor: colors.icon + '10' },
|
||||||
img: data[index].img,
|
title: { color: colors.text },
|
||||||
total_komentar: data[index].total_komentar,
|
dimmed: { color: colors.dimmed },
|
||||||
createdAt: data[index].createdAt,
|
statusOpen: { borderColor: '#10B981' as const },
|
||||||
isActive: data[index].isActive,
|
statusClosed: { borderColor: colors.dimmed + '80' },
|
||||||
})
|
statusTextOpen: { color: '#10B981' as const },
|
||||||
|
statusTextClosed: { color: colors.dimmed },
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.flex1, themed.background]}>
|
||||||
{
|
<GuideOverlay visible={guideVisible} steps={GUIDE_DIVISION_DISCUSSION} onDismiss={dismissGuide} />
|
||||||
((entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision) &&
|
{((entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision) && (
|
||||||
<View>
|
<View style={[Styles.ph15, Styles.discussionHeaderPadding]}>
|
||||||
<View style={[Styles.wrapBtnTab]}>
|
<WrapTab>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="true"
|
value="true"
|
||||||
onPress={() => { setStatus("true") }}
|
onPress={() => setStatus("true")}
|
||||||
label="Aktif"
|
label="Aktif"
|
||||||
icon={<Feather name="check-circle" color={status == "false" ? 'black' : 'white'} size={20} />}
|
icon={<Feather name="check-circle" color={status == "false" ? colors.dimmed : 'white'} size={20} />}
|
||||||
n={2} />
|
n={2}
|
||||||
|
/>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="false"
|
value="false"
|
||||||
onPress={() => { setStatus("false") }}
|
onPress={() => setStatus("false")}
|
||||||
label="Arsip"
|
label="Arsip"
|
||||||
icon={<AntDesign name="closecircleo" color={status == "true" ? 'black' : 'white'} size={20} />}
|
icon={<AntDesign name="closecircleo" color={status == "true" ? colors.dimmed : 'white'} size={20} />}
|
||||||
n={2} />
|
n={2}
|
||||||
</View>
|
/>
|
||||||
|
</WrapTab>
|
||||||
<InputSearch onChange={setSearch} />
|
<InputSearch onChange={setSearch} />
|
||||||
</View>
|
</View>
|
||||||
}
|
)}
|
||||||
|
|
||||||
|
<View style={[Styles.flex1, Styles.ph15, Styles.discussionListPadding]}>
|
||||||
|
{loading ? (
|
||||||
|
arrSkeleton.map((_, i) => <SkeletonContent key={i} />)
|
||||||
|
) : data.length === 0 ? (
|
||||||
|
<View style={[Styles.contentItemCenter, Styles.mt30]}>
|
||||||
|
<Feather name="message-circle" size={42} color={colors.icon + '40'} />
|
||||||
|
<Text style={[Styles.mt10, Styles.discussionEmptyText, themed.dimmed]}>
|
||||||
|
Tidak ada diskusi
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<FlatList
|
||||||
|
data={data}
|
||||||
|
keyExtractor={(_, i) => String(i)}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
onEndReached={loadMoreData}
|
||||||
|
onEndReachedThreshold={0.5}
|
||||||
|
refreshControl={
|
||||||
|
<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} tintColor={colors.icon} />
|
||||||
|
}
|
||||||
|
ItemSeparatorComponent={() => <View style={Styles.discussionSeparator} />}
|
||||||
|
renderItem={({ item }: { item: Props }) => (
|
||||||
|
<Pressable
|
||||||
|
onPress={() => router.push(`./discussion/${item.id}`)}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
Styles.discussionCard,
|
||||||
|
themed.card,
|
||||||
|
pressed && themed.cardPressed,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.rowItemsCenter, Styles.mb08]}>
|
||||||
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
|
||||||
|
<View style={[Styles.flex1, Styles.discussionTitleCol]}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, themed.title]} numberOfLines={1}>
|
||||||
|
{item.user_name}
|
||||||
|
</Text>
|
||||||
|
{status === "true" && (
|
||||||
|
<View style={[Styles.discussionStatusPill, isOpen(item) ? themed.statusOpen : themed.statusClosed]}>
|
||||||
|
<Text style={[Styles.discussionStatusText, isOpen(item) ? themed.statusTextOpen : themed.statusTextClosed]}>
|
||||||
|
{isOpen(item) ? 'Buka' : 'Tutup'}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
<View style={[{ flex: 2 }, Styles.mt05]}>
|
{item.desc ? (
|
||||||
{
|
<Text style={[Styles.textMediumNormal, Styles.discussionCardIndent, Styles.discussionDescMargin, themed.title]} numberOfLines={2}>
|
||||||
loading ?
|
{item.desc}
|
||||||
arrSkeleton.map((item: any, i: number) => {
|
</Text>
|
||||||
return (
|
) : null}
|
||||||
<SkeletonContent key={i} />
|
|
||||||
)
|
<View style={[Styles.rowItemsCenter, Styles.rowSpaceBetween, Styles.discussionCardIndent]}>
|
||||||
})
|
<View style={Styles.rowItemsCenter}>
|
||||||
:
|
<Feather name="message-square" size={14} color={colors.dimmed} />
|
||||||
data.length > 0 ?
|
<Text style={[Styles.discussionCommentText, themed.dimmed]}>
|
||||||
<VirtualizedList
|
{item.total_komentar} Komentar
|
||||||
data={data}
|
</Text>
|
||||||
getItemCount={() => data.length}
|
</View>
|
||||||
getItem={getItem}
|
<Text style={[Styles.discussionDateText, themed.dimmed]}>
|
||||||
renderItem={({ item, index }: { item: Props, index: number }) => {
|
{item.createdAt}
|
||||||
return (
|
</Text>
|
||||||
<BorderBottomItem
|
</View>
|
||||||
key={index}
|
</Pressable>
|
||||||
onPress={() => { router.push(`./discussion/${item.id}`) }}
|
)}
|
||||||
borderType="bottom"
|
/>
|
||||||
icon={
|
)}
|
||||||
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="sm" />
|
|
||||||
}
|
|
||||||
title={item.user_name}
|
|
||||||
subtitle={
|
|
||||||
status == "true" ? item.status == 1 ? <LabelStatus category='success' text='BUKA' size="small" /> : <LabelStatus category='error' text='TUTUP' size="small" /> : <></>
|
|
||||||
}
|
|
||||||
rightTopInfo={item.createdAt}
|
|
||||||
desc={item.desc}
|
|
||||||
leftBottomInfo={
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>Diskusikan</Text>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
rightBottomInfo={item.total_komentar + ' Komentar'}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
keyExtractor={(item, index) => String(index)}
|
|
||||||
onEndReached={loadMoreData}
|
|
||||||
onEndReachedThreshold={0.5}
|
|
||||||
showsVerticalScrollIndicator={false}
|
|
||||||
refreshControl={
|
|
||||||
<RefreshControl
|
|
||||||
refreshing={refreshing}
|
|
||||||
onRefresh={handleRefresh}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
:
|
|
||||||
(<Text style={[Styles.textDefault, Styles.cGray, Styles.mv10, { textAlign: "center" }]}>Tidak ada diskusi</Text>)
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi";
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import { ButtonHeader } from "@/components/buttonHeader";
|
import { ButtonHeader } from "@/components/buttonHeader";
|
||||||
import HeaderRightDocument from "@/components/document/headerDocument";
|
import HeaderRightDocument from "@/components/document/headerDocument";
|
||||||
@@ -12,7 +13,6 @@ import ModalLoading from "@/components/modalLoading";
|
|||||||
import ModalSelectMultiple from "@/components/modalSelectMultiple";
|
import ModalSelectMultiple from "@/components/modalSelectMultiple";
|
||||||
import Skeleton from "@/components/skeleton";
|
import Skeleton from "@/components/skeleton";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
|
||||||
import { ConstEnv } from "@/constants/ConstEnv";
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import {
|
import {
|
||||||
@@ -23,7 +23,10 @@ import {
|
|||||||
apiShareDocument,
|
apiShareDocument,
|
||||||
} from "@/lib/api";
|
} from "@/lib/api";
|
||||||
import { setUpdateDokumen } from "@/lib/dokumenUpdate";
|
import { setUpdateDokumen } from "@/lib/dokumenUpdate";
|
||||||
|
import { GUIDE_DIVISION_DOCUMENT } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import {
|
import {
|
||||||
AntDesign,
|
AntDesign,
|
||||||
MaterialCommunityIcons,
|
MaterialCommunityIcons,
|
||||||
@@ -66,6 +69,7 @@ type PropsPath = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function DocumentDivision() {
|
export default function DocumentDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const [loadingRename, setLoadingRename] = useState(false)
|
const [loadingRename, setLoadingRename] = useState(false)
|
||||||
const [isShare, setShare] = useState(false)
|
const [isShare, setShare] = useState(false)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
@@ -88,6 +92,8 @@ export default function DocumentDivision() {
|
|||||||
const [loadingOpen, setLoadingOpen] = useState(false)
|
const [loadingOpen, setLoadingOpen] = useState(false)
|
||||||
const [isMemberDivision, setIsMemberDivision] = useState(false)
|
const [isMemberDivision, setIsMemberDivision] = useState(false)
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
|
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('division-document')
|
||||||
const [bodyRename, setBodyRename] = useState({
|
const [bodyRename, setBodyRename] = useState({
|
||||||
id: "",
|
id: "",
|
||||||
name: "",
|
name: "",
|
||||||
@@ -233,9 +239,11 @@ export default function DocumentDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengubah nama"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingRename(false)
|
setLoadingRename(false)
|
||||||
setRename(false)
|
setRename(false)
|
||||||
@@ -256,9 +264,11 @@ export default function DocumentDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menghapus"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,9 +292,11 @@ export default function DocumentDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal membagikan"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setShare(false);
|
setShare(false);
|
||||||
}
|
}
|
||||||
@@ -334,7 +346,7 @@ export default function DocumentDivision() {
|
|||||||
}, [path]);
|
}, [path]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={{ flex: 1 }}>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () =>
|
// headerLeft: () =>
|
||||||
@@ -380,7 +392,7 @@ export default function DocumentDivision() {
|
|||||||
showBack={(selectedFiles.length > 0 || dariSelectAll) ? false : true}
|
showBack={(selectedFiles.length > 0 || dariSelectAll) ? false : true}
|
||||||
left={
|
left={
|
||||||
<ButtonHeader
|
<ButtonHeader
|
||||||
item={<MaterialIcons name="close" size={20} color="white" />}
|
item={<MaterialIcons name="close" size={25} color="white" />}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
handleBatal();
|
handleBatal();
|
||||||
}}
|
}}
|
||||||
@@ -393,7 +405,7 @@ export default function DocumentDivision() {
|
|||||||
selectedFiles.length > 0 || dariSelectAll ? (
|
selectedFiles.length > 0 || dariSelectAll ? (
|
||||||
<ButtonHeader
|
<ButtonHeader
|
||||||
item={
|
item={
|
||||||
<MaterialIcons name="checklist-rtl" size={20} color="white" />
|
<MaterialIcons name="checklist-rtl" size={25} color="white" />
|
||||||
}
|
}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
handleSelectAll();
|
handleSelectAll();
|
||||||
@@ -407,12 +419,14 @@ export default function DocumentDivision() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<GuideOverlay visible={guideVisible} steps={GUIDE_DIVISION_DOCUMENT} onDismiss={dismissGuide} />
|
||||||
<ModalLoading isVisible={loadingOpen} setVisible={setLoadingOpen} />
|
<ModalLoading isVisible={loadingOpen} setVisible={setLoadingOpen} />
|
||||||
<ScrollView
|
<ScrollView
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}>
|
}>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
@@ -427,9 +441,9 @@ export default function DocumentDivision() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{item.id != "home" && (
|
{item.id != "home" && (
|
||||||
<AntDesign name="right" style={[Styles.mh05, Styles.mt02]} color="black" />
|
<AntDesign name="right" style={[Styles.mh05, Styles.mt02]} color={colors.text} />
|
||||||
)}
|
)}
|
||||||
<Text> {item.name} </Text>
|
<Text style={{ color: colors.text }}> {item.name} </Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -478,14 +492,7 @@ export default function DocumentDivision() {
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
) : (
|
) : (
|
||||||
<Text
|
<Text style={[Styles.textDefault, Styles.mt15, { textAlign: "center", color: colors.dimmed }]} >
|
||||||
style={[
|
|
||||||
Styles.textDefault,
|
|
||||||
Styles.cGray,
|
|
||||||
Styles.mt15,
|
|
||||||
{ textAlign: "center" },
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
Tidak ada dokumen
|
Tidak ada dokumen
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
@@ -493,7 +500,7 @@ export default function DocumentDivision() {
|
|||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
{(selectedFiles.length > 0 || dariSelectAll) && (
|
{(selectedFiles.length > 0 || dariSelectAll) && (
|
||||||
<View style={[ColorsStatus.primary, Styles.bottomMenuSelectDocument]}>
|
<View style={[Styles.bottomMenuSelectDocument, { backgroundColor: colors.header }]}>
|
||||||
<View style={[Styles.rowItemsCenter, { justifyContent: "center" }]}>
|
<View style={[Styles.rowItemsCenter, { justifyContent: "center" }]}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={
|
icon={
|
||||||
@@ -505,13 +512,7 @@ export default function DocumentDivision() {
|
|||||||
}
|
}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
AlertKonfirmasi({
|
setShowDeleteModal(true)
|
||||||
title: "Konfirmasi",
|
|
||||||
desc: "Apakah anda yakin ingin menghapus dokumen?",
|
|
||||||
onPress: () => {
|
|
||||||
handleDelete();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
column="many"
|
column="many"
|
||||||
color="white"
|
color="white"
|
||||||
@@ -618,6 +619,19 @@ export default function DocumentDivision() {
|
|||||||
value={id}
|
value={id}
|
||||||
item={selectedFiles[0]?.id}
|
item={selectedFiles[0]?.id}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message="Apakah anda yakin ingin menghapus dokumen?"
|
||||||
|
onConfirm={() => {
|
||||||
|
setShowDeleteModal(false)
|
||||||
|
handleDelete()
|
||||||
|
}}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText="Hapus"
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiAddFileTask, apiCheckFileTask } from "@/lib/api";
|
import { apiAddFileTask, apiCheckFileTask } from "@/lib/api";
|
||||||
import { setUpdateTask } from "@/lib/taskUpdate";
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
import * as DocumentPicker from "expo-document-picker";
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
@@ -23,6 +24,7 @@ import Toast from "react-native-toast-message";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function TaskDivisionAddFile() {
|
export default function TaskDivisionAddFile() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
||||||
const [fileForm, setFileForm] = useState<any[]>([]);
|
const [fileForm, setFileForm] = useState<any[]>([]);
|
||||||
const [listFile, setListFile] = useState<any[]>([]);
|
const [listFile, setListFile] = useState<any[]>([]);
|
||||||
@@ -118,16 +120,18 @@ export default function TaskDivisionAddFile() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan file"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -169,13 +173,13 @@ export default function TaskDivisionAddFile() {
|
|||||||
listFile.length > 0 && (
|
listFile.length > 0 && (
|
||||||
<View style={[Styles.mb15]}>
|
<View style={[Styles.mb15]}>
|
||||||
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>File</Text>
|
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>File</Text>
|
||||||
<View style={[Styles.wrapPaper]}>
|
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
{
|
{
|
||||||
listFile.map((item, index) => (
|
listFile.map((item, index) => (
|
||||||
<BorderBottomItem
|
<BorderBottomItem
|
||||||
key={index}
|
key={index}
|
||||||
borderType="all"
|
borderType="all"
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
|
||||||
title={item}
|
title={item}
|
||||||
titleWeight="normal"
|
titleWeight="normal"
|
||||||
onPress={() => { setIndexDelFile(index); setModal(true) }}
|
onPress={() => { setIndexDelFile(index); setModal(true) }}
|
||||||
@@ -197,7 +201,7 @@ export default function TaskDivisionAddFile() {
|
|||||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile) }}
|
onPress={() => { deleteFile(indexDelFile) }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiAddMemberTask, apiGetDivisionMember, apiGetTaskOne } from "@/lib/api";
|
import { apiAddMemberTask, apiGetDivisionMember, apiGetTaskOne } from "@/lib/api";
|
||||||
import { setUpdateTask } from "@/lib/taskUpdate";
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { AntDesign } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -23,6 +24,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AddMemberTask() {
|
export default function AddMemberTask() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.projectUpdate)
|
const update = useSelector((state: any) => state.projectUpdate)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
@@ -72,6 +74,22 @@ export default function AddMemberTask() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const availableData = data.filter((item: any) => !dataOld.some((i: any) => i.idUser == item.idUser))
|
||||||
|
const isAllSelected = availableData.length > 0 && availableData.every((item: any) =>
|
||||||
|
selectMember.some((s: any) => s.idUser == item.idUser)
|
||||||
|
)
|
||||||
|
|
||||||
|
function handleSelectAll() {
|
||||||
|
if (isAllSelected) {
|
||||||
|
setSelectMember([])
|
||||||
|
} else {
|
||||||
|
const newMembers = availableData
|
||||||
|
.filter((item: any) => !selectMember.some((s: any) => s.idUser == item.idUser))
|
||||||
|
.map((item: any) => ({ idUser: item.idUser, name: item.name, img: item.img }))
|
||||||
|
setSelectMember([...selectMember, ...newMembers])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleAddMember() {
|
async function handleAddMember() {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
@@ -84,9 +102,11 @@ export default function AddMemberTask() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan anggota"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -127,7 +147,7 @@ export default function AddMemberTask() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
<InputSearch onChange={(val) => setSearch(val)} value={search} />
|
<InputSearch onChange={(val) => setSearch(val)} value={search} />
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -149,12 +169,21 @@ export default function AddMemberTask() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.pv05, { textAlign: 'center' }]}>Tidak ada member yang dipilih</Text>
|
<Text style={[Styles.textDefault, Styles.pv05, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada member yang dipilih</Text>
|
||||||
}
|
}
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
{availableData.length > 0 && (
|
||||||
|
<Pressable
|
||||||
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20', paddingTop: 0 }]}
|
||||||
|
onPress={handleSelectAll}
|
||||||
|
>
|
||||||
|
<Text style={[Styles.textMediumSemiBold]}>{isAllSelected ? 'Batalkan Semua' : 'Pilih Semua'}</Text>
|
||||||
|
{isAllSelected && <AntDesign name="check" size={20} color={colors.text} />}
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
{
|
{
|
||||||
data.length > 0 ?
|
data.length > 0 ?
|
||||||
data.map((item: any, index: any) => {
|
data.map((item: any, index: any) => {
|
||||||
@@ -162,22 +191,22 @@ export default function AddMemberTask() {
|
|||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={index}
|
key={index}
|
||||||
style={[Styles.itemSelectModal]}
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
!found && onChoose(item.idUser, item.name, item.img)
|
!found && onChoose(item.idUser, item.name, item.img)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<View style={[Styles.rowItemsCenter, Styles.w80]}>
|
<View style={[Styles.rowItemsCenter, Styles.w80,]}>
|
||||||
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} border />
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} border />
|
||||||
<View style={[Styles.ml10]}>
|
<View style={[Styles.ml10]}>
|
||||||
<Text style={[Styles.textDefault]} numberOfLines={1}>{item.name}</Text>
|
<Text style={[Styles.textDefault]} numberOfLines={1}>{item.name}</Text>
|
||||||
{
|
{
|
||||||
found && <Text style={[Styles.textInformation, Styles.cGray]}>sudah menjadi anggota</Text>
|
found && <Text style={[Styles.textInformation, { color: colors.dimmed }]}>sudah menjadi anggota</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
selectMember.some((i: any) => i.idUser == item.idUser) && <AntDesign name="check" size={20} color={'black'} />
|
selectMember.some((i: any) => i.idUser == item.idUser) && <AntDesign name="check" size={20} color={colors.text} />
|
||||||
}
|
}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
|
import ButtonSelect from "@/components/buttonSelect";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import ModalAddDetailTugasTask from "@/components/task/modalAddDetailTugasTask";
|
import ModalAddDetailTugasTask from "@/components/task/modalAddDetailTugasTask";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -9,6 +10,7 @@ import { formatDateOnly } from "@/lib/fun_formatDateOnly";
|
|||||||
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
||||||
import { setUpdateTask } from "@/lib/taskUpdate";
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import 'intl';
|
import 'intl';
|
||||||
@@ -16,7 +18,8 @@ import 'intl/locale-data/jsonp/id';
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
KeyboardAvoidingView, Platform, Pressable, SafeAreaView,
|
KeyboardAvoidingView, Platform,
|
||||||
|
SafeAreaView,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
View
|
View
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
@@ -25,6 +28,7 @@ import DateTimePicker, { DateType } from "react-native-ui-datepicker";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function TaskDivisionAddTask() {
|
export default function TaskDivisionAddTask() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const update = useSelector((state: any) => state.taskUpdate);
|
const update = useSelector((state: any) => state.taskUpdate);
|
||||||
@@ -129,16 +133,18 @@ export default function TaskDivisionAddTask() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -183,7 +189,7 @@ export default function TaskDivisionAddTask() {
|
|||||||
>
|
>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
<DateTimePicker
|
<DateTimePicker
|
||||||
mode="range"
|
mode="range"
|
||||||
startDate={range.startDate}
|
startDate={range.startDate}
|
||||||
@@ -193,13 +199,15 @@ export default function TaskDivisionAddTask() {
|
|||||||
selected: Styles.selectedDate,
|
selected: Styles.selectedDate,
|
||||||
selected_label: Styles.cWhite,
|
selected_label: Styles.cWhite,
|
||||||
range_fill: Styles.selectRangeDate,
|
range_fill: Styles.selectRangeDate,
|
||||||
month_label: Styles.cBlack,
|
month_label: { color: colors.text },
|
||||||
month_selector_label: Styles.cBlack,
|
month_selector_label: { color: colors.text },
|
||||||
year_label: Styles.cBlack,
|
year_label: { color: colors.text },
|
||||||
year_selector_label: Styles.cBlack,
|
year_selector_label: { color: colors.text },
|
||||||
day_label: Styles.cBlack,
|
day_label: { color: colors.text },
|
||||||
time_label: Styles.cBlack,
|
time_label: { color: colors.text },
|
||||||
weekday_label: Styles.cBlack,
|
weekday_label: { color: colors.text },
|
||||||
|
button_next_image: { tintColor: colors.text },
|
||||||
|
button_prev_image: { tintColor: colors.text },
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
@@ -207,38 +215,39 @@ export default function TaskDivisionAddTask() {
|
|||||||
<View style={[Styles.rowSpaceBetween]}>
|
<View style={[Styles.rowSpaceBetween]}>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[{ width: "48%" }]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Mulai <Text style={Styles.cError}>*</Text>
|
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{from}</Text>
|
<Text style={{ textAlign: "center" }}>{from}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[{ width: "48%" }]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
|
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{to}</Text>
|
<Text style={{ textAlign: "center" }}>{to}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
(error.endDate || error.startDate) && <Text style={[Styles.textInformation, Styles.cError, Styles.mt05]}>Tanggal tidak boleh kosong</Text>
|
(error.endDate || error.startDate) && <Text style={[Styles.textInformation, { color: colors.error }, Styles.mt05]}>Tanggal tidak boleh kosong</Text>
|
||||||
}
|
}
|
||||||
<Pressable
|
{/* <Pressable
|
||||||
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
|
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
|
||||||
disabled={dsbButton}
|
disabled={dsbButton}
|
||||||
onPress={() => { setModalDetail(true) }}
|
onPress={() => { setModalDetail(true) }}
|
||||||
>
|
>
|
||||||
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
|
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
|
||||||
</Pressable>
|
</Pressable> */}
|
||||||
|
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} disabled={from == "" || to == ""} />
|
||||||
</View>
|
</View>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul Tugas"
|
label="Judul Tugas"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul Tugas"
|
placeholder="Judul Tugas"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={title}
|
value={title}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
errorText="Judul tidak boleh kosong"
|
errorText="Judul tidak boleh kosong"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiCancelTask } from "@/lib/api";
|
import { apiCancelTask } from "@/lib/api";
|
||||||
import { setUpdateTask } from "@/lib/taskUpdate";
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -12,6 +13,7 @@ import Toast from "react-native-toast-message";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function TaskDivisionCancel() {
|
export default function TaskDivisionCancel() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -60,16 +62,18 @@ export default function TaskDivisionCancel() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal membatalkan kegiatan"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -115,7 +119,7 @@ export default function TaskDivisionCancel() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Alasan Pembatalan"
|
placeholder="Alasan Pembatalan"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
error={error}
|
error={error}
|
||||||
errorText="Alasan pembatalan harus diisi"
|
errorText="Alasan pembatalan harus diisi"
|
||||||
onChange={(val) => onValidation(val)}
|
onChange={(val) => onValidation(val)}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiEditTask, apiGetTaskOne } from "@/lib/api";
|
import { apiEditTask, apiGetTaskOne } from "@/lib/api";
|
||||||
import { setUpdateTask } from "@/lib/taskUpdate";
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -12,6 +13,7 @@ import Toast from "react-native-toast-message";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function TaskDivisionEdit() {
|
export default function TaskDivisionEdit() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const [judul, setJudul] = useState("");
|
const [judul, setJudul] = useState("");
|
||||||
@@ -78,16 +80,18 @@ export default function TaskDivisionEdit() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengubah data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -128,7 +132,7 @@ export default function TaskDivisionEdit() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul Kegiatan"
|
placeholder="Judul Kegiatan"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={judul}
|
value={judul}
|
||||||
onChange={(val) => { onValidation(val) }}
|
onChange={(val) => { onValidation(val) }}
|
||||||
error={error}
|
error={error}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
import SectionCancel from "@/components/sectionCancel";
|
import SectionCancel from "@/components/sectionCancel";
|
||||||
import SectionProgress from "@/components/sectionProgress";
|
import SectionProgress from "@/components/sectionProgress";
|
||||||
import HeaderRightTaskDetail from "@/components/task/headerTaskDetail";
|
import HeaderRightTaskDetail from "@/components/task/headerTaskDetail";
|
||||||
@@ -9,7 +10,10 @@ import SectionReportTask from "@/components/task/sectionReportTask";
|
|||||||
import SectionTanggalTugasTask from "@/components/task/sectionTanggalTugasTask";
|
import SectionTanggalTugasTask from "@/components/task/sectionTanggalTugasTask";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetDivisionOneFeature, apiGetTaskOne } from "@/lib/api";
|
import { apiGetDivisionOneFeature, apiGetTaskOne } from "@/lib/api";
|
||||||
|
import { GUIDE_PROJECT_DETAIL } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
|
import { RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -22,17 +26,21 @@ type Props = {
|
|||||||
reason: string
|
reason: string
|
||||||
status: number
|
status: number
|
||||||
isActive: boolean
|
isActive: boolean
|
||||||
|
idGroup: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function DetailTaskDivision() {
|
export default function DetailTaskDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id, detail } = useLocalSearchParams<{ id: string, detail: string }>();
|
const { id, detail } = useLocalSearchParams<{ id: string, detail: string }>();
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const [data, setData] = useState<Props>()
|
const [data, setData] = useState<Props>()
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [progress, setProgress] = useState(0)
|
const [progress, setProgress] = useState(0)
|
||||||
|
const [taskStats, setTaskStats] = useState<{ done: number, total: number } | undefined>()
|
||||||
const update = useSelector((state: any) => state.taskUpdate)
|
const update = useSelector((state: any) => state.taskUpdate)
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
const [isMemberDivision, setIsMemberDivision] = useState(false);
|
const [isMemberDivision, setIsMemberDivision] = useState(false);
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('division-task-detail')
|
||||||
const [isAdminDivision, setIsAdminDivision] = useState(false);
|
const [isAdminDivision, setIsAdminDivision] = useState(false);
|
||||||
const entityUser = useSelector((state: any) => state.user);
|
const entityUser = useSelector((state: any) => state.user);
|
||||||
|
|
||||||
@@ -63,6 +71,17 @@ export default function DetailTaskDivision() {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
async function handleLoadTaskStats() {
|
||||||
|
try {
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
const response = await apiGetTaskOne({ id: detail, user: hasil, cat: 'task' })
|
||||||
|
const tasks: { status: number }[] = response.data
|
||||||
|
setTaskStats({ done: tasks.filter(t => t.status === 1).length, total: tasks.length })
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleLoad(cat: 'data' | 'progress') {
|
async function handleLoad(cat: 'data' | 'progress') {
|
||||||
try {
|
try {
|
||||||
if (cat == 'data') setLoading(true)
|
if (cat == 'data') setLoading(true)
|
||||||
@@ -88,16 +107,21 @@ export default function DetailTaskDivision() {
|
|||||||
handleLoad('progress')
|
handleLoad('progress')
|
||||||
}, [update.progress])
|
}, [update.progress])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleLoadTaskStats()
|
||||||
|
}, [update.task])
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
await handleLoad('data')
|
await handleLoad('data')
|
||||||
await handleLoad('progress')
|
await handleLoad('progress')
|
||||||
|
await handleLoadTaskStats()
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -120,11 +144,13 @@ export default function DetailTaskDivision() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<GuideOverlay visible={guideVisible} steps={GUIDE_PROJECT_DETAIL} onDismiss={dismissGuide} />
|
||||||
<ScrollView
|
<ScrollView
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -132,9 +158,9 @@ export default function DetailTaskDivision() {
|
|||||||
{
|
{
|
||||||
data?.reason != null && data?.reason != "" && <SectionCancel text={data?.reason} />
|
data?.reason != null && data?.reason != "" && <SectionCancel text={data?.reason} />
|
||||||
}
|
}
|
||||||
<SectionProgress text={`Kemajuan Kegiatan ${progress}%`} progress={progress} />
|
<SectionProgress progress={progress} doneCount={taskStats?.done} totalCount={taskStats?.total} />
|
||||||
<SectionReportTask refreshing={refreshing} />
|
<SectionReportTask refreshing={refreshing} />
|
||||||
<SectionTanggalTugasTask refreshing={refreshing} isMemberDivision={isMemberDivision} />
|
<SectionTanggalTugasTask refreshing={refreshing} isMemberDivision={isMemberDivision} isAdminDivision={isAdminDivision} status={data?.status} idGroup={data?.idGroup ?? ''} />
|
||||||
<SectionFileTask refreshing={refreshing} isMemberDivision={isMemberDivision} />
|
<SectionFileTask refreshing={refreshing} isMemberDivision={isMemberDivision} />
|
||||||
<SectionLinkTask refreshing={refreshing} isMemberDivision={isMemberDivision} />
|
<SectionLinkTask refreshing={refreshing} isMemberDivision={isMemberDivision} />
|
||||||
<SectionMemberTask refreshing={refreshing} isAdminDivision={isAdminDivision} />
|
<SectionMemberTask refreshing={refreshing} isAdminDivision={isAdminDivision} />
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiGetTaskOne, apiReportTask } from "@/lib/api";
|
import { apiGetTaskOne, apiReportTask } from "@/lib/api";
|
||||||
import { setUpdateTask } from "@/lib/taskUpdate";
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -12,6 +13,7 @@ import Toast from "react-native-toast-message";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function TaskDivisionReport() {
|
export default function TaskDivisionReport() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const [laporan, setLaporan] = useState("");
|
const [laporan, setLaporan] = useState("");
|
||||||
@@ -78,16 +80,18 @@ export default function TaskDivisionReport() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengubah data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -128,7 +132,7 @@ export default function TaskDivisionReport() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Laporan Kegiatan"
|
placeholder="Laporan Kegiatan"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={laporan}
|
value={laporan}
|
||||||
onChange={(val) => { onValidation(val) }}
|
onChange={(val) => { onValidation(val) }}
|
||||||
error={error}
|
error={error}
|
||||||
|
|||||||
@@ -0,0 +1,382 @@
|
|||||||
|
import AppHeader from "@/components/AppHeader";
|
||||||
|
import BorderBottomItem from "@/components/borderBottomItem";
|
||||||
|
import { ButtonForm } from "@/components/buttonForm";
|
||||||
|
import ButtonSelect from "@/components/buttonSelect";
|
||||||
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
|
import ModalLoading from "@/components/modalLoading";
|
||||||
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
|
import Skeleton from "@/components/skeleton";
|
||||||
|
import Text from "@/components/Text";
|
||||||
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
|
import Styles from "@/constants/Styles";
|
||||||
|
import {
|
||||||
|
apiAddTugasTaskFile,
|
||||||
|
apiDeleteTugasTaskFile,
|
||||||
|
apiGetTaskOne,
|
||||||
|
apiGetTugasTaskFile,
|
||||||
|
apiLinkTugasTaskFile,
|
||||||
|
} from "@/lib/api";
|
||||||
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
||||||
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
|
import * as FileSystem from "expo-file-system";
|
||||||
|
import { startActivityAsync } from "expo-intent-launcher";
|
||||||
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
|
import * as Sharing from "expo-sharing";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import {
|
||||||
|
ActivityIndicator,
|
||||||
|
Alert,
|
||||||
|
Platform,
|
||||||
|
SafeAreaView,
|
||||||
|
ScrollView,
|
||||||
|
View,
|
||||||
|
} from "react-native";
|
||||||
|
import * as mime from "react-native-mime-types";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
|
type FileItem = {
|
||||||
|
id: string; // DivisionProjectTaskFile.id
|
||||||
|
idFile: string; // DivisionProjectFile.id
|
||||||
|
name: string;
|
||||||
|
extension: string;
|
||||||
|
idStorage: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProjectFile = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
extension: string;
|
||||||
|
idStorage: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function TugasFileScreen() {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const { id, detail, taskId, member: memberParam } = useLocalSearchParams<{
|
||||||
|
id: string;
|
||||||
|
detail: string;
|
||||||
|
taskId: string;
|
||||||
|
member: string;
|
||||||
|
}>();
|
||||||
|
const { token, decryptToken } = useAuthSession();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const update = useSelector((state: any) => state.taskUpdate);
|
||||||
|
const entityUser = useSelector((state: any) => state.user);
|
||||||
|
const isMember = memberParam === "true";
|
||||||
|
const canEdit = isMember || (entityUser.role !== "user" && entityUser.role !== "coadmin");
|
||||||
|
|
||||||
|
const [data, setData] = useState<FileItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [loadingOpen, setLoadingOpen] = useState(false);
|
||||||
|
const [loadingUpload, setLoadingUpload] = useState(false);
|
||||||
|
const [loadingLink, setLoadingLink] = useState(false);
|
||||||
|
|
||||||
|
const [selectFile, setSelectFile] = useState<FileItem | null>(null);
|
||||||
|
const [isMenuModal, setMenuModal] = useState(false);
|
||||||
|
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||||
|
|
||||||
|
const [projectFiles, setProjectFiles] = useState<ProjectFile[]>([]);
|
||||||
|
const [isPickerModal, setPickerModal] = useState(false);
|
||||||
|
const [loadingProjectFiles, setLoadingProjectFiles] = useState(false);
|
||||||
|
const [selectedProjectFiles, setSelectedProjectFiles] = useState<string[]>([]);
|
||||||
|
|
||||||
|
const arrSkeleton = Array.from({ length: 4 });
|
||||||
|
|
||||||
|
async function loadFiles() {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
const response = await apiGetTugasTaskFile({ user: hasil, id: taskId });
|
||||||
|
setData(response.data ?? []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadProjectFiles() {
|
||||||
|
try {
|
||||||
|
setLoadingProjectFiles(true);
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
const response = await apiGetTaskOne({ id: detail, user: hasil, cat: "file" });
|
||||||
|
setProjectFiles(response.data ?? []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
setLoadingProjectFiles(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadFiles();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const openFile = () => {
|
||||||
|
setMenuModal(false);
|
||||||
|
setLoadingOpen(true);
|
||||||
|
const remoteUrl = ConstEnv.url_storage + "/files/" + selectFile?.idStorage;
|
||||||
|
const fileName = selectFile?.name + "." + selectFile?.extension;
|
||||||
|
const localPath = `${FileSystem.documentDirectory}/${fileName}`;
|
||||||
|
const mimeType = mime.lookup(fileName);
|
||||||
|
|
||||||
|
FileSystem.downloadAsync(remoteUrl, localPath).then(async ({ uri }) => {
|
||||||
|
const contentURL = await FileSystem.getContentUriAsync(uri);
|
||||||
|
try {
|
||||||
|
if (Platform.OS === "android") {
|
||||||
|
await startActivityAsync("android.intent.action.VIEW", {
|
||||||
|
data: contentURL,
|
||||||
|
flags: 1,
|
||||||
|
type: mimeType as string,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Sharing.shareAsync(localPath);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Alert.alert("INFO", "Gagal membuka file, tidak ada aplikasi yang dapat membuka file ini");
|
||||||
|
} finally {
|
||||||
|
setLoadingOpen(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
async function handleDelete() {
|
||||||
|
try {
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
const response = await apiDeleteTugasTaskFile({ user: hasil }, String(selectFile?.id));
|
||||||
|
if (response.success) {
|
||||||
|
Toast.show({ type: "small", text1: "Berhasil menghapus file" });
|
||||||
|
dispatch(setUpdateTask({ ...update, task: !update.task }));
|
||||||
|
loadFiles();
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: "small", text1: response.message });
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
const message = error?.response?.data?.message || "Gagal menghapus file";
|
||||||
|
Toast.show({ type: "small", text1: message });
|
||||||
|
} finally {
|
||||||
|
setMenuModal(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleUpload() {
|
||||||
|
const result = await DocumentPicker.getDocumentAsync({ type: ["*/*"], multiple: true });
|
||||||
|
if (result.canceled) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
setLoadingUpload(true);
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
const fd = new FormData();
|
||||||
|
|
||||||
|
for (let i = 0; i < result.assets.length; i++) {
|
||||||
|
fd.append(`file${i}`, {
|
||||||
|
uri: result.assets[i].uri,
|
||||||
|
type: "application/octet-stream",
|
||||||
|
name: result.assets[i].name,
|
||||||
|
} as any);
|
||||||
|
}
|
||||||
|
fd.append("data", JSON.stringify({ user: hasil }));
|
||||||
|
|
||||||
|
const response = await apiAddTugasTaskFile({ data: fd, id: taskId });
|
||||||
|
if (response.success) {
|
||||||
|
Toast.show({ type: "small", text1: "Berhasil menambahkan file" });
|
||||||
|
dispatch(setUpdateTask({ ...update, task: !update.task }));
|
||||||
|
loadFiles();
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: "small", text1: response.message });
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
const message = error?.response?.data?.message || "Gagal menambahkan file";
|
||||||
|
Toast.show({ type: "small", text1: message });
|
||||||
|
} finally {
|
||||||
|
setLoadingUpload(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleProjectFileSelect(id: string) {
|
||||||
|
setSelectedProjectFiles((prev) =>
|
||||||
|
prev.includes(id) ? prev.filter((v) => v !== id) : [...prev, id]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleLinkFiles() {
|
||||||
|
if (selectedProjectFiles.length === 0) return;
|
||||||
|
try {
|
||||||
|
setLoadingLink(true);
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
for (const idFile of selectedProjectFiles) {
|
||||||
|
await apiLinkTugasTaskFile({ user: hasil, idFile, id: taskId });
|
||||||
|
}
|
||||||
|
Toast.show({ type: "small", text1: "Berhasil menambahkan file" });
|
||||||
|
dispatch(setUpdateTask({ ...update, task: !update.task }));
|
||||||
|
setPickerModal(false);
|
||||||
|
setSelectedProjectFiles([]);
|
||||||
|
loadFiles();
|
||||||
|
} catch (error: any) {
|
||||||
|
const message = error?.response?.data?.message || "Gagal menambahkan file";
|
||||||
|
Toast.show({ type: "small", text1: message });
|
||||||
|
} finally {
|
||||||
|
setLoadingLink(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const attachedFileIds = new Set(data.map((f) => f.idFile));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
header: () => (
|
||||||
|
<AppHeader
|
||||||
|
title="File Tugas"
|
||||||
|
showBack={true}
|
||||||
|
onPressLeft={() => router.back()}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<ModalLoading isVisible={loadingOpen} setVisible={setLoadingOpen} />
|
||||||
|
|
||||||
|
<ScrollView>
|
||||||
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
|
{canEdit && (
|
||||||
|
<>
|
||||||
|
<ButtonSelect
|
||||||
|
value="Upload dari Perangkat"
|
||||||
|
onPress={handleUpload}
|
||||||
|
disabled={loadingUpload}
|
||||||
|
/>
|
||||||
|
<ButtonSelect
|
||||||
|
value="Pilih dari File Kegiatan ini"
|
||||||
|
onPress={() => {
|
||||||
|
setSelectedProjectFiles([]);
|
||||||
|
setPickerModal(true);
|
||||||
|
loadProjectFiles();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loadingUpload && <ActivityIndicator size="small" style={Styles.mv05} />}
|
||||||
|
|
||||||
|
<View style={[Styles.mb15, Styles.mt10]}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>File Terlampir</Text>
|
||||||
|
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
|
{loading ? (
|
||||||
|
arrSkeleton.map((_, index) => (
|
||||||
|
<Skeleton key={index} width={100} height={40} widthType="percent" borderRadius={10} />
|
||||||
|
))
|
||||||
|
) : data.length > 0 ? (
|
||||||
|
data.map((item, index) => (
|
||||||
|
<BorderBottomItem
|
||||||
|
key={index}
|
||||||
|
borderType="all"
|
||||||
|
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
|
||||||
|
title={item.name + "." + item.extension}
|
||||||
|
titleWeight="normal"
|
||||||
|
onPress={() => {
|
||||||
|
setSelectFile(item);
|
||||||
|
setMenuModal(true);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<Text style={[Styles.textDefault, { textAlign: "center", color: colors.dimmed }]}>
|
||||||
|
Tidak ada file
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
{/* Menu per file */}
|
||||||
|
<DrawerBottom animation="slide" isVisible={isMenuModal} setVisible={setMenuModal} title="Menu">
|
||||||
|
<View style={Styles.rowItemsCenter}>
|
||||||
|
<MenuItemRow
|
||||||
|
icon={<MaterialCommunityIcons name="file-eye" color={colors.text} size={25} />}
|
||||||
|
title="Lihat / Share"
|
||||||
|
onPress={openFile}
|
||||||
|
/>
|
||||||
|
{canEdit && (
|
||||||
|
<MenuItemRow
|
||||||
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
|
title="Hapus"
|
||||||
|
onPress={() => {
|
||||||
|
setMenuModal(false);
|
||||||
|
setTimeout(() => setShowDeleteModal(true), 600);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</DrawerBottom>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message="Apakah Anda yakin ingin menghapus file ini?"
|
||||||
|
onConfirm={() => {
|
||||||
|
setShowDeleteModal(false);
|
||||||
|
handleDelete();
|
||||||
|
}}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText="Hapus"
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Picker file dari proyek */}
|
||||||
|
<DrawerBottom
|
||||||
|
animation="slide"
|
||||||
|
isVisible={isPickerModal}
|
||||||
|
setVisible={setPickerModal}
|
||||||
|
title="Pilih File Proyek"
|
||||||
|
height={60}
|
||||||
|
>
|
||||||
|
<ScrollView>
|
||||||
|
{loadingProjectFiles ? (
|
||||||
|
<ActivityIndicator size="small" />
|
||||||
|
) : projectFiles.length > 0 ? (
|
||||||
|
projectFiles.map((item, index) => {
|
||||||
|
const isAttached = attachedFileIds.has(item.id);
|
||||||
|
const isSelected = selectedProjectFiles.includes(item.id);
|
||||||
|
return (
|
||||||
|
<View key={index} style={isAttached ? { opacity: 0.4 } : undefined}>
|
||||||
|
<BorderBottomItem
|
||||||
|
borderType="bottom"
|
||||||
|
icon={
|
||||||
|
isAttached || isSelected ? (
|
||||||
|
<Ionicons name="checkmark-circle" size={25} color={colors.primary} />
|
||||||
|
) : (
|
||||||
|
<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
title={item.name + "." + item.extension}
|
||||||
|
titleWeight="normal"
|
||||||
|
onPress={() => !isAttached && toggleProjectFileSelect(item.id)}
|
||||||
|
bgColor="transparent"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<Text style={[Styles.textDefault, { textAlign: "center", color: colors.dimmed }]}>
|
||||||
|
Tidak ada file tersedia
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</ScrollView>
|
||||||
|
{projectFiles.length > 0 && (
|
||||||
|
<View>
|
||||||
|
<ButtonForm
|
||||||
|
text={loadingLink ? "Menyimpan..." : `Tambahkan (${selectedProjectFiles.length})`}
|
||||||
|
disabled={selectedProjectFiles.length === 0 || loadingLink}
|
||||||
|
onPress={handleLinkFiles} />
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</DrawerBottom>
|
||||||
|
</SafeAreaView>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import ButtonSelect from "@/components/buttonSelect";
|
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import ImageUser from "@/components/imageNew";
|
import ImageUser from "@/components/imageNew";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
@@ -16,16 +14,38 @@ import { setMemberChoose } from "@/lib/memberChoose";
|
|||||||
import { setTaskCreate } from "@/lib/taskCreate";
|
import { setTaskCreate } from "@/lib/taskCreate";
|
||||||
import { setUpdateTask } from "@/lib/taskUpdate";
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
import * as DocumentPicker from "expo-document-picker";
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { Pressable, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
|
|
||||||
|
function getFileIcon(ext: string): keyof typeof MaterialCommunityIcons.glyphMap {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return 'image-outline'
|
||||||
|
if (ext === 'pdf') return 'file-pdf-box'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return 'video-outline'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return 'file-word-outline'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return 'file-excel-outline'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return 'zip-box-outline'
|
||||||
|
return 'file-outline'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileColor(ext: string): string {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return '#339AF0'
|
||||||
|
if (ext === 'pdf') return '#F03E3E'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return '#AE3EC9'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return '#1C7ED6'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return '#2F9E44'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return '#E8590C'
|
||||||
|
return '#868E96'
|
||||||
|
}
|
||||||
|
|
||||||
export default function CreateTaskDivision() {
|
export default function CreateTaskDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id } = useLocalSearchParams();
|
const { id } = useLocalSearchParams();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -103,9 +123,11 @@ export default function CreateTaskDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -113,7 +135,7 @@ export default function CreateTaskDivision() {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -161,61 +183,134 @@ export default function CreateTaskDivision() {
|
|||||||
val == "" || val == "null" ? setError(true) : setError(false);
|
val == "" || val == "null" ? setError(true) : setError(false);
|
||||||
}}
|
}}
|
||||||
error={error}
|
error={error}
|
||||||
|
bg={colors.card}
|
||||||
errorText="Judul Tugas tidak boleh kosong"
|
errorText="Judul Tugas tidak boleh kosong"
|
||||||
/>
|
/>
|
||||||
<ButtonSelect value="Tambah Tanggal & Tugas" onPress={() => { router.push(`/division/${id}/task/create/task`); }} />
|
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
|
||||||
<ButtonSelect value="Tambah Anggota" onPress={() => { router.push(`/division/${id}/task/create/member`); }} />
|
|
||||||
<SectionListAddTask />
|
|
||||||
{
|
|
||||||
fileForm.length > 0 && (
|
|
||||||
<View style={[Styles.mb15]}>
|
|
||||||
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>File</Text>
|
|
||||||
<View style={[Styles.wrapPaper]}>
|
|
||||||
{
|
|
||||||
fileForm.map((item, index) => (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={index}
|
|
||||||
borderType="all"
|
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
|
||||||
title={item.name}
|
|
||||||
titleWeight="normal"
|
|
||||||
onPress={() => { setIndexDelFile(index); setModal(true) }}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{entitiesMember.length > 0 && (
|
|
||||||
<View>
|
|
||||||
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
|
|
||||||
<Text>Anggota</Text>
|
|
||||||
<Text>Total {entitiesMember.length} Anggota</Text>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10]}>
|
{/* Tanggal & Tugas */}
|
||||||
{entitiesMember.map(
|
<View style={[
|
||||||
(item: { img: any; name: any }, index: any) => {
|
Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
return (
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }
|
||||||
<BorderBottomItem
|
]}>
|
||||||
key={index}
|
<Pressable
|
||||||
borderType="bottom"
|
onPress={() => router.push(`/division/${id}/task/create/task`)}
|
||||||
icon={
|
style={[Styles.sectionActionRow, { marginBottom: taskCreate.length > 0 ? 12 : 0 }]}
|
||||||
<ImageUser
|
>
|
||||||
src={`${ConstEnv.url_storage}/files/${item.img}`}
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
size="sm"
|
<MaterialCommunityIcons name="calendar-check-outline" size={18} color={colors.tabActive} />
|
||||||
/>
|
</View>
|
||||||
}
|
<View style={Styles.flex1}>
|
||||||
title={item.name}
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Tanggal & Tugas</Text>
|
||||||
/>
|
{taskCreate.length === 0 && (
|
||||||
);
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Belum ada tugas ditambahkan</Text>
|
||||||
}
|
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
{taskCreate.length > 0 && (
|
||||||
)}
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.tabActive }]}>{taskCreate.length} tugas</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{taskCreate.length > 0 && <SectionListAddTask showTitle={false} />}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* File */}
|
||||||
|
<View style={[
|
||||||
|
Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }
|
||||||
|
]}>
|
||||||
|
<Pressable
|
||||||
|
onPress={pickDocumentAsync}
|
||||||
|
style={[Styles.sectionActionRow, { marginBottom: fileForm.length > 0 ? 12 : 0 }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '15' }]}>
|
||||||
|
<MaterialCommunityIcons name="paperclip" size={18} color={colors.dimmed} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>File</Text>
|
||||||
|
{fileForm.length === 0 && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Opsional — ketuk untuk upload</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{fileForm.length > 0 && (
|
||||||
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{fileForm.length} file</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{fileForm.length > 0 && (
|
||||||
|
<View style={Styles.fileGrid}>
|
||||||
|
{fileForm.map((item, index) => {
|
||||||
|
const ext = item.name.split('.').pop()?.toLowerCase() ?? ''
|
||||||
|
const baseName = item.name.includes('.') ? item.name.split('.').slice(0, -1).join('.') : item.name
|
||||||
|
const iconName = getFileIcon(ext)
|
||||||
|
const iconColor = getFileColor(ext)
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={index}
|
||||||
|
onPress={() => { setIndexDelFile(index); setModal(true) }}
|
||||||
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={Styles.textDefault} numberOfLines={1}>{baseName}</Text>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* Anggota */}
|
||||||
|
<View style={[
|
||||||
|
Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }
|
||||||
|
]}>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => router.push(`/division/${id}/task/create/member`)}
|
||||||
|
style={[Styles.sectionActionRow, { marginBottom: entitiesMember.length > 0 ? 12 : 0 }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<MaterialCommunityIcons name="account-group-outline" size={18} color={colors.tabActive} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Anggota</Text>
|
||||||
|
{entitiesMember.length === 0 && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Belum ada anggota dipilih</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{entitiesMember.length > 0 && (
|
||||||
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.tabActive }]}>{entitiesMember.length} orang</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{entitiesMember.length > 0 && (
|
||||||
|
<View style={{ gap: 6 }}>
|
||||||
|
{entitiesMember.map((item: { img: any; name: any; position?: string }, index: any) => (
|
||||||
|
<View
|
||||||
|
key={index}
|
||||||
|
style={[Styles.listItemCard, { borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
|
||||||
|
<Text style={[Styles.textDefault, Styles.flex1, { color: colors.text }]} numberOfLines={1}>{item.name}</Text>
|
||||||
|
{item.position && (
|
||||||
|
<View style={[Styles.positionBadge, { backgroundColor: colors.dimmed + '15' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]} numberOfLines={1}>{item.position}</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
@@ -223,7 +318,7 @@ export default function CreateTaskDivision() {
|
|||||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile) }}
|
onPress={() => { deleteFile(indexDelFile) }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiGetDivisionMember } from "@/lib/api";
|
import { apiGetDivisionMember } from "@/lib/api";
|
||||||
import { setMemberChoose } from "@/lib/memberChoose";
|
import { setMemberChoose } from "@/lib/memberChoose";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { AntDesign } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -23,6 +24,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AddMemberCreateTask() {
|
export default function AddMemberCreateTask() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const { id } = useLocalSearchParams<{ id: string, detail: string }>()
|
const { id } = useLocalSearchParams<{ id: string, detail: string }>()
|
||||||
@@ -52,6 +54,21 @@ export default function AddMemberCreateTask() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isAllSelected = data.length > 0 && data.every((item: any) =>
|
||||||
|
selectMember.some((s: any) => s.idUser == item.idUser)
|
||||||
|
)
|
||||||
|
|
||||||
|
function handleSelectAll() {
|
||||||
|
if (isAllSelected) {
|
||||||
|
setSelectMember([])
|
||||||
|
} else {
|
||||||
|
const newMembers = data
|
||||||
|
.filter((item: any) => !selectMember.some((s: any) => s.idUser == item.idUser))
|
||||||
|
.map((item: any) => ({ idUser: item.idUser, name: item.name, img: item.img }))
|
||||||
|
setSelectMember([...selectMember, ...newMembers])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleAddMember() {
|
async function handleAddMember() {
|
||||||
try {
|
try {
|
||||||
dispatch(setMemberChoose(selectMember))
|
dispatch(setMemberChoose(selectMember))
|
||||||
@@ -97,7 +114,7 @@ export default function AddMemberCreateTask() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
<InputSearch onChange={(val) => setSearch(val)} value={search} />
|
<InputSearch onChange={(val) => setSearch(val)} value={search} />
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -119,19 +136,28 @@ export default function AddMemberCreateTask() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.pv05, { textAlign: 'center' }]}>Tidak ada member yang dipilih</Text>
|
<Text style={[Styles.textDefault, Styles.pv05, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada member yang dipilih</Text>
|
||||||
}
|
}
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
{data.length > 0 && (
|
||||||
|
<Pressable
|
||||||
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20', paddingTop: 0 }]}
|
||||||
|
onPress={handleSelectAll}
|
||||||
|
>
|
||||||
|
<Text style={[Styles.textMediumSemiBold]}>{isAllSelected ? 'Batalkan Semua' : 'Pilih Semua'}</Text>
|
||||||
|
{isAllSelected && <AntDesign name="check" size={20} color={colors.text} />}
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
{
|
{
|
||||||
data.length > 0 ?
|
data.length > 0 ?
|
||||||
data.map((item: any, index: any) => {
|
data.map((item: any, index: any) => {
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={index}
|
key={index}
|
||||||
style={[Styles.itemSelectModal]}
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
onChoose(item.idUser, item.name, item.img)
|
onChoose(item.idUser, item.name, item.img)
|
||||||
}}
|
}}
|
||||||
@@ -143,7 +169,7 @@ export default function AddMemberCreateTask() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
selectMember.some((i: any) => i.idUser == item.idUser) && <AntDesign name="check" size={20} color={'black'} />
|
selectMember.some((i: any) => i.idUser == item.idUser) && <AntDesign name="check" size={20} color={colors.text} />
|
||||||
}
|
}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
|
import ButtonSelect from "@/components/buttonSelect";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import ModalAddDetailTugasTask from "@/components/task/modalAddDetailTugasTask";
|
import ModalAddDetailTugasTask from "@/components/task/modalAddDetailTugasTask";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -7,6 +8,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { formatDateOnly } from "@/lib/fun_formatDateOnly";
|
import { formatDateOnly } from "@/lib/fun_formatDateOnly";
|
||||||
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
||||||
import { setTaskCreate } from "@/lib/taskCreate";
|
import { setTaskCreate } from "@/lib/taskCreate";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import 'intl';
|
import 'intl';
|
||||||
@@ -16,7 +18,6 @@ import { useEffect, useState } from "react";
|
|||||||
import {
|
import {
|
||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
Platform,
|
Platform,
|
||||||
Pressable,
|
|
||||||
SafeAreaView,
|
SafeAreaView,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
View
|
View
|
||||||
@@ -27,6 +28,7 @@ import DateTimePicker, {
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function CreateTaskAddTugas() {
|
export default function CreateTaskAddTugas() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const headerHeight = useHeaderHeight();
|
const headerHeight = useHeaderHeight();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const [disable, setDisable] = useState(true);
|
const [disable, setDisable] = useState(true);
|
||||||
@@ -118,7 +120,7 @@ export default function CreateTaskAddTugas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -158,7 +160,7 @@ export default function CreateTaskAddTugas() {
|
|||||||
>
|
>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
<DateTimePicker
|
<DateTimePicker
|
||||||
mode="range"
|
mode="range"
|
||||||
startDate={range.startDate}
|
startDate={range.startDate}
|
||||||
@@ -168,13 +170,15 @@ export default function CreateTaskAddTugas() {
|
|||||||
selected: Styles.selectedDate,
|
selected: Styles.selectedDate,
|
||||||
selected_label: Styles.cWhite,
|
selected_label: Styles.cWhite,
|
||||||
range_fill: Styles.selectRangeDate,
|
range_fill: Styles.selectRangeDate,
|
||||||
month_label: Styles.cBlack,
|
month_label: { color: colors.text },
|
||||||
month_selector_label: Styles.cBlack,
|
month_selector_label: { color: colors.text },
|
||||||
year_label: Styles.cBlack,
|
year_label: { color: colors.text },
|
||||||
year_selector_label: Styles.cBlack,
|
year_selector_label: { color: colors.text },
|
||||||
day_label: Styles.cBlack,
|
day_label: { color: colors.text },
|
||||||
time_label: Styles.cBlack,
|
time_label: { color: colors.text },
|
||||||
weekday_label: Styles.cBlack,
|
weekday_label: { color: colors.text },
|
||||||
|
button_next_image: { tintColor: colors.text },
|
||||||
|
button_prev_image: { tintColor: colors.text },
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
@@ -182,38 +186,39 @@ export default function CreateTaskAddTugas() {
|
|||||||
<View style={[Styles.rowSpaceBetween]}>
|
<View style={[Styles.rowSpaceBetween]}>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[{ width: "48%" }]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Mulai <Text style={Styles.cError}>*</Text>
|
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{from}</Text>
|
<Text style={{ textAlign: "center" }}>{from}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[{ width: "48%" }]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
|
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{to}</Text>
|
<Text style={{ textAlign: "center" }}>{to}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
(error.endDate || error.startDate) && <Text style={[Styles.textInformation, Styles.cError, Styles.mt05]}>Tanggal tidak boleh kosong</Text>
|
(error.endDate || error.startDate) && <Text style={[Styles.textInformation, { color: colors.error }, Styles.mt05]}>Tanggal tidak boleh kosong</Text>
|
||||||
}
|
}
|
||||||
<Pressable
|
{/* <Pressable
|
||||||
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
|
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
|
||||||
disabled={dsbButton}
|
disabled={dsbButton}
|
||||||
onPress={() => { setModalDetail(true) }}
|
onPress={() => { setModalDetail(true) }}
|
||||||
>
|
>
|
||||||
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
|
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
|
||||||
</Pressable>
|
</Pressable> */}
|
||||||
|
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} disabled={from == "" || to == ""} />
|
||||||
</View>
|
</View>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul Tugas"
|
label="Judul Tugas"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul Tugas"
|
placeholder="Judul Tugas"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={title}
|
value={title}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
errorText="Judul tidak boleh kosong"
|
errorText="Judul tidak boleh kosong"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { ColorsStatus } from "@/constants/ColorsStatus";
|
|||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetTask } from "@/lib/api";
|
import { apiGetTask } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import {
|
import {
|
||||||
AntDesign,
|
AntDesign,
|
||||||
Ionicons,
|
Ionicons,
|
||||||
@@ -20,6 +21,7 @@ import { router, useLocalSearchParams } from "expo-router";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Pressable, RefreshControl, ScrollView, View, VirtualizedList } from "react-native";
|
import { Pressable, RefreshControl, ScrollView, View, VirtualizedList } from "react-native";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -31,9 +33,22 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function ListTask() {
|
export default function ListTask() {
|
||||||
|
const { colors } = useTheme()
|
||||||
const { id, status, year } = useLocalSearchParams<{ id: string; status: string; year: string }>()
|
const { id, status, year } = useLocalSearchParams<{ id: string; status: string; year: string }>()
|
||||||
const [isList, setList] = useState(false)
|
const [isList, setList] = useState(false)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
AsyncStorage.getItem('division_view_mode').then((val) => {
|
||||||
|
if (val !== null) setList(val === 'list')
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
function toggleView() {
|
||||||
|
const next = !isList
|
||||||
|
setList(next)
|
||||||
|
AsyncStorage.setItem('division_view_mode', next ? 'list' : 'grid')
|
||||||
|
}
|
||||||
const [data, setData] = useState<Props[]>([])
|
const [data, setData] = useState<Props[]>([])
|
||||||
const [search, setSearch] = useState("")
|
const [search, setSearch] = useState("")
|
||||||
const update = useSelector((state: any) => state.taskUpdate)
|
const update = useSelector((state: any) => state.taskUpdate)
|
||||||
@@ -110,7 +125,7 @@ export default function ListTask() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<View>
|
<View>
|
||||||
<ScrollView horizontal style={[Styles.mb10]} showsHorizontalScrollIndicator={false}>
|
<ScrollView horizontal style={[Styles.mb10]} showsHorizontalScrollIndicator={false}>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
@@ -121,7 +136,7 @@ export default function ListTask() {
|
|||||||
icon={
|
icon={
|
||||||
<MaterialCommunityIcons
|
<MaterialCommunityIcons
|
||||||
name="clock-alert-outline"
|
name="clock-alert-outline"
|
||||||
color={statusFix == "0" ? "white" : "black"}
|
color={statusFix == "0" ? "white" : colors.dimmed}
|
||||||
size={20}
|
size={20}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -135,7 +150,7 @@ export default function ListTask() {
|
|||||||
icon={
|
icon={
|
||||||
<MaterialCommunityIcons
|
<MaterialCommunityIcons
|
||||||
name="progress-check"
|
name="progress-check"
|
||||||
color={statusFix == "1" ? "white" : "black"}
|
color={statusFix == "1" ? "white" : colors.dimmed}
|
||||||
size={20}
|
size={20}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -149,7 +164,7 @@ export default function ListTask() {
|
|||||||
icon={
|
icon={
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="checkmark-done-circle-outline"
|
name="checkmark-done-circle-outline"
|
||||||
color={statusFix == "2" ? "white" : "black"}
|
color={statusFix == "2" ? "white" : colors.dimmed}
|
||||||
size={20}
|
size={20}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -163,23 +178,19 @@ export default function ListTask() {
|
|||||||
icon={
|
icon={
|
||||||
<AntDesign
|
<AntDesign
|
||||||
name="closecircleo"
|
name="closecircleo"
|
||||||
color={statusFix == "3" ? "white" : "black"}
|
color={statusFix == "3" ? "white" : colors.dimmed}
|
||||||
size={20}
|
size={20}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
n={4}
|
n={4}
|
||||||
/>
|
/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<View style={[Styles.rowSpaceBetween]}>
|
<View style={[Styles.rowSpaceBetween, { alignItems: 'center' }]}>
|
||||||
<InputSearch width={68} onChange={setSearch} />
|
<InputSearch width={68} onChange={setSearch} />
|
||||||
<Pressable
|
<Pressable onPress={toggleView}>
|
||||||
onPress={() => {
|
|
||||||
setList(!isList);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MaterialCommunityIcons
|
<MaterialCommunityIcons
|
||||||
name={isList ? "format-list-bulleted" : "view-grid"}
|
name={isList ? "format-list-bulleted" : "view-grid"}
|
||||||
color={"black"}
|
color={colors.text}
|
||||||
size={30}
|
size={30}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
@@ -188,7 +199,7 @@ export default function ListTask() {
|
|||||||
<View style={[Styles.mv05]}>
|
<View style={[Styles.mv05]}>
|
||||||
<View style={[Styles.rowOnly]}>
|
<View style={[Styles.rowOnly]}>
|
||||||
<Text style={[Styles.mr05]}>Filter :</Text>
|
<Text style={[Styles.mr05]}>Filter :</Text>
|
||||||
<LabelStatus size="small" category="secondary" text={isYear} style={{ marginRight: 5 }} />
|
<LabelStatus size="small" category="secondary" text={isYear} style={[Styles.mr05]} />
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ flex: 2 }]}>
|
<View style={[{ flex: 2 }]}>
|
||||||
@@ -217,9 +228,10 @@ export default function ListTask() {
|
|||||||
router.push(`./task/${item.id}`);
|
router.push(`./task/${item.id}`);
|
||||||
}}
|
}}
|
||||||
borderType="bottom"
|
borderType="bottom"
|
||||||
|
bgColor="transparent"
|
||||||
icon={
|
icon={
|
||||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
<View style={[Styles.iconContent]}>
|
||||||
<AntDesign name="areachart" size={25} color={"#384288"} />
|
<AntDesign name="areachart" size={25} color={"black"} />
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
title={item.title}
|
title={item.title}
|
||||||
@@ -233,6 +245,7 @@ export default function ListTask() {
|
|||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -274,11 +287,11 @@ export default function ListTask() {
|
|||||||
<LabelStatus
|
<LabelStatus
|
||||||
size="default"
|
size="default"
|
||||||
category={
|
category={
|
||||||
item.status === 0 ? 'primary' :
|
item.status === 0 ? 'secondary' :
|
||||||
item.status === 1 ? 'warning' :
|
item.status === 1 ? 'warning' :
|
||||||
item.status === 2 ? 'success' :
|
item.status === 2 ? 'success' :
|
||||||
item.status === 3 ? 'error' :
|
item.status === 3 ? 'error' :
|
||||||
'primary'
|
'secondary'
|
||||||
}
|
}
|
||||||
text={
|
text={
|
||||||
item.status === 0 ? 'SEGERA' :
|
item.status === 0 ? 'SEGERA' :
|
||||||
@@ -299,6 +312,7 @@ export default function ListTask() {
|
|||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -338,13 +352,13 @@ export default function ListTask() {
|
|||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: "center" },]} >
|
<Text style={[Styles.textDefault, Styles.textCenter]} >
|
||||||
Tidak ada data
|
Tidak ada data
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
</View>
|
</View >
|
||||||
</View>
|
</View >
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
|
import ButtonSelect from "@/components/buttonSelect";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import ModalAddDetailTugasTask from "@/components/task/modalAddDetailTugasTask";
|
import ModalAddDetailTugasTask from "@/components/task/modalAddDetailTugasTask";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -9,6 +10,7 @@ import { formatDateOnly } from "@/lib/fun_formatDateOnly";
|
|||||||
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
||||||
import { setUpdateTask } from "@/lib/taskUpdate";
|
import { setUpdateTask } from "@/lib/taskUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import 'intl';
|
import 'intl';
|
||||||
@@ -18,7 +20,6 @@ import { useEffect, useState } from "react";
|
|||||||
import {
|
import {
|
||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
Platform,
|
Platform,
|
||||||
Pressable,
|
|
||||||
SafeAreaView,
|
SafeAreaView,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
View
|
View
|
||||||
@@ -28,6 +29,7 @@ import DateTimePicker, { DateType } from "react-native-ui-datepicker";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function UpdateProjectTaskDivision() {
|
export default function UpdateProjectTaskDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const headerHeight = useHeaderHeight();
|
const headerHeight = useHeaderHeight();
|
||||||
const { detail } = useLocalSearchParams<{ detail: string }>();
|
const { detail } = useLocalSearchParams<{ detail: string }>();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -123,9 +125,11 @@ export default function UpdateProjectTaskDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengubah data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingSubmit(false)
|
setLoadingSubmit(false)
|
||||||
}
|
}
|
||||||
@@ -186,7 +190,7 @@ export default function UpdateProjectTaskDivision() {
|
|||||||
}, [range])
|
}, [range])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -231,7 +235,7 @@ export default function UpdateProjectTaskDivision() {
|
|||||||
>
|
>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
{!loading && (
|
{!loading && (
|
||||||
<DateTimePicker
|
<DateTimePicker
|
||||||
mode="range"
|
mode="range"
|
||||||
@@ -244,13 +248,15 @@ export default function UpdateProjectTaskDivision() {
|
|||||||
selected: Styles.selectedDate,
|
selected: Styles.selectedDate,
|
||||||
selected_label: Styles.cWhite,
|
selected_label: Styles.cWhite,
|
||||||
range_fill: Styles.selectRangeDate,
|
range_fill: Styles.selectRangeDate,
|
||||||
month_label: Styles.cBlack,
|
month_label: { color: colors.text },
|
||||||
month_selector_label: Styles.cBlack,
|
month_selector_label: { color: colors.text },
|
||||||
year_label: Styles.cBlack,
|
year_label: { color: colors.text },
|
||||||
year_selector_label: Styles.cBlack,
|
year_selector_label: { color: colors.text },
|
||||||
day_label: Styles.cBlack,
|
day_label: { color: colors.text },
|
||||||
time_label: Styles.cBlack,
|
time_label: { color: colors.text },
|
||||||
weekday_label: Styles.cBlack,
|
weekday_label: { color: colors.text },
|
||||||
|
button_next_image: { tintColor: colors.text },
|
||||||
|
button_prev_image: { tintColor: colors.text },
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -259,40 +265,41 @@ export default function UpdateProjectTaskDivision() {
|
|||||||
<View style={[Styles.rowSpaceBetween]}>
|
<View style={[Styles.rowSpaceBetween]}>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[{ width: "48%" }]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Mulai <Text style={Styles.cError}>*</Text>
|
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{from}</Text>
|
<Text style={{ textAlign: "center" }}>{from}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[{ width: "48%" }]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
|
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{to}</Text>
|
<Text style={{ textAlign: "center" }}>{to}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{(error.endDate || error.startDate) && (
|
{(error.endDate || error.startDate) && (
|
||||||
<Text style={[Styles.textInformation, Styles.cError, Styles.mt05]} >
|
<Text style={[Styles.textInformation, { color: colors.error }, Styles.mt05]} >
|
||||||
Tanggal tidak boleh kosong
|
Tanggal tidak boleh kosong
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
<Pressable
|
{/* <Pressable
|
||||||
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
|
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
|
||||||
disabled={dsbButton}
|
disabled={dsbButton}
|
||||||
onPress={() => { setModalDetail(true) }}
|
onPress={() => { setModalDetail(true) }}
|
||||||
>
|
>
|
||||||
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
|
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
|
||||||
</Pressable>
|
</Pressable> */}
|
||||||
|
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} disabled={from == "" || to == ""} />
|
||||||
</View>
|
</View>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul Tugas"
|
label="Judul Tugas"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul Tugas"
|
placeholder="Judul Tugas"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={title}
|
value={title}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
errorText="Judul tidak boleh kosong"
|
errorText="Judul tidak boleh kosong"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { ConstEnv } from "@/constants/ConstEnv";
|
|||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiAddMemberDivision, apiGetDivisionOneDetail, apiGetUser } from "@/lib/api";
|
import { apiAddMemberDivision, apiGetDivisionOneDetail, apiGetUser } from "@/lib/api";
|
||||||
import { setUpdateDivision } from "@/lib/divisionUpdate";
|
import { setUpdateDivision } from "@/lib/divisionUpdate";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { AntDesign } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
@@ -23,6 +24,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AddMemberDivision() {
|
export default function AddMemberDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [dataOld, setDataOld] = useState<Props[]>([])
|
const [dataOld, setDataOld] = useState<Props[]>([])
|
||||||
@@ -75,6 +77,22 @@ export default function AddMemberDivision() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const availableData = data.filter((item: any) => !dataOld.some((i: any) => i.idUser == item.id))
|
||||||
|
const isAllSelected = availableData.length > 0 && availableData.every((item: any) =>
|
||||||
|
selectMember.some((s: any) => s.idUser == item.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
function handleSelectAll() {
|
||||||
|
if (isAllSelected) {
|
||||||
|
setSelectMember([])
|
||||||
|
} else {
|
||||||
|
const newMembers = availableData
|
||||||
|
.filter((item: any) => !selectMember.some((s: any) => s.idUser == item.id))
|
||||||
|
.map((item: any) => ({ idUser: item.id, name: item.name, img: item.img }))
|
||||||
|
setSelectMember([...selectMember, ...newMembers])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleAddMember() {
|
async function handleAddMember() {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
@@ -87,9 +105,11 @@ export default function AddMemberDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan anggota"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -130,14 +150,14 @@ export default function AddMemberDivision() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
<InputSearch onChange={(val) => handleSearch(val)} value={search} />
|
<InputSearch onChange={(val) => handleSearch(val)} value={search} />
|
||||||
|
|
||||||
{
|
{
|
||||||
selectMember.length > 0
|
selectMember.length > 0
|
||||||
?
|
?
|
||||||
<View>
|
<View>
|
||||||
<ScrollView horizontal style={[Styles.mb10, Styles.pv10]} showsHorizontalScrollIndicator={false}>
|
<ScrollView horizontal style={[Styles.mb05, Styles.pv10]} showsHorizontalScrollIndicator={false}>
|
||||||
{
|
{
|
||||||
selectMember.map((item: any, index: any) => (
|
selectMember.map((item: any, index: any) => (
|
||||||
<ImageWithLabel
|
<ImageWithLabel
|
||||||
@@ -152,12 +172,21 @@ export default function AddMemberDivision() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.pv05, { textAlign: 'center' }]}>Tidak ada member yang dipilih</Text>
|
<Text style={[Styles.textDefault, Styles.pv05, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada member yang dipilih</Text>
|
||||||
}
|
}
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
{availableData.length > 0 && (
|
||||||
|
<Pressable
|
||||||
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20', paddingTop: 0 }]}
|
||||||
|
onPress={handleSelectAll}
|
||||||
|
>
|
||||||
|
<Text style={[Styles.textMediumSemiBold]}>{isAllSelected ? 'Batalkan Semua' : 'Pilih Semua'}</Text>
|
||||||
|
{isAllSelected && <AntDesign name="check" size={20} color={colors.text} />}
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
{
|
{
|
||||||
data.length > 0 ?
|
data.length > 0 ?
|
||||||
data.map((item: any, index: any) => {
|
data.map((item: any, index: any) => {
|
||||||
@@ -165,7 +194,7 @@ export default function AddMemberDivision() {
|
|||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={index}
|
key={index}
|
||||||
style={[Styles.itemSelectModal]}
|
style={[Styles.itemSelectModal, { borderBottomColor: colors.icon + '20' }]}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
!found && onChoose(item.id, item.name, item.img)
|
!found && onChoose(item.id, item.name, item.img)
|
||||||
}}
|
}}
|
||||||
@@ -175,12 +204,12 @@ export default function AddMemberDivision() {
|
|||||||
<View style={[Styles.ml10]}>
|
<View style={[Styles.ml10]}>
|
||||||
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode="tail">{item.name}</Text>
|
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode="tail">{item.name}</Text>
|
||||||
{
|
{
|
||||||
found && <Text style={[Styles.textInformation, Styles.cGray]}>sudah menjadi anggota</Text>
|
found && <Text style={[Styles.textInformation, { color: colors.dimmed }]}>sudah menjadi anggota</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={'black'} />
|
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={colors.text} />
|
||||||
}
|
}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiEditDivision, apiGetDivisionOneDetail } from "@/lib/api";
|
import { apiEditDivision, apiGetDivisionOneDetail } from "@/lib/api";
|
||||||
import { setUpdateDivision } from "@/lib/divisionUpdate";
|
import { setUpdateDivision } from "@/lib/divisionUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -12,6 +13,7 @@ import Toast from "react-native-toast-message";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function EditDivision() {
|
export default function EditDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.divisionUpdate)
|
const update = useSelector((state: any) => state.divisionUpdate)
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
@@ -54,16 +56,18 @@ export default function EditDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengubah data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -98,7 +102,7 @@ export default function EditDivision() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView>
|
<ScrollView style={{ backgroundColor: colors.background }}>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Nama Divisi"
|
label="Nama Divisi"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import CaraouselHome from "@/components/home/carouselHome"
|
|||||||
import Styles from "@/constants/Styles"
|
import Styles from "@/constants/Styles"
|
||||||
import { apiGetDivisionOneDetail } from "@/lib/api"
|
import { apiGetDivisionOneDetail } from "@/lib/api"
|
||||||
import { useAuthSession } from "@/providers/AuthProvider"
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider"
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router"
|
import { router, Stack, useLocalSearchParams } from "expo-router"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { RefreshControl, SafeAreaView, ScrollView, View } from "react-native"
|
import { RefreshControl, SafeAreaView, ScrollView, View } from "react-native"
|
||||||
@@ -22,6 +23,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function DetailDivisionFitur() {
|
export default function DetailDivisionFitur() {
|
||||||
|
const { colors } = useTheme()
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [data, setData] = useState<Props>()
|
const [data, setData] = useState<Props>()
|
||||||
@@ -54,7 +56,7 @@ export default function DetailDivisionFitur() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -76,6 +78,7 @@ export default function DetailDivisionFitur() {
|
|||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi"
|
|
||||||
import AppHeader from "@/components/AppHeader"
|
import AppHeader from "@/components/AppHeader"
|
||||||
import BorderBottomItem from "@/components/borderBottomItem"
|
|
||||||
import HeaderRightDivisionInfo from "@/components/division/headerDivisionInfo"
|
|
||||||
import DrawerBottom from "@/components/drawerBottom"
|
import DrawerBottom from "@/components/drawerBottom"
|
||||||
|
import HeaderRightDivisionInfo from "@/components/division/headerDivisionInfo"
|
||||||
import ImageUser from "@/components/imageNew"
|
import ImageUser from "@/components/imageNew"
|
||||||
|
import MenuItemRow from "@/components/menuItemRow"
|
||||||
|
import ModalConfirmation from "@/components/ModalConfirmation"
|
||||||
import SectionCancel from "@/components/sectionCancel"
|
import SectionCancel from "@/components/sectionCancel"
|
||||||
import Skeleton from "@/components/skeleton"
|
|
||||||
import SkeletonTwoItem from "@/components/skeletonTwoItem"
|
|
||||||
import Text from "@/components/Text"
|
import Text from "@/components/Text"
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus"
|
|
||||||
import { ConstEnv } from "@/constants/ConstEnv"
|
import { ConstEnv } from "@/constants/ConstEnv"
|
||||||
import Styles from "@/constants/Styles"
|
import Styles from "@/constants/Styles"
|
||||||
import { apiDeleteMemberDivision, apiGetDivisionOneDetail, apiGetDivisionOneFeature, apiUpdateStatusAdminDivision } from "@/lib/api"
|
import { apiDeleteMemberDivision, apiGetDivisionOneDetail, apiGetDivisionOneFeature, apiUpdateStatusAdminDivision } from "@/lib/api"
|
||||||
import { useAuthSession } from "@/providers/AuthProvider"
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
import { Feather, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
|
import { useTheme } from "@/providers/ThemeProvider"
|
||||||
|
import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router"
|
import { router, Stack, useLocalSearchParams } from "expo-router"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { Pressable, RefreshControl, SafeAreaView, ScrollView, View } from "react-native"
|
import { Pressable, RefreshControl, SafeAreaView, ScrollView, View } from "react-native"
|
||||||
@@ -39,6 +37,7 @@ type PropsMember = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function InformationDivision() {
|
export default function InformationDivision() {
|
||||||
|
const { colors } = useTheme()
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
@@ -48,8 +47,8 @@ export default function InformationDivision() {
|
|||||||
const [dataMember, setDataMember] = useState<PropsMember[]>([])
|
const [dataMember, setDataMember] = useState<PropsMember[]>([])
|
||||||
const [refresh, setRefresh] = useState(false)
|
const [refresh, setRefresh] = useState(false)
|
||||||
const update = useSelector((state: any) => state.divisionUpdate)
|
const update = useSelector((state: any) => state.divisionUpdate)
|
||||||
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
const SKELETON_COUNT = 5
|
||||||
const [isMemberDivision, setIsMemberDivision] = useState(false)
|
const [isMemberDivision, setIsMemberDivision] = useState(false)
|
||||||
const [isAdminDivision, setIsAdminDivision] = useState(false)
|
const [isAdminDivision, setIsAdminDivision] = useState(false)
|
||||||
const [dataMemberChoose, setDataMemberChoose] = useState({
|
const [dataMemberChoose, setDataMemberChoose] = useState({
|
||||||
@@ -57,14 +56,13 @@ export default function InformationDivision() {
|
|||||||
name: '',
|
name: '',
|
||||||
isAdmin: false
|
isAdmin: false
|
||||||
})
|
})
|
||||||
|
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||||
|
|
||||||
function handleMemberOut() {
|
function handleMemberOut() {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
AlertKonfirmasi({
|
setTimeout(() => {
|
||||||
title: 'Konfirmasi',
|
setShowDeleteModal(true)
|
||||||
desc: 'Apakah anda yakin ingin mengeluarkan anggota?',
|
}, 600)
|
||||||
onPress: () => { memberOut() }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function memberOut() {
|
async function memberOut() {
|
||||||
@@ -77,9 +75,11 @@ export default function InformationDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengeluarkan anggota"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
}
|
}
|
||||||
@@ -95,9 +95,11 @@ export default function InformationDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengubah status admin"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
}
|
}
|
||||||
@@ -161,7 +163,7 @@ export default function InformationDivision() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -181,110 +183,138 @@ export default function InformationDivision() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
refreshControl={
|
showsVerticalScrollIndicator={false}
|
||||||
<RefreshControl
|
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} tintColor={colors.icon} />}
|
||||||
refreshing={refreshing}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
onRefresh={handleRefresh}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
style={[Styles.h100]}
|
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
{
|
|
||||||
dataDetail?.isActive == false && (
|
{dataDetail?.isActive === false && <SectionCancel title="Divisi nonaktif" />}
|
||||||
<SectionCancel title={'Divisi nonaktif'} />
|
|
||||||
)
|
{/* Deskripsi */}
|
||||||
}
|
<View style={[Styles.wrapPaper, Styles.sectionCard, Styles.noShadow, Styles.mb15,
|
||||||
<View style={[Styles.mb15]}>
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
<Text style={[Styles.textDefaultSemiBold, Styles.mb05]}>Deskripsi Divisi</Text>
|
<View style={[Styles.sectionActionRow, { marginBottom: 12 }]}>
|
||||||
<View style={[Styles.wrapPaper]}>
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
{loading ?
|
<MaterialIcons name="info-outline" size={18} color={colors.dimmed} />
|
||||||
arrSkeleton.map((item, index) => {
|
</View>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, Styles.flex1, { color: colors.text }]}>Deskripsi</Text>
|
||||||
|
</View>
|
||||||
|
{loading
|
||||||
|
? Array.from({ length: 3 }).map((_, i) => (
|
||||||
|
<View key={i} style={{ height: 13, borderRadius: 6, marginBottom: 8, backgroundColor: colors.icon + '20', width: i === 2 ? '60%' : '100%' }} />
|
||||||
|
))
|
||||||
|
: <Text style={[Styles.textDefault, { color: colors.text, lineHeight: 22 }]}>{dataDetail?.desc}</Text>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* Tombol tambah anggota */}
|
||||||
|
{((entityUser.role !== "user" && entityUser.role !== "coadmin") || isAdminDivision) && dataDetail?.isActive && (
|
||||||
|
<View style={[Styles.wrapPaper, Styles.sectionCard, Styles.mb15,
|
||||||
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }]}>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => router.push(`/division/${id}/add-member`)}
|
||||||
|
style={Styles.sectionActionRow}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '18' }]}>
|
||||||
|
<MaterialCommunityIcons name="account-plus-outline" size={18} color={colors.icon} />
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, Styles.flex1, { color: colors.text }]}>Tambah Anggota</Text>
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Daftar anggota */}
|
||||||
|
<View style={[Styles.wrapPaper, Styles.sectionCard,
|
||||||
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18', padding: 0, overflow: 'hidden' }]}>
|
||||||
|
|
||||||
|
{/* Header */}
|
||||||
|
<View style={[Styles.sectionActionRow, { padding: 16, borderBottomWidth: 1, borderBottomColor: colors.icon + '14' }]}>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<MaterialIcons name="people" size={18} color={colors.dimmed} />
|
||||||
|
</View>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, Styles.flex1, { color: colors.text }]}>Anggota</Text>
|
||||||
|
{!loading && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>{dataMember.length} anggota</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{loading
|
||||||
|
? Array.from({ length: SKELETON_COUNT }).map((_, i) => (
|
||||||
|
<View key={i} style={[Styles.rowItemsCenter, Styles.ph15,
|
||||||
|
{ paddingVertical: 14, gap: 14, borderBottomWidth: i < SKELETON_COUNT - 1 ? 1 : 0, borderBottomColor: colors.icon + '14' }]}>
|
||||||
|
<View style={[Styles.userProfileExtraSmall, { backgroundColor: colors.icon + '20', borderRadius: 100 }]} />
|
||||||
|
<View style={{ height: 13, borderRadius: 6, flex: 1, backgroundColor: colors.icon + '20', maxWidth: 140 + (i % 3) * 30 }} />
|
||||||
|
</View>
|
||||||
|
))
|
||||||
|
: dataMember.length === 0
|
||||||
|
? (
|
||||||
|
<View style={[Styles.contentItemCenter, { paddingVertical: 40 }]}>
|
||||||
|
<MaterialIcons name="people-outline" size={34} color={colors.icon + '50'} />
|
||||||
|
<Text style={[Styles.textMediumNormal, Styles.mt10, { color: colors.dimmed }]}>Belum ada anggota</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
: dataMember.map((item, index) => {
|
||||||
|
const canPress = dataDetail?.isActive && (isAdminDivision || (entityUser.role !== "user" && entityUser.role !== "coadmin"))
|
||||||
return (
|
return (
|
||||||
<Skeleton key={index} width={100} height={10} widthType="percent" borderRadius={10} />
|
<Pressable
|
||||||
|
key={index}
|
||||||
|
onPress={() => canPress && handleChooseMember(item)}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
Styles.rowItemsCenter, Styles.ph15,
|
||||||
|
{
|
||||||
|
paddingVertical: 13, gap: 14,
|
||||||
|
borderBottomWidth: index < dataMember.length - 1 ? 1 : 0,
|
||||||
|
borderBottomColor: colors.icon + '14',
|
||||||
|
backgroundColor: pressed && canPress ? colors.icon + '0E' : 'transparent',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
|
||||||
|
<Text style={[Styles.textDefault, Styles.flex1, { color: colors.text }]} numberOfLines={1}>
|
||||||
|
{item.name}
|
||||||
|
</Text>
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: item.isAdmin ? colors.tabActive : colors.dimmed }]}>
|
||||||
|
{item.isAdmin ? 'Admin' : 'Anggota'}
|
||||||
|
</Text>
|
||||||
|
{canPress && <MaterialCommunityIcons name="chevron-right" size={18} color={colors.icon + '60'} />}
|
||||||
|
</Pressable>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
:
|
}
|
||||||
<Text>{dataDetail?.desc}</Text>
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
</View>
|
</View>
|
||||||
<View style={[Styles.mb15]}>
|
|
||||||
<Text style={[Styles.textDefault, Styles.mv05]}>{dataMember.length} Anggota</Text>
|
|
||||||
<View style={[Styles.wrapPaper]}>
|
|
||||||
{
|
|
||||||
((entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision) &&
|
|
||||||
dataDetail?.isActive && (
|
|
||||||
<BorderBottomItem
|
|
||||||
onPress={() => { router.push(`/division/${id}/add-member`) }}
|
|
||||||
borderType="none"
|
|
||||||
icon={
|
|
||||||
<View style={[Styles.iconContent, ColorsStatus.gray]}>
|
|
||||||
<Feather name="user-plus" size={25} color={'#384288'} />
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
title="Tambah Anggota"
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
loading ?
|
|
||||||
arrSkeleton.map((item, index) => {
|
|
||||||
return (
|
|
||||||
<SkeletonTwoItem key={index} />
|
|
||||||
)
|
|
||||||
})
|
|
||||||
:
|
|
||||||
dataMember.map((item, index) => {
|
|
||||||
return (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={index}
|
|
||||||
borderType="bottom"
|
|
||||||
onPress={() => { dataDetail?.isActive && (isAdminDivision || (entityUser.role != "user" && entityUser.role != "coadmin")) && handleChooseMember(item) }}
|
|
||||||
icon={
|
|
||||||
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="sm" />
|
|
||||||
}
|
|
||||||
title={item.name}
|
|
||||||
rightTopInfo={item.isAdmin ? "Admin" : "Anggota"}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title={dataMemberChoose.name}>
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title={dataMemberChoose.name}>
|
||||||
<View>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<Pressable style={[Styles.wrapItemBorderBottom]} onPress={() => { handleMemberAdmin() }}>
|
<MenuItemRow
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
icon={<MaterialIcons name="verified-user" color={colors.text} size={25} />}
|
||||||
<View style={[Styles.iconContent, ColorsStatus.info]}>
|
title={dataMemberChoose.isAdmin ? 'Berhentikan admin' : 'Jadikan admin'}
|
||||||
<MaterialIcons name="verified-user" size={25} color='#19345E' />
|
onPress={handleMemberAdmin}
|
||||||
</View>
|
/>
|
||||||
<View style={[Styles.rowSpaceBetween, { width: '88%' }]}>
|
<MenuItemRow
|
||||||
<View style={[Styles.ml10]}>
|
icon={<MaterialCommunityIcons name="account-remove" color={colors.text} size={25} />}
|
||||||
<Text style={[Styles.textDefault]}>{dataMemberChoose.isAdmin ? 'Memberhentikan sebagai admin' : 'Jadikan admin'}</Text>
|
title="Keluarkan"
|
||||||
</View>
|
onPress={handleMemberOut}
|
||||||
</View>
|
/>
|
||||||
</View>
|
|
||||||
</Pressable>
|
|
||||||
|
|
||||||
<Pressable style={[Styles.wrapItemBorderBottom]} onPress={() => { handleMemberOut() }}>
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<View style={[Styles.iconContent, ColorsStatus.info]}>
|
|
||||||
<MaterialCommunityIcons name="close-circle" size={25} color='#19345E' />
|
|
||||||
</View>
|
|
||||||
<View style={[Styles.rowSpaceBetween, { width: '88%' }]}>
|
|
||||||
<View style={[Styles.ml10]}>
|
|
||||||
<Text style={[Styles.textDefault]}>Keluarkan dari divisi</Text>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message="Apakah anda yakin ingin mengeluarkan anggota?"
|
||||||
|
onConfirm={() => {
|
||||||
|
setShowDeleteModal(false)
|
||||||
|
memberOut()
|
||||||
|
}}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText="Keluar"
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ import { InputDate } from "@/components/inputDate"
|
|||||||
import Styles from "@/constants/Styles"
|
import Styles from "@/constants/Styles"
|
||||||
import { apiGetDivisionReport } from "@/lib/api"
|
import { apiGetDivisionReport } from "@/lib/api"
|
||||||
import { stringToDate } from "@/lib/fun_stringToDate"
|
import { stringToDate } from "@/lib/fun_stringToDate"
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider"
|
||||||
import { useAuthSession } from "@/providers/AuthProvider"
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
import dayjs from "dayjs"
|
import dayjs from "dayjs"
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router"
|
import { router, Stack, useLocalSearchParams } from "expo-router"
|
||||||
@@ -14,6 +15,7 @@ import { SafeAreaView, ScrollView, View } from "react-native"
|
|||||||
import Toast from "react-native-toast-message"
|
import Toast from "react-native-toast-message"
|
||||||
|
|
||||||
export default function ReportDivision() {
|
export default function ReportDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const [showReport, setShowReport] = useState(false);
|
const [showReport, setShowReport] = useState(false);
|
||||||
@@ -92,8 +94,11 @@ export default function ReportDivision() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, });
|
Toast.show({ type: 'small', text1: response.message, });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
const message = error?.response?.data?.message || "Gagal mengambil data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +109,7 @@ export default function ReportDivision() {
|
|||||||
}, [showReport]);
|
}, [showReport]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -119,7 +124,7 @@ export default function ReportDivision() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView>
|
<ScrollView style={{ backgroundColor: colors.background }}>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<InputDate
|
<InputDate
|
||||||
onChange={(val) => validationForm("date", val)}
|
onChange={(val) => validationForm("date", val)}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi";
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonNextHeader from "@/components/buttonNextHeader";
|
import ButtonNextHeader from "@/components/buttonNextHeader";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
@@ -8,6 +8,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiCheckDivisionName } from "@/lib/api";
|
import { apiCheckDivisionName } from "@/lib/api";
|
||||||
import { setFormCreateDivision } from "@/lib/divisionCreate";
|
import { setFormCreateDivision } from "@/lib/divisionCreate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -15,6 +16,7 @@ import Toast from "react-native-toast-message";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function CreateDivision() {
|
export default function CreateDivision() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const [isSelect, setSelect] = useState(false)
|
const [isSelect, setSelect] = useState(false)
|
||||||
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" })
|
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" })
|
||||||
@@ -23,6 +25,7 @@ export default function CreateDivision() {
|
|||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const userLogin = useSelector((state: any) => state.entities)
|
const userLogin = useSelector((state: any) => state.entities)
|
||||||
const [loadingBtn, setLoadingBtn] = useState(false)
|
const [loadingBtn, setLoadingBtn] = useState(false)
|
||||||
|
const [showWarningModal, setShowWarningModal] = useState(false)
|
||||||
const [error, setError] = useState({
|
const [error, setError] = useState({
|
||||||
idGroup: false,
|
idGroup: false,
|
||||||
name: false,
|
name: false,
|
||||||
@@ -67,21 +70,18 @@ export default function CreateDivision() {
|
|||||||
const response = await apiCheckDivisionName({ data: { ...dataForm }, user: hasil })
|
const response = await apiCheckDivisionName({ data: { ...dataForm }, user: hasil })
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
if (!response.available) {
|
if (!response.available) {
|
||||||
AlertKonfirmasi({
|
setShowWarningModal(true)
|
||||||
title: 'Peringatan',
|
|
||||||
category: 'warning',
|
|
||||||
desc: 'Nama divisi sudah ada. Tidak dapat membuat divisi dengan nama yang sama',
|
|
||||||
onPress: () => { }
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
handleSetData()
|
handleSetData()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingBtn(false)
|
setLoadingBtn(false)
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ export default function CreateDivision() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -131,7 +131,7 @@ export default function CreateDivision() {
|
|||||||
/>
|
/>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
{
|
{
|
||||||
@@ -179,6 +179,15 @@ export default function CreateDivision() {
|
|||||||
open={isSelect}
|
open={isSelect}
|
||||||
valChoose={chooseGroup.val}
|
valChoose={chooseGroup.val}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showWarningModal}
|
||||||
|
title="Peringatan"
|
||||||
|
message="Nama divisi sudah ada. Tidak dapat membuat divisi dengan nama yang sama"
|
||||||
|
onConfirm={() => setShowWarningModal(false)}
|
||||||
|
onCancel={() => setShowWarningModal(false)}
|
||||||
|
confirmText="Oke"
|
||||||
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { apiCreateDivision } from "@/lib/api";
|
|||||||
import { setFormCreateDivision } from "@/lib/divisionCreate";
|
import { setFormCreateDivision } from "@/lib/divisionCreate";
|
||||||
import { setUpdateDivision } from "@/lib/divisionUpdate";
|
import { setUpdateDivision } from "@/lib/divisionUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { AntDesign } from "@expo/vector-icons";
|
||||||
import { StackActions, useNavigation } from "@react-navigation/native";
|
import { StackActions, useNavigation } from "@react-navigation/native";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
@@ -23,6 +24,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function CreateDivisionAddAdmin() {
|
export default function CreateDivisionAddAdmin() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const navigation = useNavigation()
|
const navigation = useNavigation()
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
@@ -64,9 +66,11 @@ export default function CreateDivisionAddAdmin() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -104,7 +108,7 @@ export default function CreateDivisionAddAdmin() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
{
|
{
|
||||||
data.length > 0 ?
|
data.length > 0 ?
|
||||||
@@ -113,7 +117,7 @@ export default function CreateDivisionAddAdmin() {
|
|||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={index}
|
key={index}
|
||||||
style={[Styles.itemSelectModal]}
|
style={[Styles.itemSelectModal, { borderBottomColor: colors.icon + '20' }]}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
!found && onChoose(item.idUser)
|
!found && onChoose(item.idUser)
|
||||||
}}
|
}}
|
||||||
@@ -123,12 +127,12 @@ export default function CreateDivisionAddAdmin() {
|
|||||||
<View style={[Styles.ml10]}>
|
<View style={[Styles.ml10]}>
|
||||||
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode="tail">{item.name}</Text>
|
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode="tail">{item.name}</Text>
|
||||||
{
|
{
|
||||||
found && <Text style={[Styles.textInformation, Styles.cGray]}>sudah menjadi anggota</Text>
|
found && <Text style={[Styles.textInformation, { color: colors.dimmed }]}>sudah menjadi anggota</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
selectMember.some((i: any) => i == item.idUser) && <AntDesign name="check" size={20} color={'black'} />
|
selectMember.some((i: any) => i == item.idUser) && <AntDesign name="check" size={20} color={colors.text} />
|
||||||
}
|
}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiGetUser } from "@/lib/api";
|
import { apiGetUser } from "@/lib/api";
|
||||||
import { setFormCreateDivision } from "@/lib/divisionCreate";
|
import { setFormCreateDivision } from "@/lib/divisionCreate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { AntDesign } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -22,6 +23,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function CreateDivisionAddMember() {
|
export default function CreateDivisionAddMember() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [dataOld, setDataOld] = useState<Props[]>([])
|
const [dataOld, setDataOld] = useState<Props[]>([])
|
||||||
@@ -53,6 +55,21 @@ export default function CreateDivisionAddMember() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isAllSelected = data.length > 0 && data.every((item: any) =>
|
||||||
|
selectMember.some((s: any) => s.idUser == item.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
function handleSelectAll() {
|
||||||
|
if (isAllSelected) {
|
||||||
|
setSelectMember([])
|
||||||
|
} else {
|
||||||
|
const newMembers = data
|
||||||
|
.filter((item: any) => !selectMember.some((s: any) => s.idUser == item.id))
|
||||||
|
.map((item: any) => ({ idUser: item.id, name: item.name, img: item.img }))
|
||||||
|
setSelectMember([...selectMember, ...newMembers])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleAddMember() {
|
async function handleAddMember() {
|
||||||
dispatch(setFormCreateDivision({ ...update, member: selectMember }))
|
dispatch(setFormCreateDivision({ ...update, member: selectMember }))
|
||||||
router.push(`./add-admin-division`)
|
router.push(`./add-admin-division`)
|
||||||
@@ -84,14 +101,14 @@ export default function CreateDivisionAddMember() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
<InputSearch onChange={(val) => setSearch(val)} value={search} />
|
<InputSearch onChange={(val) => setSearch(val)} value={search} />
|
||||||
|
|
||||||
{
|
{
|
||||||
selectMember.length > 0
|
selectMember.length > 0
|
||||||
?
|
?
|
||||||
<View>
|
<View>
|
||||||
<ScrollView horizontal style={[Styles.mb10, Styles.pv10]} showsHorizontalScrollIndicator={false}>
|
<ScrollView horizontal style={[Styles.mb05, Styles.pv10]} showsHorizontalScrollIndicator={false}>
|
||||||
{
|
{
|
||||||
selectMember.map((item: any, index: any) => (
|
selectMember.map((item: any, index: any) => (
|
||||||
<ImageWithLabel
|
<ImageWithLabel
|
||||||
@@ -106,12 +123,21 @@ export default function CreateDivisionAddMember() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.pv05, { textAlign: 'center' }]}>Tidak ada member yang dipilih</Text>
|
<Text style={[Styles.textDefault, Styles.pv05, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada member yang dipilih</Text>
|
||||||
}
|
}
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
{data.length > 0 && (
|
||||||
|
<Pressable
|
||||||
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20', paddingTop: 0 }]}
|
||||||
|
onPress={handleSelectAll}
|
||||||
|
>
|
||||||
|
<Text style={[Styles.textMediumSemiBold]}>{isAllSelected ? 'Batalkan Semua' : 'Pilih Semua'}</Text>
|
||||||
|
{isAllSelected && <AntDesign name="check" size={20} color={colors.text} />}
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
{
|
{
|
||||||
data.length > 0 ?
|
data.length > 0 ?
|
||||||
data.map((item: any, index: any) => {
|
data.map((item: any, index: any) => {
|
||||||
@@ -119,7 +145,7 @@ export default function CreateDivisionAddMember() {
|
|||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={index}
|
key={index}
|
||||||
style={[Styles.itemSelectModal]}
|
style={[Styles.itemSelectModal, { borderBottomColor: colors.icon + '20' }]}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
!found && onChoose(item.id, item.name, item.img)
|
!found && onChoose(item.id, item.name, item.img)
|
||||||
}}
|
}}
|
||||||
@@ -129,12 +155,12 @@ export default function CreateDivisionAddMember() {
|
|||||||
<View style={[Styles.ml10]}>
|
<View style={[Styles.ml10]}>
|
||||||
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode="tail">{item.name}</Text>
|
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode="tail">{item.name}</Text>
|
||||||
{
|
{
|
||||||
found && <Text style={[Styles.textInformation, Styles.cGray]}>sudah menjadi anggota</Text>
|
found && <Text style={[Styles.textInformation, { color: colors.dimmed }]}>sudah menjadi anggota</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={'black'} />
|
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={colors.text} />
|
||||||
}
|
}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,19 +6,21 @@ import PaperGridContent from "@/components/paperGridContent";
|
|||||||
import Skeleton from "@/components/skeleton";
|
import Skeleton from "@/components/skeleton";
|
||||||
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
import WrapTab from "@/components/wrapTab";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetDivision } from "@/lib/api";
|
import { apiGetDivision } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import {
|
import {
|
||||||
AntDesign,
|
AntDesign,
|
||||||
Feather,
|
Feather,
|
||||||
Ionicons,
|
Ionicons,
|
||||||
MaterialCommunityIcons,
|
MaterialCommunityIcons
|
||||||
MaterialIcons,
|
|
||||||
} from "@expo/vector-icons";
|
} from "@expo/vector-icons";
|
||||||
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
|
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { router, useLocalSearchParams } from "expo-router";
|
import { router, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { Pressable, RefreshControl, View, VirtualizedList } from "react-native";
|
import { Pressable, RefreshControl, View, VirtualizedList } from "react-native";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
@@ -36,25 +38,39 @@ export default function ListDivision() {
|
|||||||
cat?: string;
|
cat?: string;
|
||||||
}>();
|
}>();
|
||||||
const [isList, setList] = useState(false);
|
const [isList, setList] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
AsyncStorage.getItem('division_view_mode').then((val) => {
|
||||||
|
if (val !== null) setList(val === 'list')
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
function toggleView() {
|
||||||
|
const next = !isList
|
||||||
|
setList(next)
|
||||||
|
AsyncStorage.setItem('division_view_mode', next ? 'list' : 'grid')
|
||||||
|
}
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const [search, setSearch] = useState("")
|
const [search, setSearch] = useState("")
|
||||||
const [nameGroup, setNameGroup] = useState("")
|
const queryClient = useQueryClient()
|
||||||
const [data, setData] = useState<Props[]>([])
|
const [status, setStatus] = useState<'true' | 'false'>(active == 'false' ? 'false' : 'true')
|
||||||
|
const [category, setCategory] = useState<'divisi-saya' | 'semua'>(cat == 'semua' ? 'semua' : 'divisi-saya')
|
||||||
const update = useSelector((state: any) => state.divisionUpdate)
|
const update = useSelector((state: any) => state.divisionUpdate)
|
||||||
const arrSkeleton = Array.from({ length: 3 }, (_, index) => index)
|
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
const [status, setStatus] = useState<'true' | 'false'>('true')
|
|
||||||
const [category, setCategory] = useState<'divisi-saya' | 'semua'>('divisi-saya')
|
|
||||||
const [page, setPage] = useState(1)
|
|
||||||
const [waiting, setWaiting] = useState(false)
|
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
|
||||||
async function handleLoad(loading: boolean, thisPage: number) {
|
// TanStack Query for Divisions with Infinite Scroll
|
||||||
try {
|
const {
|
||||||
setWaiting(true)
|
data,
|
||||||
setLoading(loading)
|
fetchNextPage,
|
||||||
setPage(thisPage)
|
hasNextPage,
|
||||||
|
isFetchingNextPage,
|
||||||
|
isLoading,
|
||||||
|
refetch
|
||||||
|
} = useInfiniteQuery({
|
||||||
|
queryKey: ['divisions', { status, search, group, category }],
|
||||||
|
queryFn: async ({ pageParam = 1 }) => {
|
||||||
const hasil = await decryptToken(String(token?.current));
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiGetDivision({
|
const response = await apiGetDivision({
|
||||||
user: hasil,
|
user: hasil,
|
||||||
@@ -62,63 +78,61 @@ export default function ListDivision() {
|
|||||||
search: search,
|
search: search,
|
||||||
group: String(group),
|
group: String(group),
|
||||||
kategori: category,
|
kategori: category,
|
||||||
page: thisPage
|
page: pageParam
|
||||||
});
|
});
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
initialPageParam: 1,
|
||||||
|
getNextPageParam: (lastPage, allPages) => {
|
||||||
|
return lastPage.data.length > 0 ? allPages.length + 1 : undefined;
|
||||||
|
},
|
||||||
|
enabled: !!token?.current,
|
||||||
|
staleTime: 0,
|
||||||
|
})
|
||||||
|
|
||||||
if (response.success) {
|
// Refetch when manual update state changes
|
||||||
if (thisPage == 1) {
|
|
||||||
setData(response.data);
|
|
||||||
} else if (thisPage > 1 && response.data.length > 0) {
|
|
||||||
setData([...data, ...response.data]);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setNameGroup(response.filter.name);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
setWaiting(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLoad(false, 1);
|
refetch()
|
||||||
}, [update]);
|
}, [update, refetch])
|
||||||
|
|
||||||
useEffect(() => {
|
// Flatten pages into a single data array
|
||||||
handleLoad(true, 1);
|
const flatData = useMemo(() => {
|
||||||
}, [status, search, group, category]);
|
return data?.pages.flatMap(page => page.data) || [];
|
||||||
|
}, [data])
|
||||||
|
|
||||||
const loadMoreData = () => {
|
// Get nameGroup from the first available page
|
||||||
if (waiting) return
|
const nameGroup = useMemo(() => {
|
||||||
setTimeout(() => {
|
return data?.pages[0]?.filter?.name || "";
|
||||||
handleLoad(false, page + 1)
|
}, [data])
|
||||||
}, 1000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleLoad(false, 1)
|
await queryClient.invalidateQueries({ queryKey: ['divisions'] })
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadMoreData = () => {
|
||||||
|
if (hasNextPage && !isFetchingNextPage) {
|
||||||
|
fetchNextPage()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const arrSkeleton = [0, 1, 2]
|
||||||
|
|
||||||
const getItem = (_data: unknown, index: number): Props => ({
|
const getItem = (_data: unknown, index: number): Props => ({
|
||||||
id: data[index].id,
|
id: flatData[index]?.id,
|
||||||
name: data[index].name,
|
name: flatData[index]?.name,
|
||||||
desc: data[index].desc,
|
desc: flatData[index]?.desc,
|
||||||
jumlah_member: data[index].jumlah_member,
|
jumlah_member: flatData[index]?.jumlah_member,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
<View>
|
<View>
|
||||||
{
|
{
|
||||||
entityUser.role != "user" && entityUser.role != "coadmin" ?
|
entityUser.role != "user" && entityUser.role != "coadmin" ?
|
||||||
<View style={[Styles.wrapBtnTab]}>
|
<WrapTab>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="true"
|
value="true"
|
||||||
@@ -127,7 +141,7 @@ export default function ListDivision() {
|
|||||||
icon={
|
icon={
|
||||||
<Feather
|
<Feather
|
||||||
name="check-circle"
|
name="check-circle"
|
||||||
color={status == "false" ? "black" : "white"}
|
color={status == "false" ? colors.dimmed : "white"}
|
||||||
size={20}
|
size={20}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -141,15 +155,15 @@ export default function ListDivision() {
|
|||||||
icon={
|
icon={
|
||||||
<AntDesign
|
<AntDesign
|
||||||
name="closecircleo"
|
name="closecircleo"
|
||||||
color={status == "true" ? "black" : "white"}
|
color={status == "true" ? colors.dimmed : "white"}
|
||||||
size={20}
|
size={20}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
n={2}
|
n={2}
|
||||||
/>
|
/>
|
||||||
</View>
|
</WrapTab>
|
||||||
:
|
:
|
||||||
<View style={[Styles.wrapBtnTab]}>
|
<WrapTab>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={category == "semua" ? "false" : "true"}
|
active={category == "semua" ? "false" : "true"}
|
||||||
value="true"
|
value="true"
|
||||||
@@ -158,7 +172,7 @@ export default function ListDivision() {
|
|||||||
icon={
|
icon={
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="file-tray-outline"
|
name="file-tray-outline"
|
||||||
color={category == "semua" ? "black" : "white"}
|
color={category == "semua" ? colors.dimmed : "white"}
|
||||||
size={20}
|
size={20}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -172,39 +186,35 @@ export default function ListDivision() {
|
|||||||
icon={
|
icon={
|
||||||
<Ionicons
|
<Ionicons
|
||||||
name="file-tray-stacked-outline"
|
name="file-tray-stacked-outline"
|
||||||
color={category == "semua" ? "white" : "black"}
|
color={category == "semua" ? "white" : colors.dimmed}
|
||||||
size={20}
|
size={20}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
n={2}
|
n={2}
|
||||||
/>
|
/>
|
||||||
</View>
|
</WrapTab>
|
||||||
}
|
}
|
||||||
|
|
||||||
<View style={[Styles.rowSpaceBetween, { alignItems: 'center' }]}>
|
<View style={[Styles.rowSpaceBetween, { alignItems: 'center' }]}>
|
||||||
<InputSearch width={68} onChange={setSearch} />
|
<InputSearch width={68} onChange={setSearch} />
|
||||||
<Pressable
|
<Pressable onPress={toggleView}>
|
||||||
onPress={() => {
|
|
||||||
setList(!isList);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MaterialCommunityIcons
|
<MaterialCommunityIcons
|
||||||
name={isList ? "format-list-bulleted" : "view-grid"}
|
name={isList ? "format-list-bulleted" : "view-grid"}
|
||||||
color={"black"}
|
color={colors.text}
|
||||||
size={30}
|
size={30}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
{(entityUser.role == "supadmin" || entityUser.role == "developer") && (
|
{(entityUser.role == "supadmin" || entityUser.role == "developer") && (
|
||||||
<View style={[Styles.mv05, Styles.rowOnly]}>
|
<View style={[Styles.mt10, Styles.rowOnly]}>
|
||||||
<Text>Filter :</Text>
|
<Text>Filter :</Text>
|
||||||
<LabelStatus size="small" category="secondary" text={nameGroup} style={[Styles.mh05]} />
|
<LabelStatus size="small" category="secondary" text={nameGroup} style={[Styles.mh05]} />
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ flex: 2 }, Styles.mt05]}>
|
<View style={[{ flex: 2 }, Styles.mt10]}>
|
||||||
{
|
{
|
||||||
loading ?
|
isLoading ?
|
||||||
isList ?
|
isList ?
|
||||||
arrSkeleton.map((item, index) => (
|
arrSkeleton.map((item, index) => (
|
||||||
<SkeletonTwoItem key={index} />
|
<SkeletonTwoItem key={index} />
|
||||||
@@ -214,17 +224,17 @@ export default function ListDivision() {
|
|||||||
<Skeleton key={index} width={100} height={180} widthType="percent" borderRadius={10} />
|
<Skeleton key={index} width={100} height={180} widthType="percent" borderRadius={10} />
|
||||||
))
|
))
|
||||||
:
|
:
|
||||||
data.length == 0 ? (
|
flatData.length == 0 ? (
|
||||||
<View style={[Styles.mt15]}>
|
<View style={[Styles.mt15]}>
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
|
<Text style={[Styles.textDefault, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada data</Text>
|
||||||
</View>
|
</View>
|
||||||
) : (
|
) : (
|
||||||
isList ? (
|
isList ? (
|
||||||
<View style={[Styles.h100]}>
|
<View style={[Styles.h100]}>
|
||||||
<VirtualizedList
|
<VirtualizedList
|
||||||
data={data}
|
data={flatData}
|
||||||
style={[{ paddingBottom: 100 }]}
|
style={[{ paddingBottom: 100 }]}
|
||||||
getItemCount={() => data.length}
|
getItemCount={() => flatData.length}
|
||||||
getItem={getItem}
|
getItem={getItem}
|
||||||
renderItem={({ item, index }: { item: Props, index: number }) => {
|
renderItem={({ item, index }: { item: Props, index: number }) => {
|
||||||
return (
|
return (
|
||||||
@@ -232,13 +242,13 @@ export default function ListDivision() {
|
|||||||
key={index}
|
key={index}
|
||||||
onPress={() => { router.push(`/division/${item.id}`) }}
|
onPress={() => { router.push(`/division/${item.id}`) }}
|
||||||
borderType="bottom"
|
borderType="bottom"
|
||||||
|
bgColor="transparent"
|
||||||
icon={
|
icon={
|
||||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
<View style={[Styles.iconContent]}>
|
||||||
<MaterialIcons name="group" size={25} color={"#384288"} />
|
<Feather name="users" size={25} color={'black'} />
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
title={item.name}
|
title={item.name}
|
||||||
titleWeight="normal"
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
@@ -250,6 +260,7 @@ export default function ListDivision() {
|
|||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -257,9 +268,9 @@ export default function ListDivision() {
|
|||||||
) : (
|
) : (
|
||||||
<View style={[Styles.h100]}>
|
<View style={[Styles.h100]}>
|
||||||
<VirtualizedList
|
<VirtualizedList
|
||||||
data={data}
|
data={flatData}
|
||||||
style={[{ paddingBottom: 100 }]}
|
style={[{ paddingBottom: 100 }]}
|
||||||
getItemCount={() => data.length}
|
getItemCount={() => flatData.length}
|
||||||
getItem={getItem}
|
getItem={getItem}
|
||||||
renderItem={({ item, index }: { item: Props, index: number }) => {
|
renderItem={({ item, index }: { item: Props, index: number }) => {
|
||||||
return (
|
return (
|
||||||
@@ -285,6 +296,7 @@ export default function ListDivision() {
|
|||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiGetDivisionReport } from "@/lib/api";
|
import { apiGetDivisionReport } from "@/lib/api";
|
||||||
import { stringToDate } from "@/lib/fun_stringToDate";
|
import { stringToDate } from "@/lib/fun_stringToDate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -16,6 +17,7 @@ import { SafeAreaView, ScrollView, View } from "react-native";
|
|||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
export default function Report() {
|
export default function Report() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" });
|
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" });
|
||||||
const [showReport, setShowReport] = useState(false);
|
const [showReport, setShowReport] = useState(false);
|
||||||
@@ -110,8 +112,11 @@ export default function Report() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
const message = error?.response?.data?.message || "Gagal mengambil data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +127,7 @@ export default function Report() {
|
|||||||
}, [showReport]);
|
}, [showReport]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -144,11 +149,11 @@ export default function Report() {
|
|||||||
/>
|
/>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15, Styles.mb50]}>
|
<View style={[Styles.p15, Styles.mb50]}>
|
||||||
<SelectForm
|
<SelectForm
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
label="Lembaga Desa"
|
label="Lembaga Desa"
|
||||||
placeholder="Pilih Lembaga Desa"
|
placeholder="Pilih Lembaga Desa"
|
||||||
value={chooseGroup.label}
|
value={chooseGroup.label}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import ButtonBackHeader from "@/components/buttonBackHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import ModalSelect from "@/components/modalSelect";
|
import ModalSelect from "@/components/modalSelect";
|
||||||
@@ -10,6 +10,7 @@ import { apiEditProfile, apiGetProfile } from "@/lib/api";
|
|||||||
import { setEntities } from "@/lib/entitiesSlice";
|
import { setEntities } from "@/lib/entitiesSlice";
|
||||||
import { validateName } from "@/lib/fun_validateName";
|
import { validateName } from "@/lib/fun_validateName";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
import { useHeaderHeight } from "@react-navigation/elements";
|
import { useHeaderHeight } from "@react-navigation/elements";
|
||||||
import * as ImagePicker from "expo-image-picker";
|
import * as ImagePicker from "expo-image-picker";
|
||||||
@@ -43,9 +44,11 @@ type Props = {
|
|||||||
export default function EditProfile() {
|
export default function EditProfile() {
|
||||||
const headerHeight = useHeaderHeight()
|
const headerHeight = useHeaderHeight()
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
const { colors } = useTheme();
|
||||||
const entities = useSelector((state: any) => state.entities)
|
const entities = useSelector((state: any) => state.entities)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const [errorImg, setErrorImg] = useState(false)
|
const [errorImg, setErrorImg] = useState(false)
|
||||||
|
// ... keeping state same ...
|
||||||
const [selectedImage, setSelectedImage] = useState<string | undefined | { uri: string }>(undefined);
|
const [selectedImage, setSelectedImage] = useState<string | undefined | { uri: string }>(undefined);
|
||||||
const [choosePosition, setChoosePosition] = useState({ val: entities.idPosition, label: entities.position });
|
const [choosePosition, setChoosePosition] = useState({ val: entities.idPosition, label: entities.position });
|
||||||
const [chooseGender, setChooseGender] = useState({ val: entities.gender, label: entities.gender == "F" ? 'Perempuan' : 'Laki-laki' });
|
const [chooseGender, setChooseGender] = useState({ val: entities.gender, label: entities.gender == "F" ? 'Perempuan' : 'Laki-laki' });
|
||||||
@@ -185,9 +188,14 @@ export default function EditProfile() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Gagal mengupdate data', })
|
const message = error?.response?.data?.message || "Gagal mengupdate data"
|
||||||
|
|
||||||
|
Toast.show({
|
||||||
|
type: 'small',
|
||||||
|
text1: message
|
||||||
|
})
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -213,27 +221,43 @@ export default function EditProfile() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
headerLeft: () => (
|
// headerLeft: () => (
|
||||||
<ButtonBackHeader
|
// <ButtonBackHeader
|
||||||
onPress={() => {
|
// onPress={() => {
|
||||||
router.back();
|
// router.back();
|
||||||
}}
|
// }}
|
||||||
/>
|
// />
|
||||||
),
|
// ),
|
||||||
headerTitle: "Edit Profile",
|
headerTitle: "Edit Profile",
|
||||||
headerTitleAlign: "center",
|
headerTitleAlign: "center",
|
||||||
headerRight: () => (
|
header: () => (
|
||||||
<ButtonSaveHeader
|
<AppHeader
|
||||||
disable={disableBtn || loading ? true : false}
|
title="Edit Profile"
|
||||||
category="update"
|
showBack={true}
|
||||||
onPress={() => {
|
onPressLeft={() => router.back()}
|
||||||
handleEdit()
|
right={
|
||||||
}}
|
<ButtonSaveHeader
|
||||||
|
disable={disableBtn || loading ? true : false}
|
||||||
|
category="update"
|
||||||
|
onPress={() => {
|
||||||
|
handleEdit()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
),
|
)
|
||||||
|
// headerRight: () => (
|
||||||
|
// <ButtonSaveHeader
|
||||||
|
// disable={disableBtn || loading ? true : false}
|
||||||
|
// category="update"
|
||||||
|
// onPress={() => {
|
||||||
|
// handleEdit()
|
||||||
|
// }}
|
||||||
|
// />
|
||||||
|
// ),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
@@ -243,7 +267,7 @@ export default function EditProfile() {
|
|||||||
>
|
>
|
||||||
<ScrollView showsVerticalScrollIndicator={false}>
|
<ScrollView showsVerticalScrollIndicator={false}>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<View style={{ justifyContent: "center", alignItems: "center" }}>
|
<View style={[Styles.contentItemCenter]}>
|
||||||
{
|
{
|
||||||
selectedImage != undefined ? (
|
selectedImage != undefined ? (
|
||||||
<Pressable onPress={pickImageAsync}>
|
<Pressable onPress={pickImageAsync}>
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import { ButtonFiturMenu } from "@/components/buttonFiturMenu";
|
import { ButtonFiturMenu } from "@/components/buttonFiturMenu";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { AntDesign, Entypo, Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { AntDesign, Entypo, Feather, Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import { SafeAreaView, View } from "react-native";
|
import { SafeAreaView, View } from "react-native";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function Feature() {
|
export default function Feature() {
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
headerTitle: 'Fitur',
|
headerTitle: 'Fitur',
|
||||||
@@ -21,33 +23,25 @@ export default function Feature() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<View style={[Styles.rowSpaceBetween, Styles.mb15]}>
|
<View style={{ flexDirection: 'row', flexWrap: 'wrap', rowGap: 20 }}>
|
||||||
<ButtonFiturMenu icon={<MaterialIcons name="group" size={35} color="black" />} text="Divisi" onPress={() => { router.push('/division?active=true') }} />
|
<ButtonFiturMenu icon={<Feather name="users" size={30} color={colors.icon} />} text="Divisi" onPress={() => { router.push('/division?active=true') }} />
|
||||||
<ButtonFiturMenu icon={<AntDesign name="areachart" size={35} color="black" />} text="Kegiatan" onPress={() => { router.push('/project?status=0') }} />
|
<ButtonFiturMenu icon={<Feather name="bar-chart" size={30} color={colors.icon} />} text="Kegiatan" onPress={() => { router.push('/project?status=0') }} />
|
||||||
<ButtonFiturMenu icon={<MaterialIcons name="campaign" size={35} color="black" />} text="Pengumuman" onPress={() => { router.push('/announcement') }} />
|
<ButtonFiturMenu icon={<Ionicons name="megaphone-outline" size={30} color={colors.icon} />} text="Pengumuman" onPress={() => { router.push('/announcement') }} />
|
||||||
<ButtonFiturMenu icon={<Ionicons name="chatbubbles-sharp" size={35} color="black" />} text="Diskusi" onPress={() => { router.push('/discussion?active=true') }} />
|
<ButtonFiturMenu icon={<Ionicons name="chatbubbles-outline" size={30} color={colors.icon} />} text="Diskusi" onPress={() => { router.push('/discussion?active=true') }} />
|
||||||
</View>
|
<ButtonFiturMenu icon={<Feather name="calendar" size={30} color={colors.icon} />} text="Kalender" onPress={() => { router.push('/village-calendar') }} />
|
||||||
<View style={[Styles.rowSpaceBetween, Styles.mb15, (entityUser.role == 'cosupadmin' ? Styles.w70 : entityUser.role == 'supadmin' || entityUser.role == 'developer' ? Styles.w100 : Styles.w40)]}>
|
<ButtonFiturMenu icon={<MaterialCommunityIcons name="account-group-outline" size={30} color={colors.icon} />} text="Anggota" onPress={() => { router.push('/member') }} />
|
||||||
<ButtonFiturMenu icon={<MaterialIcons name="groups" size={35} color="black" />} text="Anggota" onPress={() => { router.push('/member') }} />
|
<ButtonFiturMenu icon={<MaterialCommunityIcons name="account-tie-outline" size={30} color={colors.icon} />} text="Jabatan" onPress={() => { router.push('/position') }} />
|
||||||
<ButtonFiturMenu icon={<MaterialCommunityIcons name="account-tie" size={35} color="black" />} text="Jabatan" onPress={() => { router.push('/position') }} />
|
|
||||||
{
|
{
|
||||||
entityUser.role == "cosupadmin" && <ButtonFiturMenu icon={<Entypo name="image-inverted" size={35} color="black" />} text="Banner" onPress={() => { router.push('/banner') }} />
|
entityUser.role == "cosupadmin" && <ButtonFiturMenu icon={<Ionicons name="images-outline" size={30} color={colors.icon} />} text="Banner" onPress={() => { router.push('/banner') }} />
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
||||||
<>
|
<>
|
||||||
<ButtonFiturMenu icon={<AntDesign name="tags" size={35} color="black" />} text="Lembaga Desa" onPress={() => { router.push('/group') }} />
|
<ButtonFiturMenu icon={<Ionicons name="bookmarks-outline" size={30} color={colors.icon} />} text="Lembaga Desa" onPress={() => { router.push('/group') }} />
|
||||||
{/* <ButtonFiturMenu icon={<Ionicons name="color-palette-sharp" size={35} color="black" />} text="Tema" onPress={() => { }} /> */}
|
<ButtonFiturMenu icon={<Ionicons name="images-outline" size={30} color={colors.icon} />} text="Banner" onPress={() => { router.push('/banner') }} />
|
||||||
<ButtonFiturMenu icon={<Entypo name="image-inverted" size={35} color="black" />} text="Banner" onPress={() => { router.push('/banner') }} />
|
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
{/* {
|
|
||||||
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
|
||||||
<View style={[Styles.rowSpaceBetween, Styles.mb15]}>
|
|
||||||
<ButtonFiturMenu icon={<Entypo name="image-inverted" size={35} color="black" />} text="Banner" onPress={() => { router.push('/banner') }} />
|
|
||||||
</View>
|
|
||||||
} */}
|
|
||||||
</View>
|
</View>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi";
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
import BorderBottomItem from "@/components/borderBottomItem";
|
||||||
import { ButtonForm } from "@/components/buttonForm";
|
import { ButtonForm } from "@/components/buttonForm";
|
||||||
import ButtonTab from "@/components/buttonTab";
|
import ButtonTab from "@/components/buttonTab";
|
||||||
@@ -8,13 +9,17 @@ import InputSearch from "@/components/inputSearch";
|
|||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
import WrapTab from "@/components/wrapTab";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiDeleteGroup, apiEditGroup, apiGetGroup } from "@/lib/api";
|
import { apiDeleteGroup, apiEditGroup, apiGetGroup } from "@/lib/api";
|
||||||
import { setUpdateGroup } from "@/lib/groupSlice";
|
import { setUpdateGroup } from "@/lib/groupSlice";
|
||||||
|
import { GUIDE_GROUP } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { AntDesign, Feather, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { useEffect, useState } from "react";
|
import { AntDesign, Feather, Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { RefreshControl, View, VirtualizedList } from "react-native";
|
import { RefreshControl, View, VirtualizedList } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
@@ -27,18 +32,19 @@ type Props = {
|
|||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const [isModal, setModal] = useState(false)
|
const [isModal, setModal] = useState(false)
|
||||||
const [isVisibleEdit, setVisibleEdit] = useState(false)
|
const [isVisibleEdit, setVisibleEdit] = useState(false)
|
||||||
const [data, setData] = useState<Props[]>([])
|
|
||||||
const [search, setSearch] = useState('')
|
const [search, setSearch] = useState('')
|
||||||
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||||
const [loading, setLoading] = useState(true)
|
|
||||||
const [status, setStatus] = useState<'true' | 'false'>('true')
|
const [status, setStatus] = useState<'true' | 'false'>('true')
|
||||||
const [loadingSubmit, setLoadingSubmit] = useState(false)
|
const [loadingSubmit, setLoadingSubmit] = useState(false)
|
||||||
const [idChoose, setIdChoose] = useState('')
|
const [idChoose, setIdChoose] = useState('')
|
||||||
const [activeChoose, setActiveChoose] = useState(true)
|
const [activeChoose, setActiveChoose] = useState(true)
|
||||||
const [titleChoose, setTitleChoose] = useState('')
|
const [titleChoose, setTitleChoose] = useState('')
|
||||||
|
const queryClient = useQueryClient()
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('group')
|
||||||
|
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.groupUpdate)
|
const update = useSelector((state: any) => state.groupUpdate)
|
||||||
@@ -46,12 +52,38 @@ export default function Index() {
|
|||||||
title: false,
|
title: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TanStack Query for Groups
|
||||||
|
const {
|
||||||
|
data: queryData,
|
||||||
|
isLoading,
|
||||||
|
refetch
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ['groups', { status, search }],
|
||||||
|
queryFn: async () => {
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
const response = await apiGetGroup({
|
||||||
|
user: hasil,
|
||||||
|
active: status,
|
||||||
|
search: search
|
||||||
|
})
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
enabled: !!token?.current,
|
||||||
|
staleTime: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = useMemo(() => queryData?.data || [], [queryData])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refetch()
|
||||||
|
}, [update, refetch])
|
||||||
|
|
||||||
async function handleEdit() {
|
async function handleEdit() {
|
||||||
try {
|
try {
|
||||||
setLoadingSubmit(true)
|
setLoadingSubmit(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiEditGroup({ user: hasil, name: titleChoose }, idChoose)
|
const response = await apiEditGroup({ user: hasil, name: titleChoose }, idChoose)
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['groups'] })
|
||||||
dispatch(setUpdateGroup(!update))
|
dispatch(setUpdateGroup(!update))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
@@ -68,6 +100,7 @@ export default function Index() {
|
|||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiDeleteGroup({ user: hasil, isActive: activeChoose }, idChoose)
|
const response = await apiDeleteGroup({ user: hasil, isActive: activeChoose }, idChoose)
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['groups'] })
|
||||||
dispatch(setUpdateGroup(!update))
|
dispatch(setUpdateGroup(!update))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
@@ -77,32 +110,9 @@ export default function Index() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleLoad(loading: boolean) {
|
|
||||||
try {
|
|
||||||
setLoading(loading)
|
|
||||||
const hasil = await decryptToken(String(token?.current))
|
|
||||||
const response = await apiGetGroup({ user: hasil, active: status, search: search })
|
|
||||||
setData(response.data)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(false)
|
|
||||||
}, [update])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(true)
|
|
||||||
}, [status, search])
|
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleLoad(false)
|
await queryClient.invalidateQueries({ queryKey: ['groups'] })
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,30 +136,33 @@ export default function Index() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const arrSkeleton = [0, 1, 2, 3, 4]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
|
<GuideOverlay visible={guideVisible} steps={GUIDE_GROUP} onDismiss={dismissGuide} />
|
||||||
<View style={[Styles.mb10]}>
|
<View style={[Styles.mb10]}>
|
||||||
<View style={[Styles.wrapBtnTab]}>
|
<WrapTab>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="true"
|
value="true"
|
||||||
onPress={() => { setStatus("true") }}
|
onPress={() => { setStatus("true") }}
|
||||||
label="Aktif"
|
label="Aktif"
|
||||||
icon={<Feather name="check-circle" color={status == "true" ? 'white' : 'black'} size={20} />}
|
icon={<Feather name="check-circle" color={status == "true" ? 'white' : colors.dimmed} size={20} />}
|
||||||
n={2} />
|
n={2} />
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="false"
|
value="false"
|
||||||
onPress={() => { setStatus("false") }}
|
onPress={() => { setStatus("false") }}
|
||||||
label="Tidak Aktif"
|
label="Tidak Aktif"
|
||||||
icon={<AntDesign name="closecircleo" color={status == "false" ? 'white' : 'black'} size={20} />}
|
icon={<AntDesign name="closecircleo" color={status == "false" ? 'white' : colors.dimmed} size={20} />}
|
||||||
n={2} />
|
n={2} />
|
||||||
</View>
|
</WrapTab>
|
||||||
<InputSearch onChange={setSearch} />
|
<InputSearch onChange={setSearch} />
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ flex: 2 }, Styles.mt05]}>
|
<View style={[{ flex: 2 }, Styles.mt10]}>
|
||||||
{
|
{
|
||||||
loading ?
|
isLoading ?
|
||||||
arrSkeleton.map((item, index) => {
|
arrSkeleton.map((item, index) => {
|
||||||
return (
|
return (
|
||||||
<SkeletonTwoItem key={index} />
|
<SkeletonTwoItem key={index} />
|
||||||
@@ -173,8 +186,8 @@ export default function Index() {
|
|||||||
}}
|
}}
|
||||||
borderType="all"
|
borderType="all"
|
||||||
icon={
|
icon={
|
||||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
<View style={[Styles.iconContent]}>
|
||||||
<MaterialCommunityIcons name="office-building-outline" size={25} color={'#384288'} />
|
<Ionicons name="bookmark-outline" size={25} color={'black'} />
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
title={item.name}
|
title={item.name}
|
||||||
@@ -187,30 +200,29 @@ export default function Index() {
|
|||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
|
<Text style={[Styles.textDefault, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada data</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={() => setModal(false)} title={titleChoose}>
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={() => setModal(false)} title={titleChoose}>
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="toggle-switch-off-outline" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="toggle-switch-off-outline" color={colors.text} size={25} />}
|
||||||
title={activeChoose ? "Non Aktifkan" : "Aktifkan"}
|
title={activeChoose ? "Non Aktifkan" : "Aktifkan"}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
AlertKonfirmasi({
|
setTimeout(() => {
|
||||||
title: 'Konfirmasi',
|
setShowDeleteModal(true)
|
||||||
desc: activeChoose ? 'Apakah anda yakin ingin menonaktifkan data?' : 'Apakah anda yakin ingin mengaktifkan data?',
|
}, 600)
|
||||||
onPress: () => { handleDelete() }
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="pencil-outline" color={colors.text} size={25} />}
|
||||||
title="Edit"
|
title="Edit"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
@@ -232,6 +244,7 @@ export default function Index() {
|
|||||||
label="Lembaga Desa"
|
label="Lembaga Desa"
|
||||||
value={titleChoose}
|
value={titleChoose}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
|
bg={"transparent"}
|
||||||
errorText="Lembaga Desa tidak boleh kosong & minimal 3 karakter"
|
errorText="Lembaga Desa tidak boleh kosong & minimal 3 karakter"
|
||||||
onChange={(val) => { validationForm(val, 'title') }} />
|
onChange={(val) => { validationForm(val, 'title') }} />
|
||||||
</View>
|
</View>
|
||||||
@@ -240,6 +253,19 @@ export default function Index() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message={activeChoose ? 'Apakah anda yakin ingin menonaktifkan data?' : 'Apakah anda yakin ingin mengaktifkan data?'}
|
||||||
|
onConfirm={() => {
|
||||||
|
setShowDeleteModal(false)
|
||||||
|
handleDelete()
|
||||||
|
}}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText={activeChoose ? "Nonaktifkan" : "Aktifkan"}
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
</View >
|
</View >
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import CaraouselHome from "@/components/home/carouselHome";
|
import CaraouselHome2 from "@/components/home/carouselHome2";
|
||||||
import ChartDokumenHome from "@/components/home/chartDokumenHome";
|
import ChartDokumenHome from "@/components/home/chartDokumenHome";
|
||||||
import ChartProgresHome from "@/components/home/chartProgresHome";
|
import ChartProgresHome from "@/components/home/chartProgresHome";
|
||||||
import DisccussionHome from "@/components/home/discussionHome";
|
import DisccussionHome from "@/components/home/discussionHome";
|
||||||
import DivisionHome from "@/components/home/divisionHome";
|
import DivisionHome from "@/components/home/divisionHome";
|
||||||
import EventHome from "@/components/home/eventHome";
|
import EventHome from "@/components/home/eventHome";
|
||||||
import FiturHome from "@/components/home/fiturHome";
|
|
||||||
import { HeaderRightHome } from "@/components/home/headerRightHome";
|
import { HeaderRightHome } from "@/components/home/headerRightHome";
|
||||||
import ProjectHome from "@/components/home/projectHome";
|
import ProjectHome from "@/components/home/projectHome";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -12,9 +11,12 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiGetProfile } from "@/lib/api";
|
import { apiGetProfile } from "@/lib/api";
|
||||||
import { setEntities } from "@/lib/entitiesSlice";
|
import { setEntities } from "@/lib/entitiesSlice";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { LinearGradient } from "expo-linear-gradient";
|
||||||
import { Stack } from "expo-router";
|
import { Stack } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Platform, RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
|
import { Alert, Dimensions, Platform, RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
@@ -22,38 +24,77 @@ import { useDispatch, useSelector } from "react-redux";
|
|||||||
export default function Home() {
|
export default function Home() {
|
||||||
const entities = useSelector((state: any) => state.entities)
|
const entities = useSelector((state: any) => state.entities)
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
const { token, decryptToken, signOut } = useAuthSession()
|
const { token, decryptToken, signOut } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const insets = useSafeAreaInsets()
|
const insets = useSafeAreaInsets()
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
const { data: profile, isError } = useQuery({
|
||||||
handleUserLogin()
|
queryKey: ['profile'],
|
||||||
}, [dispatch]);
|
queryFn: async () => {
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
const data = await apiGetProfile({ id: hasil })
|
||||||
|
return data.data
|
||||||
|
},
|
||||||
|
enabled: !!token?.current,
|
||||||
|
staleTime: 0, // Ensure it refetches every time the component mounts
|
||||||
|
})
|
||||||
|
|
||||||
async function handleUserLogin() {
|
// Sync to Redux for global usage
|
||||||
const hasil = await decryptToken(String(token?.current))
|
useEffect(() => {
|
||||||
apiGetProfile({ id: hasil })
|
if (profile) {
|
||||||
.then((data) => dispatch(setEntities(data.data)))
|
dispatch(setEntities(profile))
|
||||||
.catch((error) => {
|
}
|
||||||
signOut()
|
}, [profile, dispatch])
|
||||||
});
|
|
||||||
}
|
// Auto Sign Out if profile fetch fails (e.g. invalid/expired token)
|
||||||
|
useEffect(() => {
|
||||||
|
if (isError) {
|
||||||
|
signOut()
|
||||||
|
}
|
||||||
|
}, [isError, signOut])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (profile && profile.isActive === false) {
|
||||||
|
Alert.alert(
|
||||||
|
'Akun Dinonaktifkan',
|
||||||
|
'Akun kamu telah dinonaktifkan. Silahkan hubungi admin untuk informasi lebih lanjut.',
|
||||||
|
[{ text: 'OK', onPress: signOut }]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, [profile, signOut])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (profile && profile.villageIsActive === false) {
|
||||||
|
Alert.alert(
|
||||||
|
'Desa Dinonaktifkan',
|
||||||
|
'Desa kamu saat ini telah dinonaktifkan. Silahkan hubungi pengelola sistem untuk informasi lebih lanjut.',
|
||||||
|
[{ text: 'OK', onPress: signOut }]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, [profile, signOut])
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleUserLogin()
|
// Invalidate all queries related to the home screen
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await queryClient.invalidateQueries({ queryKey: ['profile'] })
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['banners'] })
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['homeData'] })
|
||||||
|
|
||||||
|
// Artificial delay to show refresh indicator if sync is too fast
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
title: 'Home',
|
title: 'Home',
|
||||||
headerTitle: entities.village,
|
headerTitle: entities.village,
|
||||||
header: () => (
|
header: () => (
|
||||||
<View style={[Styles.rowItemsCenter, Styles.ph20, Platform.OS === 'ios' ? Styles.pb07 : Styles.pb13, { backgroundColor: '#19345E', paddingTop: Platform.OS === 'ios' ? insets.top : 10 }]}>
|
<View style={[Styles.rowItemsCenter, Styles.ph20, Platform.OS === 'ios' ? Styles.pb07 : Styles.pb13, { backgroundColor: colors.header, paddingTop: Platform.OS === 'ios' ? insets.top : 10 }]}>
|
||||||
<Text style={Styles.textHeaderHome}>{entities.village}</Text>
|
<Text style={Styles.textHeaderHome}>{entities.village}</Text>
|
||||||
<HeaderRightHome />
|
<HeaderRightHome />
|
||||||
</View>
|
</View>
|
||||||
@@ -65,19 +106,36 @@ export default function Home() {
|
|||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
>
|
>
|
||||||
<CaraouselHome refreshing={refreshing}/>
|
<LinearGradient
|
||||||
<View style={[Styles.ph15, Styles.mb100]}>
|
colors={[colors.header, colors.header, colors.header, colors.header, colors.homeGradient]}
|
||||||
<FiturHome />
|
style={[
|
||||||
<ProjectHome refreshing={refreshing}/>
|
Styles.posAbsolute,
|
||||||
<DivisionHome refreshing={refreshing}/>
|
Styles.zIndexMinus1,
|
||||||
<ChartProgresHome refreshing={refreshing}/>
|
{
|
||||||
<ChartDokumenHome refreshing={refreshing}/>
|
width: Dimensions.get('window').width * 1.5,
|
||||||
<EventHome refreshing={refreshing}/>
|
height: Dimensions.get('window').width * 1.5,
|
||||||
<DisccussionHome refreshing={refreshing}/>
|
borderRadius: Dimensions.get('window').width * 0.5,
|
||||||
|
top: -Dimensions.get('window').width * 1, // Positioned to show the bottom part of the circle as an arc
|
||||||
|
left: -Dimensions.get('window').width * 0.25,
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
{/* <CaraouselHome refreshing={refreshing} /> */}
|
||||||
|
<View style={[Styles.ph15]}>
|
||||||
|
<CaraouselHome2 refreshing={refreshing} />
|
||||||
|
{/* <FiturHome /> */}
|
||||||
|
<ProjectHome refreshing={refreshing} />
|
||||||
|
<DivisionHome refreshing={refreshing} />
|
||||||
|
<ChartProgresHome refreshing={refreshing} />
|
||||||
|
<ChartDokumenHome refreshing={refreshing} />
|
||||||
|
<EventHome refreshing={refreshing} />
|
||||||
|
<DisccussionHome refreshing={refreshing} />
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ImageUser from "@/components/imageNew";
|
import ImageUser from "@/components/imageNew";
|
||||||
import ItemDetailMember from "@/components/itemDetailMember";
|
|
||||||
import LabelStatus from "@/components/labelStatus";
|
import LabelStatus from "@/components/labelStatus";
|
||||||
import HeaderRightMemberDetail from "@/components/member/headerMemberDetail";
|
import HeaderRightMemberDetail from "@/components/member/headerMemberDetail";
|
||||||
import Skeleton from "@/components/skeleton";
|
import Skeleton from "@/components/skeleton";
|
||||||
@@ -10,6 +9,9 @@ import { ConstEnv } from "@/constants/ConstEnv";
|
|||||||
import { valueRoleUser } from "@/constants/RoleUser";
|
import { valueRoleUser } from "@/constants/RoleUser";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetProfile } from "@/lib/api";
|
import { apiGetProfile } from "@/lib/api";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { AntDesign, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
||||||
|
import { LinearGradient } from "expo-linear-gradient";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Pressable, RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
|
import { Pressable, RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -28,11 +30,13 @@ type Props = {
|
|||||||
group: string,
|
group: string,
|
||||||
img: string,
|
img: string,
|
||||||
isActive: boolean,
|
isActive: boolean,
|
||||||
|
isApprover: boolean,
|
||||||
role: string
|
role: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function MemberDetail() {
|
export default function MemberDetail() {
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
|
const { colors } = useTheme();
|
||||||
const [data, setData] = useState<Props>()
|
const [data, setData] = useState<Props>()
|
||||||
const [errorImg, setErrorImg] = useState(false)
|
const [errorImg, setErrorImg] = useState(false)
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
@@ -52,9 +56,11 @@ export default function MemberDetail() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message })
|
Toast.show({ type: 'small', text1: response.message })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Gagal mengambil data' })
|
const message = error?.response?.data?.message || "Gagal mengambil data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -74,79 +80,101 @@ export default function MemberDetail() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
|
||||||
headerTitle: 'Anggota',
|
headerTitle: 'Anggota',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
// headerRight: () => (entityUser.role != "user") && isEdit ? <HeaderRightMemberDetail active={data?.isActive} id={id} /> : <></>,
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader title="Anggota"
|
<AppHeader title="Anggota"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={
|
right={
|
||||||
(entityUser.role != "user") && isEdit ? <HeaderRightMemberDetail active={data?.isActive} id={id} /> : <></>
|
(entityUser.role != "user") && isEdit ? <HeaderRightMemberDetail active={data?.isActive} id={id} isApprover={data?.isApprover ?? false} /> : <></>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<View style={[Styles.wrapHeadViewMember]}>
|
<LinearGradient
|
||||||
{
|
colors={[colors.header, colors.homeGradient]}
|
||||||
loading ?
|
style={[Styles.wrapHeadViewMember]}
|
||||||
<>
|
>
|
||||||
<Skeleton width={100} height={100} borderRadius={100} />
|
{loading ? (
|
||||||
<Skeleton width={200} height={10} borderRadius={5} />
|
<>
|
||||||
<Skeleton width={150} height={10} borderRadius={5} />
|
<Skeleton width={100} height={100} borderRadius={100} />
|
||||||
</>
|
<Skeleton width={200} height={10} borderRadius={5} />
|
||||||
:
|
<Skeleton width={150} height={10} borderRadius={5} />
|
||||||
<>
|
</>
|
||||||
<Pressable onPress={() => setPreview(true)}>
|
) : (
|
||||||
|
<>
|
||||||
|
<Pressable onPress={() => setPreview(true)}>
|
||||||
|
<View style={[Styles.memberAvatarRing]}>
|
||||||
<ImageUser src={`${ConstEnv.url_storage}/files/${data?.img}`} size="lg" onError={setErrorImg} />
|
<ImageUser src={`${ConstEnv.url_storage}/files/${data?.img}`} size="lg" onError={setErrorImg} />
|
||||||
</Pressable>
|
</View>
|
||||||
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10, { textAlign: 'center' }]}>{data?.name}</Text>
|
</Pressable>
|
||||||
<Text style={[Styles.textMediumNormal, Styles.cWhite]}>{data?.role}</Text>
|
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10, Styles.textCenter]}>{data?.name}</Text>
|
||||||
</>
|
<Text style={[Styles.textMediumNormal, Styles.cWhiteDimmed]}>{data?.role}</Text>
|
||||||
|
<View style={[Styles.memberBadgeRow]}>
|
||||||
|
{data?.isApprover && (
|
||||||
|
<View style={[Styles.memberBadgeApprover]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, Styles.cWhite]}>APPROVER</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<View style={[Styles.memberBadgePill, { backgroundColor: data?.isActive ? colors.success : colors.error }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, Styles.cWhite]}>{data?.isActive ? 'AKTIF' : 'TIDAK AKTIF'}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</LinearGradient>
|
||||||
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<View style={[Styles.rowSpaceBetween]}>
|
<Text style={[Styles.textDefaultSemiBold, Styles.mb08, { color: colors.dimmed }]}>Informasi</Text>
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>Informasi</Text>
|
<View>
|
||||||
<LabelStatus
|
{loading ? (
|
||||||
size="small"
|
arrSkeleton.map((_, index) => (
|
||||||
category={data?.isActive ? 'success' : 'error'}
|
<View key={index} style={[Styles.pv14, { borderBottomWidth: index < arrSkeleton.length - 1 ? 1 : 0, borderBottomColor: `${colors.dimmed}30` }]}>
|
||||||
text={data?.isActive ? 'AKTIF' : 'TIDAK AKTIF'}
|
<Skeleton width={80} height={8} borderRadius={4} />
|
||||||
/>
|
<View style={[Styles.mt05]}>
|
||||||
|
<Skeleton width={60} widthType="percent" height={10} borderRadius={4} />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
[
|
||||||
|
{ icon: <MaterialCommunityIcons name="card-account-details" size={20} color={colors.icon} />, label: 'NIK', value: data?.nik },
|
||||||
|
{ icon: <MaterialCommunityIcons name="office-building-outline" size={20} color={colors.icon} />, label: 'Lembaga Desa', value: data?.group },
|
||||||
|
{ icon: <MaterialCommunityIcons name="account-tie" size={20} color={colors.icon} />, label: 'Jabatan', value: data?.position },
|
||||||
|
{ icon: <MaterialIcons name="phone" size={20} color={colors.icon} />, label: 'No Telepon', value: `+62${data?.phone}` },
|
||||||
|
{ icon: <MaterialIcons name="email" size={20} color={colors.icon} />, label: 'Email', value: data?.email },
|
||||||
|
{ icon: <MaterialCommunityIcons name="gender-male-female" size={20} color={colors.icon} />, label: 'Jenis Kelamin', value: data?.gender == "F" ? "Perempuan" : "Laki-Laki" },
|
||||||
|
].map((item, index, arr) => (
|
||||||
|
<View
|
||||||
|
key={index}
|
||||||
|
style={[Styles.memberInfoRow, { borderBottomWidth: index < arr.length - 1 ? 1 : 0, borderBottomColor: `${colors.dimmed}30` }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.memberInfoIcon]}>
|
||||||
|
{item.icon}
|
||||||
|
</View>
|
||||||
|
<View style={[Styles.memberInfoContent]}>
|
||||||
|
<Text style={[Styles.textInformation, { color: colors.dimmed }]}>{item.label}</Text>
|
||||||
|
<Text style={[Styles.textDefault, Styles.mt02, { color: colors.text }]} numberOfLines={1}>{item.value ?? '-'}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
))
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
{
|
|
||||||
loading ?
|
|
||||||
arrSkeleton.map((item, index) => {
|
|
||||||
return (
|
|
||||||
<Skeleton key={index} width={100} widthType="percent" height={25} borderRadius={5} />
|
|
||||||
)
|
|
||||||
})
|
|
||||||
:
|
|
||||||
<>
|
|
||||||
<ItemDetailMember category="nik" value={data?.nik} />
|
|
||||||
<ItemDetailMember category="group" value={data?.group} />
|
|
||||||
<ItemDetailMember category="position" value={data?.position} />
|
|
||||||
<ItemDetailMember category="phone" value={`+62${data?.phone}`} />
|
|
||||||
<ItemDetailMember category="email" value={data?.email} />
|
|
||||||
<ItemDetailMember category="gender" value={data?.gender == "F" ? "Perempuan" : "Laki-Laki"} />
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import ModalSelect from "@/components/modalSelect";
|
import ModalSelect from "@/components/modalSelect";
|
||||||
import SelectForm from "@/components/selectForm";
|
import SelectForm from "@/components/selectForm";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -10,6 +11,7 @@ import { apiCreateUser } from "@/lib/api";
|
|||||||
import { validateName } from "@/lib/fun_validateName";
|
import { validateName } from "@/lib/fun_validateName";
|
||||||
import { setUpdateMember } from "@/lib/memberSlice";
|
import { setUpdateMember } from "@/lib/memberSlice";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
import * as ImagePicker from "expo-image-picker";
|
import * as ImagePicker from "expo-image-picker";
|
||||||
@@ -32,6 +34,7 @@ export default function CreateMember() {
|
|||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.memberUpdate)
|
const update = useSelector((state: any) => state.memberUpdate)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const [valSelect, setValSelect] = useState<"group" | "position" | "role" | "gender">("group");
|
const [valSelect, setValSelect] = useState<"group" | "position" | "role" | "gender">("group");
|
||||||
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" });
|
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" });
|
||||||
const [choosePosition, setChoosePosition] = useState({ val: "", label: "" });
|
const [choosePosition, setChoosePosition] = useState({ val: "", label: "" });
|
||||||
@@ -182,9 +185,11 @@ export default function CreateMember() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -206,25 +211,11 @@ export default function CreateMember() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
|
||||||
// <ButtonBackHeader
|
|
||||||
// onPress={() => {
|
|
||||||
// router.back();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
headerTitle: "Tambah Anggota",
|
headerTitle: "Tambah Anggota",
|
||||||
headerTitleAlign: "center",
|
headerTitleAlign: "center",
|
||||||
// headerRight: () => (
|
|
||||||
// <ButtonSaveHeader
|
|
||||||
// disable={disableBtn || loading}
|
|
||||||
// category="create"
|
|
||||||
// onPress={() => { handleCreate() }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader title="Anggota"
|
<AppHeader title="Anggota"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
@@ -240,14 +231,15 @@ export default function CreateMember() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{loading && <LoadingCenter />}
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
||||||
keyboardVerticalOffset={headerHeight}
|
keyboardVerticalOffset={headerHeight}
|
||||||
>
|
>
|
||||||
<ScrollView showsVerticalScrollIndicator={false}>
|
<ScrollView showsVerticalScrollIndicator={false}>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<View style={{ justifyContent: "center", alignItems: "center" }}>
|
<View style={[Styles.contentItemCenter]}>
|
||||||
{selectedImage != undefined ? (
|
{selectedImage != undefined ? (
|
||||||
<Pressable onPress={pickImageAsync}>
|
<Pressable onPress={pickImageAsync}>
|
||||||
<Image src={selectedImage} style={[Styles.userProfileBig]} />
|
<Image src={selectedImage} style={[Styles.userProfileBig]} />
|
||||||
@@ -271,6 +263,7 @@ export default function CreateMember() {
|
|||||||
placeholder="Pilih Lembaga Desa"
|
placeholder="Pilih Lembaga Desa"
|
||||||
value={chooseGroup.label}
|
value={chooseGroup.label}
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setValChoose(chooseGroup.val);
|
setValChoose(chooseGroup.val);
|
||||||
setValSelect("group");
|
setValSelect("group");
|
||||||
@@ -285,6 +278,7 @@ export default function CreateMember() {
|
|||||||
placeholder="Pilih Jabatan"
|
placeholder="Pilih Jabatan"
|
||||||
value={choosePosition.label}
|
value={choosePosition.label}
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setValChoose(choosePosition.val);
|
setValChoose(choosePosition.val);
|
||||||
setValSelect("position");
|
setValSelect("position");
|
||||||
@@ -298,6 +292,7 @@ export default function CreateMember() {
|
|||||||
placeholder="Pilih Role"
|
placeholder="Pilih Role"
|
||||||
value={chooseRole.label}
|
value={chooseRole.label}
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setValChoose(chooseRole.val);
|
setValChoose(chooseRole.val);
|
||||||
setValSelect("role");
|
setValSelect("role");
|
||||||
@@ -311,6 +306,7 @@ export default function CreateMember() {
|
|||||||
type="numeric"
|
type="numeric"
|
||||||
placeholder="NIK"
|
placeholder="NIK"
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
error={error.nik}
|
error={error.nik}
|
||||||
errorText="NIK Harus 16 Karakter"
|
errorText="NIK Harus 16 Karakter"
|
||||||
onChange={val => {
|
onChange={val => {
|
||||||
@@ -322,6 +318,7 @@ export default function CreateMember() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Nama"
|
placeholder="Nama"
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
error={error.name}
|
error={error.name}
|
||||||
errorText="Nama harus 3–50 karakter (huruf, angka, spasi, dan simbol ringan (. , ' _ -))"
|
errorText="Nama harus 3–50 karakter (huruf, angka, spasi, dan simbol ringan (. , ' _ -))"
|
||||||
onChange={val => {
|
onChange={val => {
|
||||||
@@ -333,6 +330,7 @@ export default function CreateMember() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
error={error.email}
|
error={error.email}
|
||||||
errorText="Email tidak valid"
|
errorText="Email tidak valid"
|
||||||
onChange={val => {
|
onChange={val => {
|
||||||
@@ -344,7 +342,8 @@ export default function CreateMember() {
|
|||||||
type="numeric"
|
type="numeric"
|
||||||
placeholder="8XX-XXX-XXX"
|
placeholder="8XX-XXX-XXX"
|
||||||
required
|
required
|
||||||
itemLeft={<Text style={[Platform.OS === 'ios' && Styles.mt02]}>+62</Text>}
|
bg={colors.card}
|
||||||
|
itemLeft={<Text style={[Platform.OS === 'ios' && Styles.mt02, { color: colors.text }]}>+62</Text>}
|
||||||
error={error.phone}
|
error={error.phone}
|
||||||
errorText="Nomor Telepon tidak valid"
|
errorText="Nomor Telepon tidak valid"
|
||||||
onChange={val => {
|
onChange={val => {
|
||||||
@@ -356,6 +355,7 @@ export default function CreateMember() {
|
|||||||
placeholder="Pilih Jenis Kelamin"
|
placeholder="Pilih Jenis Kelamin"
|
||||||
value={chooseGender.label}
|
value={chooseGender.label}
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setValChoose(chooseGender.val);
|
setValChoose(chooseGender.val);
|
||||||
setValSelect("gender");
|
setValSelect("gender");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import ModalSelect from "@/components/modalSelect";
|
import ModalSelect from "@/components/modalSelect";
|
||||||
import SelectForm from "@/components/selectForm";
|
import SelectForm from "@/components/selectForm";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -10,6 +11,7 @@ import { apiEditUser, apiGetProfile } from "@/lib/api";
|
|||||||
import { validateName } from "@/lib/fun_validateName";
|
import { validateName } from "@/lib/fun_validateName";
|
||||||
import { setUpdateMember } from "@/lib/memberSlice";
|
import { setUpdateMember } from "@/lib/memberSlice";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
import * as ImagePicker from "expo-image-picker";
|
import * as ImagePicker from "expo-image-picker";
|
||||||
@@ -47,6 +49,7 @@ export default function EditMember() {
|
|||||||
const update = useSelector((state: any) => state.memberUpdate)
|
const update = useSelector((state: any) => state.memberUpdate)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
|
const { colors } = useTheme();
|
||||||
const [errorImg, setErrorImg] = useState(false)
|
const [errorImg, setErrorImg] = useState(false)
|
||||||
const [selectedImage, setSelectedImage] = useState<string | undefined | { uri: string }>(undefined);
|
const [selectedImage, setSelectedImage] = useState<string | undefined | { uri: string }>(undefined);
|
||||||
const [choosePosition, setChoosePosition] = useState({ val: "", label: "" });
|
const [choosePosition, setChoosePosition] = useState({ val: "", label: "" });
|
||||||
@@ -168,11 +171,9 @@ export default function EditMember() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkForm() {
|
function checkForm() {
|
||||||
if (Object.values(error).some((v) => v == true) || Object.values(data).some((v) => v == "")) {
|
const requiredFields: (keyof Props)[] = ["idPosition", "idUserRole", "nik", "name", "email", "phone", "gender"];
|
||||||
setDisableBtn(true)
|
const hasEmpty = requiredFields.some((key) => data[key] === "");
|
||||||
} else {
|
setDisableBtn(Object.values(error).some((v) => v === true) || hasEmpty);
|
||||||
setDisableBtn(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -208,9 +209,11 @@ export default function EditMember() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -236,27 +239,11 @@ export default function EditMember() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
|
||||||
// <ButtonBackHeader
|
|
||||||
// onPress={() => {
|
|
||||||
// router.back();
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
headerTitle: "Edit Anggota",
|
headerTitle: "Edit Anggota",
|
||||||
headerTitleAlign: "center",
|
headerTitleAlign: "center",
|
||||||
// headerRight: () => (
|
|
||||||
// <ButtonSaveHeader
|
|
||||||
// disable={disableBtn || loading}
|
|
||||||
// category="update"
|
|
||||||
// onPress={() => {
|
|
||||||
// handleEdit()
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
// ),
|
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Edit Anggota"
|
title="Edit Anggota"
|
||||||
@@ -275,15 +262,15 @@ export default function EditMember() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{loading && <LoadingCenter />}
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
||||||
keyboardVerticalOffset={headerHeight}
|
keyboardVerticalOffset={headerHeight}
|
||||||
>
|
>
|
||||||
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
|
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<View style={{ justifyContent: "center", alignItems: "center" }}>
|
<View style={[Styles.contentItemCenter]}>
|
||||||
{
|
{
|
||||||
errorImg ?
|
errorImg ?
|
||||||
<Pressable onPress={pickImageAsync}>
|
<Pressable onPress={pickImageAsync}>
|
||||||
@@ -325,6 +312,7 @@ export default function EditMember() {
|
|||||||
placeholder="Pilih Jabatan"
|
placeholder="Pilih Jabatan"
|
||||||
value={choosePosition.label}
|
value={choosePosition.label}
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setValChoose(choosePosition.val);
|
setValChoose(choosePosition.val);
|
||||||
setValSelect("position");
|
setValSelect("position");
|
||||||
@@ -338,6 +326,7 @@ export default function EditMember() {
|
|||||||
placeholder="Pilih Role"
|
placeholder="Pilih Role"
|
||||||
value={chooseRole.label}
|
value={chooseRole.label}
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setValChoose(chooseRole.val);
|
setValChoose(chooseRole.val);
|
||||||
setValSelect("role");
|
setValSelect("role");
|
||||||
@@ -352,6 +341,7 @@ export default function EditMember() {
|
|||||||
placeholder="NIK"
|
placeholder="NIK"
|
||||||
required
|
required
|
||||||
value={data?.nik}
|
value={data?.nik}
|
||||||
|
bg={colors.card}
|
||||||
error={error.nik}
|
error={error.nik}
|
||||||
errorText="NIK Harus 16 Karakter"
|
errorText="NIK Harus 16 Karakter"
|
||||||
onChange={val => {
|
onChange={val => {
|
||||||
@@ -364,6 +354,7 @@ export default function EditMember() {
|
|||||||
placeholder="Nama"
|
placeholder="Nama"
|
||||||
required
|
required
|
||||||
value={data?.name}
|
value={data?.name}
|
||||||
|
bg={colors.card}
|
||||||
error={error.name}
|
error={error.name}
|
||||||
errorText="Nama harus 3–50 karakter (huruf, angka, spasi, dan simbol ringan (. , ' _ -))"
|
errorText="Nama harus 3–50 karakter (huruf, angka, spasi, dan simbol ringan (. , ' _ -))"
|
||||||
onChange={val => {
|
onChange={val => {
|
||||||
@@ -376,6 +367,7 @@ export default function EditMember() {
|
|||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
required
|
required
|
||||||
value={data?.email}
|
value={data?.email}
|
||||||
|
bg={colors.card}
|
||||||
error={error.email}
|
error={error.email}
|
||||||
errorText="Email tidak valid"
|
errorText="Email tidak valid"
|
||||||
onChange={val => {
|
onChange={val => {
|
||||||
@@ -387,8 +379,9 @@ export default function EditMember() {
|
|||||||
type="numeric"
|
type="numeric"
|
||||||
placeholder="8XX-XXX-XXX"
|
placeholder="8XX-XXX-XXX"
|
||||||
required
|
required
|
||||||
itemLeft={<Text style={[Platform.OS === 'ios' && Styles.mt02]}>+62</Text>}
|
itemLeft={<Text style={[Platform.OS === 'ios' && Styles.mt02, { color: colors.text }]}>+62</Text>}
|
||||||
value={data?.phone}
|
value={data?.phone}
|
||||||
|
bg={colors.card}
|
||||||
error={error.phone}
|
error={error.phone}
|
||||||
errorText="Nomor Telepon tidak valid"
|
errorText="Nomor Telepon tidak valid"
|
||||||
onChange={val => {
|
onChange={val => {
|
||||||
@@ -400,6 +393,7 @@ export default function EditMember() {
|
|||||||
placeholder="Pilih Jenis Kelamin"
|
placeholder="Pilih Jenis Kelamin"
|
||||||
value={chooseGender.label}
|
value={chooseGender.label}
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setValChoose(chooseGender.val);
|
setValChoose(chooseGender.val);
|
||||||
setValSelect("gender");
|
setValSelect("gender");
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
import BorderBottomItem from "@/components/borderBottomItem";
|
||||||
import ButtonTab from "@/components/buttonTab";
|
import ButtonTab from "@/components/buttonTab";
|
||||||
import ImageUser from "@/components/imageNew";
|
import ImageUser from "@/components/imageNew";
|
||||||
@@ -5,13 +6,18 @@ import InputSearch from "@/components/inputSearch";
|
|||||||
import LabelStatus from "@/components/labelStatus";
|
import LabelStatus from "@/components/labelStatus";
|
||||||
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
|
import WrapTab from "@/components/wrapTab";
|
||||||
import { ConstEnv } from "@/constants/ConstEnv";
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetUser } from "@/lib/api";
|
import { apiGetUser } from "@/lib/api";
|
||||||
|
import { GUIDE_MEMBER } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign, Feather } from "@expo/vector-icons";
|
import { AntDesign, Feather } from "@expo/vector-icons";
|
||||||
|
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { router, useLocalSearchParams } from "expo-router";
|
import { router, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { RefreshControl, View, VirtualizedList } from "react-native";
|
import { RefreshControl, View, VirtualizedList } from "react-native";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
@@ -33,118 +39,129 @@ export default function Index() {
|
|||||||
const { active, group } = useLocalSearchParams<{ active?: string, group?: string }>()
|
const { active, group } = useLocalSearchParams<{ active?: string, group?: string }>()
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
|
const { colors } = useTheme();
|
||||||
const [search, setSearch] = useState('')
|
const [search, setSearch] = useState('')
|
||||||
const [nameGroup, setNameGroup] = useState('')
|
|
||||||
const [data, setData] = useState<Props[]>([])
|
|
||||||
const update = useSelector((state: any) => state.memberUpdate)
|
const update = useSelector((state: any) => state.memberUpdate)
|
||||||
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
const queryClient = useQueryClient()
|
||||||
const [loading, setLoading] = useState(true)
|
const [status, setStatus] = useState<'true' | 'false'>(active == 'false' ? 'false' : 'true')
|
||||||
const [status, setStatus] = useState<'true' | 'false'>('true')
|
|
||||||
const [page, setPage] = useState(1)
|
|
||||||
const [waiting, setWaiting] = useState(false)
|
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('member')
|
||||||
|
|
||||||
async function handleLoad(loading: boolean, thisPage: number) {
|
// TanStack Query for Members with Infinite Scroll
|
||||||
try {
|
const {
|
||||||
setWaiting(true)
|
data,
|
||||||
setLoading(loading)
|
fetchNextPage,
|
||||||
setPage(thisPage)
|
hasNextPage,
|
||||||
|
isFetchingNextPage,
|
||||||
|
isLoading,
|
||||||
|
refetch
|
||||||
|
} = useInfiniteQuery({
|
||||||
|
queryKey: ['members', { status, search, group }],
|
||||||
|
queryFn: async ({ pageParam = 1 }) => {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiGetUser({ user: hasil, active: status, search, group: String(group), page: thisPage })
|
const response = await apiGetUser({
|
||||||
if (thisPage == 1) {
|
user: hasil,
|
||||||
setData(response.data)
|
active: status,
|
||||||
} else if (thisPage > 1 && response.data.length > 0) {
|
search,
|
||||||
setData([...data, ...response.data])
|
group: String(group),
|
||||||
} else {
|
page: pageParam
|
||||||
return;
|
})
|
||||||
}
|
return response;
|
||||||
setNameGroup(response.filter.name)
|
},
|
||||||
} catch (error) {
|
initialPageParam: 1,
|
||||||
console.error(error)
|
getNextPageParam: (lastPage, allPages) => {
|
||||||
} finally {
|
return lastPage.data.length > 0 ? allPages.length + 1 : undefined;
|
||||||
setLoading(false)
|
},
|
||||||
setWaiting(false)
|
enabled: !!token?.current,
|
||||||
}
|
staleTime: 0,
|
||||||
}
|
})
|
||||||
|
|
||||||
const loadMoreData = () => {
|
// Flatten pages into a single data array
|
||||||
if (waiting) return
|
const flatData = useMemo(() => {
|
||||||
setTimeout(() => {
|
return data?.pages.flatMap(page => page.data) || [];
|
||||||
handleLoad(false, page + 1)
|
}, [data])
|
||||||
}, 1000);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Get nameGroup from the first available page
|
||||||
|
const nameGroup = useMemo(() => {
|
||||||
|
return data?.pages[0]?.filter?.name || "";
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
// Refetch when manual update state changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLoad(false, 1)
|
refetch()
|
||||||
}, [update])
|
}, [update, refetch])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(true, 1)
|
|
||||||
}, [group, search, status])
|
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleLoad(false, 1)
|
await queryClient.invalidateQueries({ queryKey: ['members'] })
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadMoreData = () => {
|
||||||
|
if (hasNextPage && !isFetchingNextPage) {
|
||||||
|
fetchNextPage()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const arrSkeleton = [0, 1, 2, 3, 4]
|
||||||
|
|
||||||
const getItem = (_data: unknown, index: number): Props => ({
|
const getItem = (_data: unknown, index: number): Props => ({
|
||||||
id: data[index].id,
|
id: flatData[index]?.id,
|
||||||
name: data[index].name,
|
name: flatData[index]?.name,
|
||||||
nik: data[index].nik,
|
nik: flatData[index]?.nik,
|
||||||
email: data[index].email,
|
email: flatData[index]?.email,
|
||||||
phone: data[index].phone,
|
phone: flatData[index]?.phone,
|
||||||
gender: data[index].gender,
|
gender: flatData[index]?.gender,
|
||||||
position: data[index].position,
|
position: flatData[index]?.position,
|
||||||
group: data[index].group,
|
group: flatData[index]?.group,
|
||||||
img: data[index].img,
|
img: flatData[index]?.img,
|
||||||
isActive: data[index].isActive,
|
isActive: flatData[index]?.isActive,
|
||||||
role: data[index].role,
|
role: flatData[index]?.role,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
|
<GuideOverlay visible={guideVisible} steps={GUIDE_MEMBER} onDismiss={dismissGuide} />
|
||||||
<View>
|
<View>
|
||||||
<View style={[Styles.wrapBtnTab]}>
|
<WrapTab>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="true"
|
value="true"
|
||||||
onPress={() => { setStatus("true") }}
|
onPress={() => { setStatus("true") }}
|
||||||
label="Aktif"
|
label="Aktif"
|
||||||
icon={<Feather name="check-circle" color={status == "false" ? 'black' : 'white'} size={20} />}
|
icon={<Feather name="check-circle" color={status == "false" ? colors.dimmed : 'white'} size={20} />}
|
||||||
n={2} />
|
n={2} />
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="false"
|
value="false"
|
||||||
onPress={() => { setStatus("false") }}
|
onPress={() => { setStatus("false") }}
|
||||||
label="Tidak Aktif"
|
label="Tidak Aktif"
|
||||||
icon={<AntDesign name="closecircleo" color={status == "false" ? 'white' : 'black'} size={20} />}
|
icon={<AntDesign name="closecircleo" color={status == "false" ? 'white' : colors.dimmed} size={20} />}
|
||||||
n={2} />
|
n={2} />
|
||||||
</View>
|
</WrapTab>
|
||||||
<InputSearch onChange={setSearch} />
|
<InputSearch onChange={setSearch} />
|
||||||
{
|
{
|
||||||
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
||||||
<View style={[Styles.mv05, Styles.rowOnly]}>
|
<View style={[Styles.mt10, Styles.rowOnly]}>
|
||||||
<Text>Filter :</Text>
|
<Text>Filter :</Text>
|
||||||
<LabelStatus size="small" category="secondary" text={nameGroup} style={[Styles.mh05]} />
|
<LabelStatus size="small" category="secondary" text={nameGroup} style={[Styles.mh05]} />
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ flex: 2 }, Styles.mt05]}>
|
<View style={[{ flex: 2 }, Styles.mt10]}>
|
||||||
{
|
{
|
||||||
loading ?
|
isLoading ?
|
||||||
arrSkeleton.map((item, index) => {
|
arrSkeleton.map((item, index) => {
|
||||||
return (
|
return (
|
||||||
<SkeletonTwoItem key={index} />
|
<SkeletonTwoItem key={index} />
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
:
|
:
|
||||||
data.length > 0
|
flatData.length > 0
|
||||||
?
|
?
|
||||||
<VirtualizedList
|
<VirtualizedList
|
||||||
data={data}
|
data={flatData}
|
||||||
getItemCount={() => data.length}
|
getItemCount={() => flatData.length}
|
||||||
getItem={getItem}
|
getItem={getItem}
|
||||||
renderItem={({ item, index }: { item: Props, index: number }) => {
|
renderItem={({ item, index }: { item: Props, index: number }) => {
|
||||||
return (
|
return (
|
||||||
@@ -168,11 +185,12 @@ export default function Index() {
|
|||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
|
<Text style={[Styles.textDefault, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada data</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
import AppHeader from "@/components/AppHeader";
|
||||||
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetNotification, apiReadOneNotification } from "@/lib/api";
|
import { apiGetNotification, apiReadAllNotification, apiReadOneNotification } from "@/lib/api";
|
||||||
import { setUpdateNotification } from "@/lib/notificationSlice";
|
import { setUpdateNotification } from "@/lib/notificationSlice";
|
||||||
import { pushToPage } from "@/lib/pushToPage";
|
import { pushToPage } from "@/lib/pushToPage";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Feather } from "@expo/vector-icons";
|
import { Feather } from "@expo/vector-icons";
|
||||||
import { useEffect, useState } from "react";
|
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { RefreshControl, SafeAreaView, View, VirtualizedList } from "react-native";
|
import { router, Stack } from "expo-router";
|
||||||
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
import { FlatList, Pressable, RefreshControl, SafeAreaView, View } from "react-native";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -22,66 +25,121 @@ type Props = {
|
|||||||
createdAt: string
|
createdAt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HeaderRow = { _type: 'header'; date: string }
|
||||||
|
type ItemRow = Props & { _type: 'item' }
|
||||||
|
type ListRow = HeaderRow | ItemRow
|
||||||
|
|
||||||
|
function getNotifStyle(category: string): { icon: keyof typeof Feather.glyphMap; color: string } {
|
||||||
|
if (category === 'announcement') return { icon: 'volume-2', color: '#3B82F6' }
|
||||||
|
if (category === 'project') return { icon: 'activity', color: '#10B981' }
|
||||||
|
if (category.includes('/task')) return { icon: 'clipboard', color: '#8B5CF6' }
|
||||||
|
if (category === 'division') return { icon: 'users', color: '#3B82F6' }
|
||||||
|
if (category.includes('/discussion') || category === 'discussion-general') return { icon: 'message-square', color: '#06B6D4' }
|
||||||
|
if (category.includes('/calendar')) return { icon: 'calendar', color: '#F59E0B' }
|
||||||
|
if (category.includes('/document')) return { icon: 'file-text', color: '#FBBF24' }
|
||||||
|
if (category === 'member') return { icon: 'user', color: '#1F3C88' }
|
||||||
|
return { icon: 'bell', color: '#6B7280' }
|
||||||
|
}
|
||||||
|
|
||||||
export default function Notification() {
|
export default function Notification() {
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const [loading, setLoading] = useState(false)
|
const { colors } = useTheme();
|
||||||
const [data, setData] = useState<Props[]>([])
|
const queryClient = useQueryClient()
|
||||||
const [page, setPage] = useState(1)
|
|
||||||
const [waiting, setWaiting] = useState(false)
|
|
||||||
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const updateNotification = useSelector((state: any) => state.notificationUpdate)
|
const updateNotification = useSelector((state: any) => state.notificationUpdate)
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
const [markingAll, setMarkingAll] = useState(false)
|
||||||
|
const [showConfirm, setShowConfirm] = useState(false)
|
||||||
|
|
||||||
async function handleLoad(loading: boolean, thisPage: number) {
|
const {
|
||||||
try {
|
data,
|
||||||
setLoading(loading)
|
fetchNextPage,
|
||||||
setPage(thisPage)
|
hasNextPage,
|
||||||
setWaiting(true)
|
isFetchingNextPage,
|
||||||
|
isLoading,
|
||||||
|
refetch
|
||||||
|
} = useInfiniteQuery({
|
||||||
|
queryKey: ['notifications'],
|
||||||
|
queryFn: async ({ pageParam = 1 }) => {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiGetNotification({ user: hasil, page: thisPage })
|
const response = await apiGetNotification({ user: hasil, page: pageParam })
|
||||||
if (thisPage == 1) {
|
return response;
|
||||||
setData(response.data)
|
},
|
||||||
} else if (thisPage > 1 && response.data.length > 0) {
|
initialPageParam: 1,
|
||||||
setData([...data, ...response.data])
|
getNextPageParam: (lastPage, allPages) => {
|
||||||
} else {
|
return lastPage.data.length > 0 ? allPages.length + 1 : undefined;
|
||||||
return;
|
},
|
||||||
|
enabled: !!token?.current,
|
||||||
|
staleTime: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
const flatData = useMemo(() => {
|
||||||
|
return data?.pages.flatMap(page => page.data) || [];
|
||||||
|
}, [data])
|
||||||
|
|
||||||
|
const listData = useMemo<ListRow[]>(() => {
|
||||||
|
const BULAN: Record<string, number> = {
|
||||||
|
'JAN': 0, 'FEB': 1, 'MAR': 2, 'APR': 3, 'MEI': 4, 'JUN': 5,
|
||||||
|
'JUL': 6, 'AGU': 7, 'SEP': 8, 'OKT': 9, 'NOV': 10, 'DES': 11,
|
||||||
|
}
|
||||||
|
const parseDate = (str: string) => {
|
||||||
|
const [d, m, y] = str.split(' ')
|
||||||
|
return new Date(Number(y), BULAN[m?.toUpperCase()] ?? 0, Number(d)).getTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
const groups: Record<string, Props[]> = {}
|
||||||
|
const dateOrder: string[] = []
|
||||||
|
|
||||||
|
flatData.forEach((item) => {
|
||||||
|
if (!groups[item.createdAt]) {
|
||||||
|
groups[item.createdAt] = []
|
||||||
|
dateOrder.push(item.createdAt)
|
||||||
}
|
}
|
||||||
|
groups[item.createdAt].push(item)
|
||||||
|
})
|
||||||
|
|
||||||
|
dateOrder.sort((a, b) => parseDate(b) - parseDate(a))
|
||||||
|
|
||||||
|
const result: ListRow[] = []
|
||||||
|
dateOrder.forEach((date) => {
|
||||||
|
result.push({ _type: 'header', date })
|
||||||
|
const sorted = [...groups[date]].sort((a, b) => Number(a.isRead) - Number(b.isRead))
|
||||||
|
sorted.forEach((item) => result.push({ ...item, _type: 'item' }))
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}, [flatData])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refetch()
|
||||||
|
}, [updateNotification, refetch])
|
||||||
|
|
||||||
|
const handleRefresh = async () => {
|
||||||
|
setRefreshing(true)
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['notifications'] })
|
||||||
|
setRefreshing(false)
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasUnread = flatData.some((item) => !item.isRead)
|
||||||
|
|
||||||
|
async function handleReadAll() {
|
||||||
|
try {
|
||||||
|
setMarkingAll(true)
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
await apiReadAllNotification({ user: hasil })
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['notifications'] })
|
||||||
|
dispatch(setUpdateNotification(!updateNotification))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setMarkingAll(false)
|
||||||
setWaiting(false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const loadMoreData = () => {
|
|
||||||
if (waiting) return
|
|
||||||
setTimeout(() => {
|
|
||||||
handleLoad(false, page + 1)
|
|
||||||
}, 1000);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(true, 1)
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
|
|
||||||
const getItem = (_data: unknown, index: number): Props => ({
|
|
||||||
id: data[index].id,
|
|
||||||
title: data[index].title,
|
|
||||||
desc: data[index].desc,
|
|
||||||
category: data[index].category,
|
|
||||||
idContent: data[index].idContent,
|
|
||||||
isRead: data[index].isRead,
|
|
||||||
createdAt: data[index].createdAt,
|
|
||||||
});
|
|
||||||
|
|
||||||
async function handleReadNotification(id: string, category: string, idContent: string) {
|
async function handleReadNotification(id: string, category: string, idContent: string) {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiReadOneNotification({ user: hasil, id: id })
|
await apiReadOneNotification({ user: hasil, id: id })
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['notifications'] })
|
||||||
pushToPage(category, idContent)
|
pushToPage(category, idContent)
|
||||||
dispatch(setUpdateNotification(!updateNotification))
|
dispatch(setUpdateNotification(!updateNotification))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -89,64 +147,150 @@ export default function Notification() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
async function handleMarkOneRead(id: string) {
|
||||||
setRefreshing(true)
|
try {
|
||||||
handleLoad(false, 1)
|
const hasil = await decryptToken(String(token?.current))
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await apiReadOneNotification({ user: hasil, id: id })
|
||||||
setRefreshing(false)
|
await queryClient.invalidateQueries({ queryKey: ['notifications'] })
|
||||||
};
|
dispatch(setUpdateNotification(!updateNotification))
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15]}>
|
<Stack.Screen
|
||||||
{
|
options={{
|
||||||
loading ?
|
header: () => (
|
||||||
arrSkeleton.map((item, index) => {
|
<AppHeader
|
||||||
return (
|
title="Notifikasi"
|
||||||
<SkeletonTwoItem key={index} />
|
showBack={true}
|
||||||
)
|
onPressLeft={() => router.back()}
|
||||||
})
|
right={
|
||||||
:
|
hasUnread ? (
|
||||||
data.length > 0 ?
|
<Pressable
|
||||||
<VirtualizedList
|
onPress={() => setShowConfirm(true)}
|
||||||
data={data}
|
disabled={markingAll}
|
||||||
getItemCount={() => data.length}
|
style={{ opacity: markingAll ? 0.5 : 1, padding: 4 }}
|
||||||
getItem={getItem}
|
>
|
||||||
renderItem={({ item, index }: { item: Props, index: number }) => {
|
<Feather name="check-square" size={20} color="white" />
|
||||||
return (
|
</Pressable>
|
||||||
<BorderBottomItem
|
) : undefined
|
||||||
borderType="bottom"
|
}
|
||||||
icon={
|
/>
|
||||||
<View style={[Styles.iconContent, item.isRead ? ColorsStatus.secondary : ColorsStatus.primary]}>
|
)
|
||||||
<Feather name="bell" size={25} color="white" />
|
}}
|
||||||
</View>
|
/>
|
||||||
}
|
|
||||||
title={item.title}
|
|
||||||
rightTopInfo={item.createdAt}
|
|
||||||
desc={item.desc}
|
|
||||||
textColor={item.isRead ? 'gray' : 'black'}
|
|
||||||
onPress={() => {
|
|
||||||
handleReadNotification(item.id, item.category, item.idContent)
|
|
||||||
|
|
||||||
}}
|
<ModalConfirmation
|
||||||
/>
|
visible={showConfirm}
|
||||||
)
|
title="Tandai Semua Dibaca"
|
||||||
}}
|
message="Semua notifikasi akan ditandai sebagai telah dibaca."
|
||||||
keyExtractor={(item, index) => String(index)}
|
confirmText="Tandai"
|
||||||
onEndReached={loadMoreData}
|
cancelText="Batal"
|
||||||
onEndReachedThreshold={0.5}
|
onConfirm={() => {
|
||||||
showsVerticalScrollIndicator={false}
|
setShowConfirm(false)
|
||||||
refreshControl={
|
handleReadAll()
|
||||||
<RefreshControl
|
}}
|
||||||
refreshing={refreshing}
|
onCancel={() => setShowConfirm(false)}
|
||||||
onRefresh={handleRefresh}
|
/>
|
||||||
/>
|
|
||||||
}
|
|
||||||
|
<View style={[Styles.flex1, Styles.ph15, Styles.notifContainer]}>
|
||||||
|
{isLoading ? (
|
||||||
|
[0, 1, 2, 3, 4].map((_, i) => <SkeletonTwoItem key={i} />)
|
||||||
|
) : flatData.length === 0 ? (
|
||||||
|
<View style={[Styles.contentItemCenter, Styles.mt30]}>
|
||||||
|
<Feather name="bell-off" size={42} color={colors.icon + '40'} />
|
||||||
|
<Text style={[Styles.mt10, { color: colors.dimmed, fontSize: 14 }]}>
|
||||||
|
Tidak ada notifikasi
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<FlatList
|
||||||
|
data={listData}
|
||||||
|
keyExtractor={(item, index) => String(index)}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
onEndReached={() => {
|
||||||
|
if (hasNextPage && !isFetchingNextPage) fetchNextPage()
|
||||||
|
}}
|
||||||
|
onEndReachedThreshold={0.5}
|
||||||
|
refreshControl={
|
||||||
|
<RefreshControl
|
||||||
|
refreshing={refreshing}
|
||||||
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
:
|
}
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
|
renderItem={({ item }) => {
|
||||||
}
|
if (item._type === 'header') {
|
||||||
|
return (
|
||||||
|
<View style={[Styles.rowItemsCenter, Styles.notifHeaderRow]}>
|
||||||
|
<Text style={[Styles.notifDateText, { color: colors.dimmed }]}>
|
||||||
|
{item.date}
|
||||||
|
</Text>
|
||||||
|
<View style={[Styles.notifDateSeparator, { backgroundColor: colors.icon + '20' }]} />
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const { icon, color } = getNotifStyle(item.category)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
onPress={() => handleReadNotification(item.id, item.category, item.idContent)}
|
||||||
|
style={({ pressed }) => [Styles.notifItemRow, {
|
||||||
|
borderColor: colors.icon + '20',
|
||||||
|
backgroundColor: pressed
|
||||||
|
? colors.icon + '10'
|
||||||
|
: item.isRead
|
||||||
|
? colors.icon + '10'
|
||||||
|
: colors.card,
|
||||||
|
}]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.notifIconContainer, { backgroundColor: color + '20' }]}>
|
||||||
|
<Feather name={icon} size={20} color={color} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={[Styles.flex1, Styles.notifContent]}>
|
||||||
|
<View style={[Styles.rowSpaceBetween, Styles.itemsCenter]}>
|
||||||
|
<View style={[Styles.flex1, Styles.mr10]}>
|
||||||
|
<Text
|
||||||
|
style={[Styles.textDefaultSemiBold, { color: item.isRead ? colors.dimmed : colors.text }]}
|
||||||
|
numberOfLines={1}
|
||||||
|
>
|
||||||
|
{item.title}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
{!item.isRead && (
|
||||||
|
<Pressable
|
||||||
|
onPress={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
handleMarkOneRead(item.id)
|
||||||
|
}}
|
||||||
|
hitSlop={8}
|
||||||
|
style={({ pressed }) => ({ opacity: pressed ? 0.5 : 1, flexShrink: 0 })}
|
||||||
|
>
|
||||||
|
<Text style={Styles.notifMarkReadText}>
|
||||||
|
Tandai dibaca
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
<Text
|
||||||
|
style={[Styles.textMediumNormal, { color: item.isRead ? colors.dimmed : colors.text, opacity: item.isRead ? 0.7 : 1 }]}
|
||||||
|
numberOfLines={2}
|
||||||
|
>
|
||||||
|
{item.desc}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi";
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
import BorderBottomItem from "@/components/borderBottomItem";
|
||||||
import { ButtonForm } from "@/components/buttonForm";
|
import { ButtonForm } from "@/components/buttonForm";
|
||||||
import ButtonTab from "@/components/buttonTab";
|
import ButtonTab from "@/components/buttonTab";
|
||||||
@@ -7,16 +7,21 @@ import { InputForm } from "@/components/inputForm";
|
|||||||
import InputSearch from "@/components/inputSearch";
|
import InputSearch from "@/components/inputSearch";
|
||||||
import LabelStatus from "@/components/labelStatus";
|
import LabelStatus from "@/components/labelStatus";
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
import SkeletonTwoItem from "@/components/skeletonTwoItem";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
import WrapTab from "@/components/wrapTab";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiDeletePosition, apiEditPosition, apiGetPosition } from "@/lib/api";
|
import { apiDeletePosition, apiEditPosition, apiGetPosition } from "@/lib/api";
|
||||||
import { setUpdatePosition } from "@/lib/positionSlice";
|
import { setUpdatePosition } from "@/lib/positionSlice";
|
||||||
|
import { GUIDE_POSITION } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign, Feather, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { AntDesign, Feather, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useLocalSearchParams } from "expo-router";
|
import { useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { RefreshControl, View, VirtualizedList } from "react-native";
|
import { RefreshControl, View, VirtualizedList } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
@@ -30,49 +35,54 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
|
||||||
const [loading, setLoading] = useState(true)
|
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const [status, setStatus] = useState<'true' | 'false'>('true')
|
const { colors } = useTheme()
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
|
||||||
const { active, group } = useLocalSearchParams<{ active?: string, group?: string }>()
|
const { active, group } = useLocalSearchParams<{ active?: string, group?: string }>()
|
||||||
|
const [status, setStatus] = useState<'true' | 'false'>(active == 'false' ? 'false' : 'true')
|
||||||
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const [isModal, setModal] = useState(false)
|
const [isModal, setModal] = useState(false)
|
||||||
const [isVisibleEdit, setVisibleEdit] = useState(false)
|
const [isVisibleEdit, setVisibleEdit] = useState(false)
|
||||||
const [data, setData] = useState<Props[]>([])
|
|
||||||
const [search, setSearch] = useState('')
|
const [search, setSearch] = useState('')
|
||||||
const [nameGroup, setNameGroup] = useState('')
|
|
||||||
const [loadingSubmit, setLoadingSubmit] = useState(false)
|
const [loadingSubmit, setLoadingSubmit] = useState(false)
|
||||||
const [chooseData, setChooseData] = useState({ name: '', id: '', active: false, idGroup: '' })
|
const [chooseData, setChooseData] = useState({ name: '', id: '', active: false, idGroup: '' })
|
||||||
const [error, setError] = useState({
|
const [error, setError] = useState({
|
||||||
name: false,
|
name: false,
|
||||||
});
|
});
|
||||||
|
const queryClient = useQueryClient()
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('position')
|
||||||
|
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.positionUpdate)
|
const update = useSelector((state: any) => state.positionUpdate)
|
||||||
|
|
||||||
async function handleLoad(loading: boolean) {
|
// TanStack Query for Positions
|
||||||
try {
|
const {
|
||||||
setLoading(loading)
|
data: queryData,
|
||||||
|
isLoading,
|
||||||
|
refetch
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ['positions', { status, search, group }],
|
||||||
|
queryFn: async () => {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiGetPosition({ user: hasil, active: status, search: search, group: String(group) })
|
const response = await apiGetPosition({
|
||||||
setData(response.data)
|
user: hasil,
|
||||||
setNameGroup(response.filter.name)
|
active: status,
|
||||||
} catch (error) {
|
search: search,
|
||||||
console.error(error)
|
group: String(group)
|
||||||
} finally {
|
})
|
||||||
setLoading(false)
|
return response;
|
||||||
}
|
},
|
||||||
}
|
enabled: !!token?.current,
|
||||||
|
staleTime: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = useMemo(() => queryData?.data || [], [queryData])
|
||||||
|
const nameGroup = useMemo(() => queryData?.filter?.name || "", [queryData])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLoad(false)
|
refetch()
|
||||||
}, [update])
|
}, [update, refetch])
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
handleLoad(true)
|
|
||||||
}, [status, search, group])
|
|
||||||
|
|
||||||
|
|
||||||
function handleChooseData(id: string, name: string, active: boolean, group: string) {
|
function handleChooseData(id: string, name: string, active: boolean, group: string) {
|
||||||
@@ -85,8 +95,11 @@ export default function Index() {
|
|||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiDeletePosition({ user: hasil, isActive: chooseData.active }, chooseData.id)
|
const response = await apiDeletePosition({ user: hasil, isActive: chooseData.active }, chooseData.id)
|
||||||
dispatch(setUpdatePosition(!update))
|
dispatch(setUpdatePosition(!update))
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
|
const message = error?.response?.data?.message || "Gagal menghapus data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil mengupdate data', })
|
Toast.show({ type: 'small', text1: 'Berhasil mengupdate data', })
|
||||||
@@ -104,8 +117,11 @@ export default function Index() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
|
const message = error?.response?.data?.message || "Gagal mengubah data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingSubmit(false)
|
setLoadingSubmit(false)
|
||||||
setVisibleEdit(false)
|
setVisibleEdit(false)
|
||||||
@@ -129,10 +145,11 @@ export default function Index() {
|
|||||||
handleEdit()
|
handleEdit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const arrSkeleton = [0, 1, 2, 3, 4]
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
handleLoad(false)
|
await queryClient.invalidateQueries({ queryKey: ['positions'] })
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -146,36 +163,37 @@ export default function Index() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
|
<GuideOverlay visible={guideVisible} steps={GUIDE_POSITION} onDismiss={dismissGuide} />
|
||||||
<View>
|
<View>
|
||||||
<View style={[Styles.wrapBtnTab]}>
|
<WrapTab>
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="true"
|
value="true"
|
||||||
onPress={() => { setStatus("true") }}
|
onPress={() => { setStatus("true") }}
|
||||||
label="Aktif"
|
label="Aktif"
|
||||||
icon={<Feather name="check-circle" color={status == "true" ? 'white' : 'black'} size={20} />}
|
icon={<Feather name="check-circle" color={status == "true" ? 'white' : colors.dimmed} size={20} />}
|
||||||
n={2} />
|
n={2} />
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={status == "false" ? "false" : "true"}
|
active={status == "false" ? "false" : "true"}
|
||||||
value="false"
|
value="false"
|
||||||
onPress={() => { setStatus("false") }}
|
onPress={() => { setStatus("false") }}
|
||||||
label="Tidak Aktif"
|
label="Tidak Aktif"
|
||||||
icon={<AntDesign name="closecircleo" color={status == "false" ? 'white' : 'black'} size={20} />}
|
icon={<AntDesign name="closecircleo" color={status == "false" ? 'white' : colors.dimmed} size={20} />}
|
||||||
n={2} />
|
n={2} />
|
||||||
</View>
|
</WrapTab>
|
||||||
<InputSearch onChange={setSearch} />
|
<InputSearch onChange={setSearch} />
|
||||||
{
|
{
|
||||||
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
||||||
<View style={[Styles.mv05, Styles.rowOnly]}>
|
<View style={[Styles.mt10, Styles.rowOnly]}>
|
||||||
<Text>Filter :</Text>
|
<Text>Filter :</Text>
|
||||||
<LabelStatus size="small" category="secondary" text={nameGroup} style={[Styles.mh05]} />
|
<LabelStatus size="small" category="secondary" text={nameGroup} style={[Styles.mh05]} />
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ flex: 2 }, Styles.mt05]}>
|
<View style={[Styles.flex2, Styles.mt10]}>
|
||||||
{
|
{
|
||||||
loading ?
|
isLoading ?
|
||||||
arrSkeleton.map((item, index) => {
|
arrSkeleton.map((item, index) => {
|
||||||
return (
|
return (
|
||||||
<SkeletonTwoItem key={index} />
|
<SkeletonTwoItem key={index} />
|
||||||
@@ -197,8 +215,8 @@ export default function Index() {
|
|||||||
}}
|
}}
|
||||||
borderType="all"
|
borderType="all"
|
||||||
icon={
|
icon={
|
||||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
<View style={[Styles.iconContent]}>
|
||||||
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
|
<MaterialCommunityIcons name="account-tie-outline" size={25} color={'black'} />
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
title={item.name}
|
title={item.name}
|
||||||
@@ -212,29 +230,28 @@ export default function Index() {
|
|||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
|
<Text style={[Styles.textDefault, Styles.textCenter, { color: colors.dimmed }]}>Tidak ada data</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={() => setModal(false)} title={chooseData.name}>
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={() => setModal(false)} title={chooseData.name}>
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="toggle-switch-off-outline" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="toggle-switch-off-outline" color={colors.text} size={25} />}
|
||||||
title={chooseData.active ? 'Non Aktifkan' : "Aktifkan"}
|
title={chooseData.active ? 'Non Aktifkan' : "Aktifkan"}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
AlertKonfirmasi({
|
setTimeout(() => {
|
||||||
title: 'Konfirmasi',
|
setShowDeleteModal(true)
|
||||||
desc: chooseData.active ? 'Apakah anda yakin ingin menonaktifkan data?' : 'Apakah anda yakin ingin mengaktifkan data?',
|
}, 600)
|
||||||
onPress: () => { handleDelete() }
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="pencil-outline" color={colors.text} size={25} />}
|
||||||
title="Edit"
|
title="Edit"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
@@ -248,13 +265,14 @@ export default function Index() {
|
|||||||
|
|
||||||
|
|
||||||
<DrawerBottom animation="none" keyboard height={30} backdropPressable={false} isVisible={isVisibleEdit} setVisible={() => setVisibleEdit(false)} title="Edit Jabatan">
|
<DrawerBottom animation="none" keyboard height={30} backdropPressable={false} isVisible={isVisibleEdit} setVisible={() => setVisibleEdit(false)} title="Edit Jabatan">
|
||||||
<View style={{ justifyContent: 'space-between', flex: 1 }}>
|
<View style={[Styles.justifySpaceBetween, Styles.flex1]}>
|
||||||
<View>
|
<View>
|
||||||
<InputForm
|
<InputForm
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Nama Jabatan"
|
placeholder="Nama Jabatan"
|
||||||
required
|
required
|
||||||
label="Jabatan"
|
label="Jabatan"
|
||||||
|
bg={"transparent"}
|
||||||
value={chooseData.name}
|
value={chooseData.name}
|
||||||
onChange={(val) => { validationForm(val) }}
|
onChange={(val) => { validationForm(val) }}
|
||||||
error={error.name}
|
error={error.name}
|
||||||
@@ -266,6 +284,19 @@ export default function Index() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message={chooseData.active ? 'Apakah anda yakin ingin menonaktifkan data?' : 'Apakah anda yakin ingin mengaktifkan data?'}
|
||||||
|
onConfirm={() => {
|
||||||
|
setShowDeleteModal(false)
|
||||||
|
handleDelete()
|
||||||
|
}}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText={chooseData.active ? "Nonaktifkan" : "Aktifkan"}
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,57 @@
|
|||||||
import AlertKonfirmasi from "@/components/alertKonfirmasi";
|
|
||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import { ButtonHeader } from "@/components/buttonHeader";
|
import { ButtonHeader } from "@/components/buttonHeader";
|
||||||
import ItemDetailMember from "@/components/itemDetailMember";
|
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
import { assetUserImage } from "@/constants/AssetsError";
|
import { assetUserImage } from "@/constants/AssetsError";
|
||||||
import { ConstEnv } from "@/constants/ConstEnv";
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
|
import { apiGetProfile } from "@/lib/api";
|
||||||
|
import { setEntities } from "@/lib/entitiesSlice";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { Feather, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
||||||
|
import { LinearGradient } from "expo-linear-gradient";
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Image, Pressable, SafeAreaView, ScrollView, View } from "react-native";
|
import { Image, Pressable, RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
import ImageViewing from 'react-native-image-viewing';
|
import ImageViewing from 'react-native-image-viewing';
|
||||||
import { useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
|
||||||
export default function Profile() {
|
export default function Profile() {
|
||||||
const { signOut } = useAuthSession()
|
const { colors } = useTheme();
|
||||||
const entities = useSelector((state: any) => state.entities)
|
const entities = useSelector((state: any) => state.entities)
|
||||||
const [error, setError] = useState(false)
|
const [error, setError] = useState(false)
|
||||||
const [preview, setPreview] = useState(false)
|
const [preview, setPreview] = useState(false)
|
||||||
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
|
||||||
|
async function handleUserLogin() {
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
apiGetProfile({ id: hasil })
|
||||||
|
.then((data) => dispatch(setEntities(data.data)))
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRefresh = async () => {
|
||||||
|
setRefreshing(true)
|
||||||
|
handleUserLogin()
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
|
setRefreshing(false)
|
||||||
|
};
|
||||||
|
|
||||||
|
const infoRows = [
|
||||||
|
{ icon: <MaterialCommunityIcons name="card-account-details" size={20} color={colors.icon} />, label: 'NIK', value: entities.nik },
|
||||||
|
{ icon: <MaterialCommunityIcons name="office-building-outline" size={20} color={colors.icon} />, label: 'Lembaga Desa', value: entities.group },
|
||||||
|
{ icon: <MaterialCommunityIcons name="account-tie" size={20} color={colors.icon} />, label: 'Jabatan', value: entities.position },
|
||||||
|
{ icon: <MaterialIcons name="phone" size={20} color={colors.icon} />, label: 'No Telepon', value: `0${entities.phone}` },
|
||||||
|
{ icon: <MaterialIcons name="email" size={20} color={colors.icon} />, label: 'Email', value: entities.email },
|
||||||
|
{ icon: <MaterialCommunityIcons name="gender-male-female" size={20} color={colors.icon} />, label: 'Jenis Kelamin', value: entities.gender == "F" ? 'Perempuan' : 'Laki-laki' },
|
||||||
|
]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
headerTitle: 'Profile',
|
headerTitle: 'Profile',
|
||||||
@@ -34,59 +63,69 @@ export default function Profile() {
|
|||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={
|
right={
|
||||||
<ButtonHeader
|
<ButtonHeader
|
||||||
item={<AntDesign name="logout" size={20} color="white" />}
|
item={<Feather name="settings" size={20} color="white" />}
|
||||||
onPress={() => {
|
onPress={() => router.push('/setting')}
|
||||||
AlertKonfirmasi({
|
|
||||||
title: 'Keluar',
|
|
||||||
desc: 'Apakah anda yakin ingin keluar?',
|
|
||||||
onPress: () => { signOut() }
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
// headerRight: () => <ButtonHeader
|
|
||||||
// item={<AntDesign name="logout" size={20} color="white" />}
|
|
||||||
// onPress={() => {
|
|
||||||
// AlertKonfirmasi({
|
|
||||||
// title: 'Keluar',
|
|
||||||
// desc: 'Apakah anda yakin ingin keluar?',
|
|
||||||
// onPress: () => { signOut() }
|
|
||||||
// })
|
|
||||||
// }}
|
|
||||||
// />
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView style={[Styles.h100]}>
|
<ScrollView
|
||||||
<View style={{ flexDirection: 'column' }}>
|
refreshControl={
|
||||||
<View style={[Styles.wrapHeadViewMember]}>
|
<RefreshControl
|
||||||
<Pressable onPress={() => setPreview(true)}>
|
refreshing={refreshing}
|
||||||
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
|
>
|
||||||
|
<LinearGradient
|
||||||
|
colors={[colors.header, colors.homeGradient]}
|
||||||
|
style={[Styles.wrapHeadViewMember]}
|
||||||
|
>
|
||||||
|
<Pressable onPress={() => setPreview(true)}>
|
||||||
|
<View style={[Styles.memberAvatarRing]}>
|
||||||
<Image
|
<Image
|
||||||
source={error ? require("../../assets/images/user.jpg") : { uri: `${ConstEnv.url_storage}/files/${entities.img}` }}
|
source={error ? require("../../assets/images/user.jpg") : { uri: `${ConstEnv.url_storage}/files/${entities.img}` }}
|
||||||
onError={() => { setError(true) }}
|
onError={() => setError(true)}
|
||||||
style={[Styles.userProfileBig]}
|
style={[Styles.userProfileBig]}
|
||||||
/>
|
/>
|
||||||
</Pressable>
|
|
||||||
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10]}>{entities.name}</Text>
|
|
||||||
<Text style={[Styles.textMediumNormal, Styles.cWhite]}>{entities.role}</Text>
|
|
||||||
</View>
|
|
||||||
<View style={[Styles.p15]}>
|
|
||||||
<View style={[Styles.rowSpaceBetween]}>
|
|
||||||
<Text style={[Styles.textDefaultSemiBold]}>Informasi</Text>
|
|
||||||
{
|
|
||||||
entities.idUserRole != "developer" && <Text onPress={() => { router.push('/edit-profile') }} style={[Styles.textLink]}>Edit</Text>
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
<ItemDetailMember category="nik" value={entities.nik} />
|
</Pressable>
|
||||||
<ItemDetailMember category="group" value={entities.group} />
|
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10, Styles.textCenter]}>{entities.name}</Text>
|
||||||
<ItemDetailMember category="position" value={entities.position} />
|
<Text style={[Styles.textMediumNormal, Styles.cWhiteDimmed]}>{entities.role}</Text>
|
||||||
<ItemDetailMember category="phone" value={`0${entities.phone}`} />
|
{entities.isApprover && (
|
||||||
<ItemDetailMember category="email" value={entities.email} />
|
<View style={[Styles.memberBadgeRow, { justifyContent: 'center' }]}>
|
||||||
<ItemDetailMember category="gender" value={entities.gender == "F" ? 'Perempuan' : 'Laki-laki'} />
|
<View style={[Styles.memberBadgeApprover]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, Styles.cWhite]}>APPROVER</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</LinearGradient>
|
||||||
|
|
||||||
|
<View style={[Styles.p15]}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, Styles.mb08, { color: colors.dimmed }]}>Informasi</Text>
|
||||||
|
<View>
|
||||||
|
{infoRows.map((item, index, arr) => (
|
||||||
|
<View
|
||||||
|
key={index}
|
||||||
|
style={[Styles.memberInfoRow, { borderBottomWidth: index < arr.length - 1 ? 1 : 0, borderBottomColor: `${colors.dimmed}30` }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.memberInfoIcon]}>
|
||||||
|
{item.icon}
|
||||||
|
</View>
|
||||||
|
<View style={[Styles.memberInfoContent]}>
|
||||||
|
<Text style={[Styles.textInformation, { color: colors.dimmed }]}>{item.label}</Text>
|
||||||
|
<Text style={[Styles.textDefault, Styles.mt02, { color: colors.text }]} numberOfLines={1}>{item.value ?? '-'}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<ImageViewing
|
<ImageViewing
|
||||||
images={[{ uri: error ? assetUserImage.uri : `${ConstEnv.url_storage}/files/${entities.img}` }]}
|
images={[{ uri: error ? assetUserImage.uri : `${ConstEnv.url_storage}/files/${entities.img}` }]}
|
||||||
imageIndex={0}
|
imageIndex={0}
|
||||||
@@ -96,4 +135,4 @@ export default function Profile() {
|
|||||||
/>
|
/>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ import BorderBottomItem from "@/components/borderBottomItem"
|
|||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader"
|
import ButtonSaveHeader from "@/components/buttonSaveHeader"
|
||||||
import ButtonSelect from "@/components/buttonSelect"
|
import ButtonSelect from "@/components/buttonSelect"
|
||||||
import DrawerBottom from "@/components/drawerBottom"
|
import DrawerBottom from "@/components/drawerBottom"
|
||||||
|
import LoadingCenter from "@/components/loadingCenter"
|
||||||
import MenuItemRow from "@/components/menuItemRow"
|
import MenuItemRow from "@/components/menuItemRow"
|
||||||
import Styles from "@/constants/Styles"
|
import Styles from "@/constants/Styles"
|
||||||
import { apiAddFileProject, apiCheckFileProject } from "@/lib/api"
|
import { apiAddFileProject, apiCheckFileProject } from "@/lib/api"
|
||||||
import { setUpdateProject } from "@/lib/projectUpdate"
|
import { setUpdateProject } from "@/lib/projectUpdate"
|
||||||
import { useAuthSession } from "@/providers/AuthProvider"
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider"
|
||||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"
|
||||||
import * as DocumentPicker from "expo-document-picker"
|
import * as DocumentPicker from "expo-document-picker"
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router"
|
import { router, Stack, useLocalSearchParams } from "expo-router"
|
||||||
@@ -17,6 +19,7 @@ import Toast from "react-native-toast-message"
|
|||||||
import { useDispatch, useSelector } from "react-redux"
|
import { useDispatch, useSelector } from "react-redux"
|
||||||
|
|
||||||
export default function ProjectAddFile() {
|
export default function ProjectAddFile() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>()
|
||||||
const [fileForm, setFileForm] = useState<any[]>([])
|
const [fileForm, setFileForm] = useState<any[]>([])
|
||||||
const [listFile, setListFile] = useState<any[]>([])
|
const [listFile, setListFile] = useState<any[]>([])
|
||||||
@@ -115,9 +118,11 @@ export default function ProjectAddFile() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -127,7 +132,7 @@ export default function ProjectAddFile() {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -153,20 +158,23 @@ export default function ProjectAddFile() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView>
|
{
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
loading && <LoadingCenter size="large" />
|
||||||
|
}
|
||||||
|
<ScrollView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
|
<View style={[Styles.p15]}>
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
||||||
{
|
{
|
||||||
listFile.length > 0 && (
|
listFile.length > 0 && (
|
||||||
<View style={[Styles.mb15]}>
|
<View style={[Styles.mb15]}>
|
||||||
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>File</Text>
|
<Text style={[Styles.textDefaultSemiBold, Styles.mv05, { color: colors.text }]}>File</Text>
|
||||||
<View style={[Styles.wrapPaper]}>
|
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
{
|
{
|
||||||
listFile.map((item, index) => (
|
listFile.map((item, index) => (
|
||||||
<BorderBottomItem
|
<BorderBottomItem
|
||||||
key={index}
|
key={index}
|
||||||
borderType="all"
|
borderType="all"
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
|
||||||
title={item}
|
title={item}
|
||||||
titleWeight="normal"
|
titleWeight="normal"
|
||||||
onPress={() => { setIndexDelFile(index); setModal(true) }}
|
onPress={() => { setIndexDelFile(index); setModal(true) }}
|
||||||
@@ -180,15 +188,12 @@ export default function ProjectAddFile() {
|
|||||||
{
|
{
|
||||||
loadingCheck && <ActivityIndicator size="small" />
|
loadingCheck && <ActivityIndicator size="small" />
|
||||||
}
|
}
|
||||||
{
|
|
||||||
loading && <ActivityIndicator size="large" />
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile) }}
|
onPress={() => { deleteFile(indexDelFile) }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiAddMemberProject, apiGetProjectOne, apiGetUser } from "@/lib/api";
|
import { apiAddMemberProject, apiGetProjectOne, apiGetUser } from "@/lib/api";
|
||||||
import { setUpdateProject } from "@/lib/projectUpdate";
|
import { setUpdateProject } from "@/lib/projectUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { AntDesign } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -23,6 +24,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AddMemberProject() {
|
export default function AddMemberProject() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const update = useSelector((state: any) => state.projectUpdate)
|
const update = useSelector((state: any) => state.projectUpdate)
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
@@ -43,9 +45,11 @@ export default function AddMemberProject() {
|
|||||||
setIdGroup(responseGroup.data.idGroup)
|
setIdGroup(responseGroup.data.idGroup)
|
||||||
const responsemember = await apiGetUser({ user: hasil, active: "true", search: search, group: String(responseGroup.data.idGroup) })
|
const responsemember = await apiGetUser({ user: hasil, active: "true", search: search, group: String(responseGroup.data.idGroup) })
|
||||||
setData(responsemember.data.filter((i: any) => i.idUserRole != 'supadmin'))
|
setData(responsemember.data.filter((i: any) => i.idUserRole != 'supadmin'))
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengambil data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +78,22 @@ export default function AddMemberProject() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const availableData = data.filter((item: any) => !dataOld.some((i: any) => i.idUser == item.id))
|
||||||
|
const isAllSelected = availableData.length > 0 && availableData.every((item: any) =>
|
||||||
|
selectMember.some((s: any) => s.idUser == item.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
function handleSelectAll() {
|
||||||
|
if (isAllSelected) {
|
||||||
|
setSelectMember([])
|
||||||
|
} else {
|
||||||
|
const newMembers = availableData
|
||||||
|
.filter((item: any) => !selectMember.some((s: any) => s.idUser == item.id))
|
||||||
|
.map((item: any) => ({ idUser: item.id, name: item.name, img: item.img }))
|
||||||
|
setSelectMember([...selectMember, ...newMembers])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleAddMember() {
|
async function handleAddMember() {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
@@ -84,9 +104,11 @@ export default function AddMemberProject() {
|
|||||||
dispatch(setUpdateProject({ ...update, member: !update.member }))
|
dispatch(setUpdateProject({ ...update, member: !update.member }))
|
||||||
router.back()
|
router.back()
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan anggota"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -98,7 +120,7 @@ export default function AddMemberProject() {
|
|||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
headerTitle: 'Tambah Anggota Kegiatan',
|
headerTitle: 'Tambah Anggota',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
// headerRight: () => (
|
// headerRight: () => (
|
||||||
// <ButtonSaveHeader
|
// <ButtonSaveHeader
|
||||||
@@ -111,7 +133,7 @@ export default function AddMemberProject() {
|
|||||||
// )
|
// )
|
||||||
header: () => (
|
header: () => (
|
||||||
<AppHeader
|
<AppHeader
|
||||||
title="Tambah Anggota Kegiatan"
|
title="Tambah Anggota"
|
||||||
showBack={true}
|
showBack={true}
|
||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={
|
right={
|
||||||
@@ -127,7 +149,7 @@ export default function AddMemberProject() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
|
||||||
<InputSearch onChange={(val) => handleSearch(val)} value={search} />
|
<InputSearch onChange={(val) => handleSearch(val)} value={search} />
|
||||||
{
|
{
|
||||||
selectMember.length > 0
|
selectMember.length > 0
|
||||||
@@ -148,12 +170,21 @@ export default function AddMemberProject() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.pv05, { textAlign: 'center' }]}>Tidak ada member yang dipilih</Text>
|
<Text style={[Styles.textDefault, Styles.pv05, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada member yang dipilih</Text>
|
||||||
}
|
}
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
>
|
>
|
||||||
|
{availableData.length > 0 && (
|
||||||
|
<Pressable
|
||||||
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20', paddingTop: 0 }]}
|
||||||
|
onPress={handleSelectAll}
|
||||||
|
>
|
||||||
|
<Text style={[Styles.textMediumSemiBold]}>{isAllSelected ? 'Batalkan Semua' : 'Pilih Semua'}</Text>
|
||||||
|
{isAllSelected && <AntDesign name="check" size={20} color={colors.text} />}
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
{
|
{
|
||||||
data.length > 0 ?
|
data.length > 0 ?
|
||||||
<View style={[Styles.mb100]}>
|
<View style={[Styles.mb100]}>
|
||||||
@@ -163,7 +194,7 @@ export default function AddMemberProject() {
|
|||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={index}
|
key={index}
|
||||||
style={[Styles.itemSelectModal]}
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
!found && onChoose(item.id, item.name, item.img)
|
!found && onChoose(item.id, item.name, item.img)
|
||||||
}}
|
}}
|
||||||
@@ -173,12 +204,12 @@ export default function AddMemberProject() {
|
|||||||
<View style={[Styles.ml10]}>
|
<View style={[Styles.ml10]}>
|
||||||
<Text style={[Styles.textDefault]} numberOfLines={1}>{item.name}</Text>
|
<Text style={[Styles.textDefault]} numberOfLines={1}>{item.name}</Text>
|
||||||
{
|
{
|
||||||
found && <Text style={[Styles.textInformation, Styles.cGray]}>sudah menjadi anggota</Text>
|
found && <Text style={[Styles.textInformation, { color: colors.dimmed }]}>sudah menjadi anggota</Text>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={'black'} />
|
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={colors.text} />
|
||||||
}
|
}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
|
import ButtonSelect from "@/components/buttonSelect";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import ModalAddDetailTugasProject from "@/components/project/modalAddDetailTugasProject";
|
import ModalAddDetailTugasProject from "@/components/project/modalAddDetailTugasProject";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -9,6 +10,7 @@ import { formatDateOnly } from "@/lib/fun_formatDateOnly";
|
|||||||
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
||||||
import { setUpdateProject } from "@/lib/projectUpdate";
|
import { setUpdateProject } from "@/lib/projectUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import 'intl';
|
import 'intl';
|
||||||
@@ -18,7 +20,6 @@ import { useEffect, useState } from "react";
|
|||||||
import {
|
import {
|
||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
Platform,
|
Platform,
|
||||||
Pressable,
|
|
||||||
SafeAreaView,
|
SafeAreaView,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
View
|
View
|
||||||
@@ -30,6 +31,7 @@ import DateTimePicker, {
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function ProjectAddTask() {
|
export default function ProjectAddTask() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const headerHeight = useHeaderHeight();
|
const headerHeight = useHeaderHeight();
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
@@ -124,16 +126,18 @@ export default function ProjectAddTask() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -158,11 +162,11 @@ export default function ProjectAddTask() {
|
|||||||
showBack={true}
|
showBack={true}
|
||||||
onPressLeft={() => router.back()}
|
onPressLeft={() => router.back()}
|
||||||
right={
|
right={
|
||||||
<ButtonSaveHeader
|
<ButtonSaveHeader
|
||||||
disable={disable || loading}
|
disable={disable || loading}
|
||||||
category="create"
|
category="create"
|
||||||
onPress={() => { handleCreate() }}
|
onPress={() => { handleCreate() }}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -172,9 +176,9 @@ export default function ProjectAddTask() {
|
|||||||
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
||||||
keyboardVerticalOffset={headerHeight}
|
keyboardVerticalOffset={headerHeight}
|
||||||
>
|
>
|
||||||
<ScrollView>
|
<ScrollView style={[Styles.h100, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
<DateTimePicker
|
<DateTimePicker
|
||||||
mode="range"
|
mode="range"
|
||||||
startDate={range.startDate}
|
startDate={range.startDate}
|
||||||
@@ -184,52 +188,55 @@ export default function ProjectAddTask() {
|
|||||||
selected: Styles.selectedDate,
|
selected: Styles.selectedDate,
|
||||||
selected_label: Styles.cWhite,
|
selected_label: Styles.cWhite,
|
||||||
range_fill: Styles.selectRangeDate,
|
range_fill: Styles.selectRangeDate,
|
||||||
month_label: Styles.cBlack,
|
month_label: { color: colors.text },
|
||||||
month_selector_label: Styles.cBlack,
|
month_selector_label: { color: colors.text },
|
||||||
year_label: Styles.cBlack,
|
year_label: { color: colors.text },
|
||||||
year_selector_label: Styles.cBlack,
|
year_selector_label: { color: colors.text },
|
||||||
day_label: Styles.cBlack,
|
day_label: { color: colors.text },
|
||||||
time_label: Styles.cBlack,
|
time_label: { color: colors.text },
|
||||||
weekday_label: Styles.cBlack,
|
weekday_label: { color: colors.text },
|
||||||
|
button_next_image: { tintColor: colors.text },
|
||||||
|
button_prev_image: { tintColor: colors.text },
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={[Styles.mv10]}>
|
<View style={[Styles.mv10]}>
|
||||||
<View style={[Styles.rowSpaceBetween]}>
|
<View style={[Styles.rowSpaceBetween, Styles.mb10]}>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[Styles.w48]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Mulai <Text style={Styles.cError}>*</Text>
|
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{from}</Text>
|
<Text style={Styles.textCenter}>{from}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[Styles.w48]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
|
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{to}</Text>
|
<Text style={Styles.textCenter}>{to}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
(error.endDate || error.startDate) && <Text style={[Styles.textInformation, Styles.cError, Styles.mt05]}>Tanggal tidak boleh kosong</Text>
|
(error.endDate || error.startDate) && <Text style={[Styles.textInformation, { color: colors.error }, Styles.mt05]}>Tanggal tidak boleh kosong</Text>
|
||||||
}
|
}
|
||||||
<Pressable
|
{/* <Pressable
|
||||||
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
|
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
|
||||||
disabled={dsbButton}
|
disabled={dsbButton}
|
||||||
onPress={() => { setModalDetail(true) }}
|
onPress={() => { setModalDetail(true) }}
|
||||||
>
|
>
|
||||||
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
|
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
|
||||||
</Pressable>
|
</Pressable> */}
|
||||||
|
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} disabled={from == "" || to == ""} />
|
||||||
</View>
|
</View>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul Tugas"
|
label="Judul Tugas"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul Tugas"
|
placeholder="Judul Tugas"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={title}
|
value={title}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
errorText="Judul tidak boleh kosong"
|
errorText="Judul tidak boleh kosong"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiCancelProject } from "@/lib/api";
|
import { apiCancelProject } from "@/lib/api";
|
||||||
import { setUpdateProject } from "@/lib/projectUpdate";
|
import { setUpdateProject } from "@/lib/projectUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -12,6 +13,7 @@ import Toast from "react-native-toast-message";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function ProjectCancel() {
|
export default function ProjectCancel() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -56,16 +58,18 @@ export default function ProjectCancel() {
|
|||||||
Toast.show({ type: 'small', text1: 'Berhasil membatalkan kegiatan', })
|
Toast.show({ type: 'small', text1: 'Berhasil membatalkan kegiatan', })
|
||||||
router.back();
|
router.back();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal membatalkan kegiatan"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -106,7 +110,7 @@ export default function ProjectCancel() {
|
|||||||
/>
|
/>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<InputForm
|
<InputForm
|
||||||
@@ -114,7 +118,7 @@ export default function ProjectCancel() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Alasan Pembatalan"
|
placeholder="Alasan Pembatalan"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
error={error}
|
error={error}
|
||||||
errorText="Alasan pembatalan harus diisi"
|
errorText="Alasan pembatalan harus diisi"
|
||||||
onChange={(val) => onValidation(val)}
|
onChange={(val) => onValidation(val)}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiEditProject, apiGetProjectOne } from "@/lib/api";
|
import { apiEditProject, apiGetProjectOne } from "@/lib/api";
|
||||||
import { setUpdateProject } from "@/lib/projectUpdate";
|
import { setUpdateProject } from "@/lib/projectUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -12,6 +13,7 @@ import Toast from "react-native-toast-message";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function EditProject() {
|
export default function EditProject() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
@@ -75,9 +77,11 @@ export default function EditProject() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengubah data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -86,7 +90,7 @@ export default function EditProject() {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -121,14 +125,14 @@ export default function EditProject() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView>
|
<ScrollView style={[Styles.h100, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul Kegiatan"
|
label="Judul Kegiatan"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul Kegiatan"
|
placeholder="Judul Kegiatan"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={judul}
|
value={judul}
|
||||||
onChange={(val) => { onValidation(val) }}
|
onChange={(val) => { onValidation(val) }}
|
||||||
error={error}
|
error={error}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
|
import GuideOverlay from "@/components/GuideOverlay";
|
||||||
import HeaderRightProjectDetail from "@/components/project/headerProjectDetail";
|
import HeaderRightProjectDetail from "@/components/project/headerProjectDetail";
|
||||||
import SectionFile from "@/components/project/sectionFile";
|
import SectionFile from "@/components/project/sectionFile";
|
||||||
import SectionLink from "@/components/project/sectionLink";
|
import SectionLink from "@/components/project/sectionLink";
|
||||||
@@ -9,7 +10,10 @@ import SectionCancel from "@/components/sectionCancel";
|
|||||||
import SectionProgress from "@/components/sectionProgress";
|
import SectionProgress from "@/components/sectionProgress";
|
||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetProjectOne } from "@/lib/api";
|
import { apiGetProjectOne } from "@/lib/api";
|
||||||
|
import { GUIDE_PROJECT_DETAIL } from "@/lib/guideSteps";
|
||||||
|
import { useGuide } from "@/lib/useGuide";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
|
import { RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -32,14 +36,17 @@ type Props = {
|
|||||||
|
|
||||||
export default function DetailProject() {
|
export default function DetailProject() {
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const { colors } = useTheme();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const [data, setData] = useState<Props>()
|
const [data, setData] = useState<Props>()
|
||||||
const [progress, setProgress] = useState(0)
|
const [progress, setProgress] = useState(0)
|
||||||
|
const [taskStats, setTaskStats] = useState<{ done: number, total: number } | undefined>()
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const update = useSelector((state: any) => state.projectUpdate)
|
const update = useSelector((state: any) => state.projectUpdate)
|
||||||
const [isMember, setIsMember] = useState(false)
|
const [isMember, setIsMember] = useState(false)
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const [refreshing, setRefreshing] = useState(false)
|
const [refreshing, setRefreshing] = useState(false)
|
||||||
|
const { visible: guideVisible, dismiss: dismissGuide } = useGuide('project-detail')
|
||||||
|
|
||||||
async function handleLoad(cat: 'data' | 'progress') {
|
async function handleLoad(cat: 'data' | 'progress') {
|
||||||
try {
|
try {
|
||||||
@@ -58,6 +65,17 @@ export default function DetailProject() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleLoadTaskStats() {
|
||||||
|
try {
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
const response = await apiGetProjectOne({ user: hasil, cat: 'task', id: id })
|
||||||
|
const tasks: { status: number }[] = response.data
|
||||||
|
setTaskStats({ done: tasks.filter(t => t.status === 1).length, total: tasks.length })
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function checkMember() {
|
async function checkMember() {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
@@ -77,6 +95,10 @@ export default function DetailProject() {
|
|||||||
handleLoad('progress')
|
handleLoad('progress')
|
||||||
}, [update.progress])
|
}, [update.progress])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleLoadTaskStats()
|
||||||
|
}, [update.task])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
checkMember()
|
checkMember()
|
||||||
}, [])
|
}, [])
|
||||||
@@ -86,12 +108,13 @@ export default function DetailProject() {
|
|||||||
setRefreshing(true)
|
setRefreshing(true)
|
||||||
await handleLoad('data')
|
await handleLoad('data')
|
||||||
await handleLoad('progress')
|
await handleLoad('progress')
|
||||||
|
await handleLoadTaskStats()
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
setRefreshing(false)
|
setRefreshing(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
@@ -110,11 +133,14 @@ export default function DetailProject() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<GuideOverlay visible={guideVisible} steps={GUIDE_PROJECT_DETAIL} onDismiss={dismissGuide} />
|
||||||
<ScrollView
|
<ScrollView
|
||||||
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={refreshing}
|
refreshing={refreshing}
|
||||||
onRefresh={handleRefresh}
|
onRefresh={handleRefresh}
|
||||||
|
tintColor={colors.icon}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -122,9 +148,9 @@ export default function DetailProject() {
|
|||||||
{
|
{
|
||||||
data?.reason != null && data?.reason != "" && <SectionCancel text={data?.reason} />
|
data?.reason != null && data?.reason != "" && <SectionCancel text={data?.reason} />
|
||||||
}
|
}
|
||||||
<SectionProgress text={`Kemajuan Kegiatan ${progress}%`} progress={progress} />
|
<SectionProgress progress={progress} doneCount={taskStats?.done} totalCount={taskStats?.total} />
|
||||||
<SectionReportProject refreshing={refreshing} />
|
<SectionReportProject refreshing={refreshing} />
|
||||||
<SectionTanggalTugasProject status={data?.status} member={isMember} refreshing={refreshing} />
|
<SectionTanggalTugasProject status={data?.status} member={isMember} refreshing={refreshing} idGroup={data?.idGroup ?? ''} />
|
||||||
<SectionFile status={data?.status} member={isMember} refreshing={refreshing} />
|
<SectionFile status={data?.status} member={isMember} refreshing={refreshing} />
|
||||||
<SectionLink status={data?.status} member={isMember} refreshing={refreshing} />
|
<SectionLink status={data?.status} member={isMember} refreshing={refreshing} />
|
||||||
<SectionMember status={data?.status} refreshing={refreshing} />
|
<SectionMember status={data?.status} refreshing={refreshing} />
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiGetProjectOne, apiReportProject } from "@/lib/api";
|
import { apiGetProjectOne, apiReportProject } from "@/lib/api";
|
||||||
import { setUpdateProject } from "@/lib/projectUpdate";
|
import { setUpdateProject } from "@/lib/projectUpdate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
import { SafeAreaView, ScrollView, View } from "react-native";
|
||||||
@@ -12,6 +13,7 @@ import Toast from "react-native-toast-message";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function ReportProject() {
|
export default function ReportProject() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
@@ -75,9 +77,11 @@ export default function ReportProject() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal mengubah data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -86,7 +90,7 @@ export default function ReportProject() {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -123,7 +127,7 @@ export default function ReportProject() {
|
|||||||
/>
|
/>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<InputForm
|
<InputForm
|
||||||
@@ -131,7 +135,7 @@ export default function ReportProject() {
|
|||||||
type="default"
|
type="default"
|
||||||
placeholder="Laporan Kegiatan"
|
placeholder="Laporan Kegiatan"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={laporan}
|
value={laporan}
|
||||||
onChange={(val) => { onValidation(val) }}
|
onChange={(val) => { onValidation(val) }}
|
||||||
error={error}
|
error={error}
|
||||||
|
|||||||
377
app/(application)/project/[id]/tugas-file/[taskId].tsx
Normal file
@@ -0,0 +1,377 @@
|
|||||||
|
import AppHeader from "@/components/AppHeader";
|
||||||
|
import BorderBottomItem from "@/components/borderBottomItem";
|
||||||
|
import { ButtonForm } from "@/components/buttonForm";
|
||||||
|
import ButtonSelect from "@/components/buttonSelect";
|
||||||
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
|
import ModalConfirmation from "@/components/ModalConfirmation";
|
||||||
|
import ModalLoading from "@/components/modalLoading";
|
||||||
|
import Skeleton from "@/components/skeleton";
|
||||||
|
import Text from "@/components/Text";
|
||||||
|
import { ConstEnv } from "@/constants/ConstEnv";
|
||||||
|
import Styles from "@/constants/Styles";
|
||||||
|
import {
|
||||||
|
apiAddProjectTaskFile,
|
||||||
|
apiDeleteProjectTaskFile,
|
||||||
|
apiGetProjectOne,
|
||||||
|
apiGetProjectTaskFile,
|
||||||
|
apiLinkProjectTaskFile,
|
||||||
|
} from "@/lib/api";
|
||||||
|
import { setUpdateProject } from "@/lib/projectUpdate";
|
||||||
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
|
import * as FileSystem from "expo-file-system";
|
||||||
|
import { startActivityAsync } from "expo-intent-launcher";
|
||||||
|
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||||
|
import * as Sharing from "expo-sharing";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import {
|
||||||
|
ActivityIndicator,
|
||||||
|
Alert,
|
||||||
|
Platform,
|
||||||
|
SafeAreaView,
|
||||||
|
ScrollView,
|
||||||
|
View,
|
||||||
|
} from "react-native";
|
||||||
|
import * as mime from "react-native-mime-types";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
|
type FileItem = {
|
||||||
|
id: string; // ProjectTaskFile.id
|
||||||
|
idFile: string; // ProjectFile.id
|
||||||
|
name: string;
|
||||||
|
extension: string;
|
||||||
|
idStorage: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ProjectFile = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
extension: string;
|
||||||
|
idStorage: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ProjectTugasFileScreen() {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
const { id, taskId, member: memberParam } = useLocalSearchParams<{ id: string; taskId: string; member: string }>();
|
||||||
|
const { token, decryptToken } = useAuthSession();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const update = useSelector((state: any) => state.projectUpdate);
|
||||||
|
const entityUser = useSelector((state: any) => state.user);
|
||||||
|
const isMember = memberParam === "true";
|
||||||
|
const canEdit = isMember || (entityUser.role !== "user" && entityUser.role !== "coadmin");
|
||||||
|
|
||||||
|
const [data, setData] = useState<FileItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [loadingOpen, setLoadingOpen] = useState(false);
|
||||||
|
const [loadingUpload, setLoadingUpload] = useState(false);
|
||||||
|
const [loadingLink, setLoadingLink] = useState(false);
|
||||||
|
|
||||||
|
const [selectFile, setSelectFile] = useState<FileItem | null>(null);
|
||||||
|
const [isMenuModal, setMenuModal] = useState(false);
|
||||||
|
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||||
|
|
||||||
|
const [projectFiles, setProjectFiles] = useState<ProjectFile[]>([]);
|
||||||
|
const [isPickerModal, setPickerModal] = useState(false);
|
||||||
|
const [loadingProjectFiles, setLoadingProjectFiles] = useState(false);
|
||||||
|
const [selectedProjectFiles, setSelectedProjectFiles] = useState<string[]>([]);
|
||||||
|
|
||||||
|
const arrSkeleton = Array.from({ length: 4 });
|
||||||
|
|
||||||
|
async function loadFiles() {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
const response = await apiGetProjectTaskFile({ user: hasil, id: taskId });
|
||||||
|
setData(response.data ?? []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadProjectFiles() {
|
||||||
|
try {
|
||||||
|
setLoadingProjectFiles(true);
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
const response = await apiGetProjectOne({ user: hasil, cat: "file", id });
|
||||||
|
setProjectFiles(response.data ?? []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
setLoadingProjectFiles(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadFiles();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const openFile = () => {
|
||||||
|
setMenuModal(false);
|
||||||
|
setLoadingOpen(true);
|
||||||
|
const remoteUrl = ConstEnv.url_storage + "/files/" + selectFile?.idStorage;
|
||||||
|
const fileName = selectFile?.name + "." + selectFile?.extension;
|
||||||
|
const localPath = `${FileSystem.documentDirectory}/${fileName}`;
|
||||||
|
const mimeType = mime.lookup(fileName);
|
||||||
|
|
||||||
|
FileSystem.downloadAsync(remoteUrl, localPath).then(async ({ uri }) => {
|
||||||
|
const contentURL = await FileSystem.getContentUriAsync(uri);
|
||||||
|
try {
|
||||||
|
if (Platform.OS === "android") {
|
||||||
|
await startActivityAsync("android.intent.action.VIEW", {
|
||||||
|
data: contentURL,
|
||||||
|
flags: 1,
|
||||||
|
type: mimeType as string,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Sharing.shareAsync(localPath);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Alert.alert("INFO", "Gagal membuka file, tidak ada aplikasi yang dapat membuka file ini");
|
||||||
|
} finally {
|
||||||
|
setLoadingOpen(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
async function handleDelete() {
|
||||||
|
try {
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
const response = await apiDeleteProjectTaskFile({ user: hasil }, String(selectFile?.id));
|
||||||
|
if (response.success) {
|
||||||
|
Toast.show({ type: "small", text1: "Berhasil menghapus file" });
|
||||||
|
dispatch(setUpdateProject({ ...update, task: !update.task }));
|
||||||
|
loadFiles();
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: "small", text1: response.message });
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
const message = error?.response?.data?.message || "Gagal menghapus file";
|
||||||
|
Toast.show({ type: "small", text1: message });
|
||||||
|
} finally {
|
||||||
|
setMenuModal(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleUpload() {
|
||||||
|
const result = await DocumentPicker.getDocumentAsync({ type: ["*/*"], multiple: true });
|
||||||
|
if (result.canceled) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
setLoadingUpload(true);
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
const fd = new FormData();
|
||||||
|
|
||||||
|
for (let i = 0; i < result.assets.length; i++) {
|
||||||
|
fd.append(`file${i}`, {
|
||||||
|
uri: result.assets[i].uri,
|
||||||
|
type: "application/octet-stream",
|
||||||
|
name: result.assets[i].name,
|
||||||
|
} as any);
|
||||||
|
}
|
||||||
|
fd.append("data", JSON.stringify({ user: hasil }));
|
||||||
|
|
||||||
|
const response = await apiAddProjectTaskFile({ data: fd, id: taskId });
|
||||||
|
if (response.success) {
|
||||||
|
Toast.show({ type: "small", text1: "Berhasil menambahkan file" });
|
||||||
|
dispatch(setUpdateProject({ ...update, task: !update.task }));
|
||||||
|
loadFiles();
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: "small", text1: response.message });
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
const message = error?.response?.data?.message || "Gagal menambahkan file";
|
||||||
|
Toast.show({ type: "small", text1: message });
|
||||||
|
} finally {
|
||||||
|
setLoadingUpload(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleProjectFileSelect(fileId: string) {
|
||||||
|
setSelectedProjectFiles((prev) =>
|
||||||
|
prev.includes(fileId) ? prev.filter((v) => v !== fileId) : [...prev, fileId]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleLinkFiles() {
|
||||||
|
if (selectedProjectFiles.length === 0) return;
|
||||||
|
try {
|
||||||
|
setLoadingLink(true);
|
||||||
|
const hasil = await decryptToken(String(token?.current));
|
||||||
|
for (const idFile of selectedProjectFiles) {
|
||||||
|
await apiLinkProjectTaskFile({ user: hasil, idFile, id: taskId });
|
||||||
|
}
|
||||||
|
Toast.show({ type: "small", text1: "Berhasil menambahkan file" });
|
||||||
|
dispatch(setUpdateProject({ ...update, task: !update.task }));
|
||||||
|
setPickerModal(false);
|
||||||
|
setSelectedProjectFiles([]);
|
||||||
|
loadFiles();
|
||||||
|
} catch (error: any) {
|
||||||
|
const message = error?.response?.data?.message || "Gagal menambahkan file";
|
||||||
|
Toast.show({ type: "small", text1: message });
|
||||||
|
} finally {
|
||||||
|
setLoadingLink(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const attachedFileIds = new Set(data.map((f) => f.idFile));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
header: () => (
|
||||||
|
<AppHeader
|
||||||
|
title="File Tugas"
|
||||||
|
showBack={true}
|
||||||
|
onPressLeft={() => router.back()}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<ModalLoading isVisible={loadingOpen} setVisible={setLoadingOpen} />
|
||||||
|
|
||||||
|
<ScrollView>
|
||||||
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
|
{canEdit && (
|
||||||
|
<>
|
||||||
|
<ButtonSelect
|
||||||
|
value="Upload dari Perangkat"
|
||||||
|
onPress={handleUpload}
|
||||||
|
disabled={loadingUpload}
|
||||||
|
/>
|
||||||
|
<ButtonSelect
|
||||||
|
value="Pilih dari File Kegiatan ini"
|
||||||
|
onPress={() => {
|
||||||
|
setSelectedProjectFiles([]);
|
||||||
|
setPickerModal(true);
|
||||||
|
loadProjectFiles();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loadingUpload && <ActivityIndicator size="small" style={Styles.mv05} />}
|
||||||
|
|
||||||
|
<View style={[Styles.mb15, Styles.mt10]}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>File Terlampir</Text>
|
||||||
|
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
|
{loading ? (
|
||||||
|
arrSkeleton.map((_, index) => (
|
||||||
|
<Skeleton key={index} width={100} height={40} widthType="percent" borderRadius={10} />
|
||||||
|
))
|
||||||
|
) : data.length > 0 ? (
|
||||||
|
data.map((item, index) => (
|
||||||
|
<BorderBottomItem
|
||||||
|
key={index}
|
||||||
|
borderType="all"
|
||||||
|
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
|
||||||
|
title={item.name + "." + item.extension}
|
||||||
|
titleWeight="normal"
|
||||||
|
onPress={() => {
|
||||||
|
setSelectFile(item);
|
||||||
|
setMenuModal(true);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<Text style={[Styles.textDefault, { textAlign: "center", color: colors.dimmed }]}>
|
||||||
|
Tidak ada file
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
{/* Menu per file */}
|
||||||
|
<DrawerBottom animation="slide" isVisible={isMenuModal} setVisible={setMenuModal} title="Menu">
|
||||||
|
<View style={Styles.rowItemsCenter}>
|
||||||
|
<MenuItemRow
|
||||||
|
icon={<MaterialCommunityIcons name="file-eye" color={colors.text} size={25} />}
|
||||||
|
title="Lihat / Share"
|
||||||
|
onPress={openFile}
|
||||||
|
/>
|
||||||
|
{canEdit && (
|
||||||
|
<MenuItemRow
|
||||||
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
|
title="Hapus"
|
||||||
|
onPress={() => {
|
||||||
|
setMenuModal(false);
|
||||||
|
setTimeout(() => setShowDeleteModal(true), 600);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</DrawerBottom>
|
||||||
|
|
||||||
|
<ModalConfirmation
|
||||||
|
visible={showDeleteModal}
|
||||||
|
title="Konfirmasi"
|
||||||
|
message="Apakah Anda yakin ingin menghapus file ini?"
|
||||||
|
onConfirm={() => {
|
||||||
|
setShowDeleteModal(false);
|
||||||
|
handleDelete();
|
||||||
|
}}
|
||||||
|
onCancel={() => setShowDeleteModal(false)}
|
||||||
|
confirmText="Hapus"
|
||||||
|
cancelText="Batal"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Picker file dari proyek */}
|
||||||
|
<DrawerBottom
|
||||||
|
animation="slide"
|
||||||
|
isVisible={isPickerModal}
|
||||||
|
setVisible={setPickerModal}
|
||||||
|
title="Pilih File Proyek"
|
||||||
|
height={60}
|
||||||
|
>
|
||||||
|
<ScrollView>
|
||||||
|
{loadingProjectFiles ? (
|
||||||
|
<ActivityIndicator size="small" />
|
||||||
|
) : projectFiles.length > 0 ? (
|
||||||
|
projectFiles.map((item, index) => {
|
||||||
|
const isAttached = attachedFileIds.has(item.id);
|
||||||
|
const isSelected = selectedProjectFiles.includes(item.id);
|
||||||
|
return (
|
||||||
|
<View key={index} style={isAttached ? { opacity: 0.4 } : undefined}>
|
||||||
|
<BorderBottomItem
|
||||||
|
borderType="bottom"
|
||||||
|
icon={
|
||||||
|
isAttached || isSelected ? (
|
||||||
|
<Ionicons name="checkmark-circle" size={25} color={colors.primary} />
|
||||||
|
) : (
|
||||||
|
<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
title={item.name + "." + item.extension}
|
||||||
|
titleWeight="normal"
|
||||||
|
onPress={() => !isAttached && toggleProjectFileSelect(item.id)}
|
||||||
|
bgColor="transparent"
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<Text style={[Styles.textDefault, { textAlign: "center", color: colors.dimmed }]}>
|
||||||
|
Tidak ada file tersedia
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</ScrollView>
|
||||||
|
{projectFiles.length > 0 && (
|
||||||
|
<View>
|
||||||
|
<ButtonForm
|
||||||
|
text={loadingLink ? "Menyimpan..." : `Tambahkan (${selectedProjectFiles.length})`}
|
||||||
|
disabled={selectedProjectFiles.length === 0 || loadingLink}
|
||||||
|
onPress={handleLinkFiles} />
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</DrawerBottom>
|
||||||
|
</SafeAreaView>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import ButtonSelect from "@/components/buttonSelect";
|
|
||||||
import DrawerBottom from "@/components/drawerBottom";
|
import DrawerBottom from "@/components/drawerBottom";
|
||||||
import ImageUser from "@/components/imageNew";
|
import ImageUser from "@/components/imageNew";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
|
import LoadingCenter from "@/components/loadingCenter";
|
||||||
import MenuItemRow from "@/components/menuItemRow";
|
import MenuItemRow from "@/components/menuItemRow";
|
||||||
import ModalSelect from "@/components/modalSelect";
|
import ModalSelect from "@/components/modalSelect";
|
||||||
import SectionListAddTask from "@/components/project/sectionListAddTask";
|
import SectionListAddTask from "@/components/project/sectionListAddTask";
|
||||||
@@ -18,11 +17,13 @@ import { setMemberChoose } from "@/lib/memberChoose";
|
|||||||
import { setUpdateProject } from "@/lib/projectUpdate";
|
import { setUpdateProject } from "@/lib/projectUpdate";
|
||||||
import { setTaskCreate } from "@/lib/taskCreate";
|
import { setTaskCreate } from "@/lib/taskCreate";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||||
import * as DocumentPicker from "expo-document-picker";
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
|
Pressable,
|
||||||
SafeAreaView,
|
SafeAreaView,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
View
|
View
|
||||||
@@ -30,7 +31,28 @@ import {
|
|||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
|
function getFileIcon(ext: string): keyof typeof MaterialCommunityIcons.glyphMap {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return 'image-outline'
|
||||||
|
if (ext === 'pdf') return 'file-pdf-box'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return 'video-outline'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return 'file-word-outline'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return 'file-excel-outline'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return 'zip-box-outline'
|
||||||
|
return 'file-outline'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileColor(ext: string): string {
|
||||||
|
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return '#339AF0'
|
||||||
|
if (ext === 'pdf') return '#F03E3E'
|
||||||
|
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return '#AE3EC9'
|
||||||
|
if (['doc', 'docx'].includes(ext)) return '#1C7ED6'
|
||||||
|
if (['xls', 'xlsx'].includes(ext)) return '#2F9E44'
|
||||||
|
if (['zip', 'rar', '7z'].includes(ext)) return '#E8590C'
|
||||||
|
return '#868E96'
|
||||||
|
}
|
||||||
|
|
||||||
export default function CreateProject() {
|
export default function CreateProject() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const { token, decryptToken } = useAuthSession();
|
const { token, decryptToken } = useAuthSession();
|
||||||
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" });
|
const [chooseGroup, setChooseGroup] = useState({ val: "", label: "" });
|
||||||
@@ -148,9 +170,11 @@ export default function CreateProject() {
|
|||||||
} else {
|
} else {
|
||||||
Toast.show({ type: 'small', text1: response.message, })
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error : any ) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
|
const message = error?.response?.data?.message || "Gagal menambahkan data"
|
||||||
|
|
||||||
|
Toast.show({ type: 'small', text1: message })
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -190,7 +214,7 @@ export default function CreateProject() {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -228,123 +252,194 @@ export default function CreateProject() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{
|
||||||
|
loading && <LoadingCenter />
|
||||||
|
}
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
style={[Styles.h100]}
|
style={[Styles.h100, { backgroundColor: colors.background }]}
|
||||||
>
|
>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
{
|
{(entityUser.role == "supadmin" || entityUser.role == "developer") && (
|
||||||
(entityUser.role == "supadmin" || entityUser.role == "developer")
|
<SelectForm
|
||||||
&&
|
label="Lembaga Desa"
|
||||||
(
|
placeholder="Pilih Lembaga Desa"
|
||||||
<SelectForm
|
value={chooseGroup.label}
|
||||||
label="Lembaga Desa"
|
required
|
||||||
placeholder="Pilih Lembaga Desa"
|
bg={colors.card}
|
||||||
value={chooseGroup.label}
|
onPress={() => {
|
||||||
required
|
setValChoose(chooseGroup.val);
|
||||||
onPress={() => {
|
setValSelect("group");
|
||||||
setValChoose(chooseGroup.val);
|
setSelect(true);
|
||||||
setValSelect("group");
|
}}
|
||||||
setSelect(true);
|
error={error.group}
|
||||||
}}
|
errorText="Lembaga Desa tidak boleh kosong"
|
||||||
error={error.group}
|
/>
|
||||||
errorText="Lembaga Desa tidak boleh kosong"
|
)}
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Kegiatan"
|
label="Kegiatan"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Nama Kegiatan"
|
placeholder="Nama Kegiatan"
|
||||||
required
|
required
|
||||||
|
bg={colors.card}
|
||||||
value={dataForm.title}
|
value={dataForm.title}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
errorText="Nama kegiatan tidak boleh kosong"
|
errorText="Nama kegiatan tidak boleh kosong"
|
||||||
onChange={(val) => {
|
onChange={(val) => validationForm("title", val)}
|
||||||
validationForm("title", val);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<ButtonSelect
|
|
||||||
value="Tambah Tanggal & Tugas"
|
|
||||||
onPress={() => {
|
|
||||||
router.push(`/project/create/task`);
|
|
||||||
}}
|
|
||||||
error={error.task}
|
|
||||||
errorText="Tanggal & Tugas tidak boleh kosong"
|
|
||||||
/>
|
|
||||||
<ButtonSelect value="Upload File" onPress={pickDocumentAsync} />
|
|
||||||
<ButtonSelect
|
|
||||||
value="Pilih Anggota"
|
|
||||||
onPress={() => {
|
|
||||||
if (entityUser.role == "supadmin" || entityUser.role == "developer") {
|
|
||||||
if (chooseGroup.val != "") {
|
|
||||||
router.push(`/project/create/member`);
|
|
||||||
} else {
|
|
||||||
Toast.show({ type: 'small', text1: "Pilih Lembaga Desa terlebih dahulu", })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
router.push(`/project/create/member`);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
error={error.member}
|
|
||||||
errorText="Anggota tidak boleh kosong"
|
|
||||||
/>
|
|
||||||
<SectionListAddTask />
|
|
||||||
{
|
|
||||||
fileForm.length > 0 && (
|
|
||||||
<View style={[Styles.mb15]}>
|
|
||||||
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>File</Text>
|
|
||||||
<View style={[Styles.wrapPaper]}>
|
|
||||||
{
|
|
||||||
fileForm.map((item, index) => (
|
|
||||||
<BorderBottomItem
|
|
||||||
key={index}
|
|
||||||
borderType="all"
|
|
||||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
|
|
||||||
title={item.name}
|
|
||||||
titleWeight="normal"
|
|
||||||
onPress={() => { setIndexDelFile(index); setModal(true) }}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{entitiesMember.length > 0 && (
|
|
||||||
<View>
|
|
||||||
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
|
|
||||||
<Text>Anggota</Text>
|
|
||||||
<Text>Total {entitiesMember.length} Anggota</Text>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={[Styles.borderAll, Styles.round10, Styles.p10]}>
|
{/* Tanggal & Tugas */}
|
||||||
{entitiesMember.map(
|
<View style={[
|
||||||
(item: { img: any; name: any }, index: any) => {
|
Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
return (
|
{ backgroundColor: colors.card, borderColor: error.task ? colors.error + '50' : colors.icon + '18' }
|
||||||
<BorderBottomItem
|
]}>
|
||||||
key={index}
|
<Pressable
|
||||||
borderType="bottom"
|
onPress={() => router.push(`/project/create/task`)}
|
||||||
icon={
|
style={[Styles.sectionActionRow, { marginBottom: taskCreate.length > 0 ? 12 : 0 }]}
|
||||||
<ImageUser
|
>
|
||||||
src={`${ConstEnv.url_storage}/files/${item.img}`}
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
size="sm"
|
<MaterialCommunityIcons name="calendar-check-outline" size={18} color={colors.tabActive} />
|
||||||
/>
|
</View>
|
||||||
}
|
<View style={Styles.flex1}>
|
||||||
title={item.name}
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Tanggal & Tugas</Text>
|
||||||
/>
|
{taskCreate.length === 0 && (
|
||||||
);
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Belum ada tugas ditambahkan</Text>
|
||||||
}
|
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
{taskCreate.length > 0 && (
|
||||||
)}
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.tabActive }]}>{taskCreate.length} tugas</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{taskCreate.length > 0 && <SectionListAddTask showTitle={false} />}
|
||||||
|
{error.task && (
|
||||||
|
<Text style={[Styles.textMediumNormal, Styles.mt05, { color: colors.error }]}>
|
||||||
|
Tanggal & Tugas tidak boleh kosong
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* File */}
|
||||||
|
<View style={[
|
||||||
|
Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
|
{ backgroundColor: colors.card, borderColor: colors.icon + '18' }
|
||||||
|
]}>
|
||||||
|
<Pressable
|
||||||
|
onPress={pickDocumentAsync}
|
||||||
|
style={[Styles.sectionActionRow, { marginBottom: fileForm.length > 0 ? 12 : 0 }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.icon + '15' }]}>
|
||||||
|
<MaterialCommunityIcons name="paperclip" size={18} color={colors.dimmed} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>File</Text>
|
||||||
|
{fileForm.length === 0 && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Opsional — ketuk untuk upload</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{fileForm.length > 0 && (
|
||||||
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.dimmed + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{fileForm.length} file</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{fileForm.length > 0 && (
|
||||||
|
<View style={Styles.fileGrid}>
|
||||||
|
{fileForm.map((item, index) => {
|
||||||
|
const ext = item.name.split('.').pop()?.toLowerCase() ?? ''
|
||||||
|
const baseName = item.name.includes('.') ? item.name.split('.').slice(0, -1).join('.') : item.name
|
||||||
|
const iconName = getFileIcon(ext)
|
||||||
|
const iconColor = getFileColor(ext)
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
key={index}
|
||||||
|
onPress={() => { setIndexDelFile(index); setModal(true) }}
|
||||||
|
style={[Styles.fileCard, { backgroundColor: 'transparent', borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||||
|
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={Styles.textDefault} numberOfLines={1}>{baseName}</Text>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>{ext.toUpperCase()}</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* Anggota */}
|
||||||
|
<View style={[
|
||||||
|
Styles.wrapPaper, Styles.mb15, Styles.sectionCard,
|
||||||
|
{ backgroundColor: colors.card, borderColor: error.member ? colors.error + '50' : colors.icon + '18' }
|
||||||
|
]}>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => {
|
||||||
|
if (entityUser.role == "supadmin" || entityUser.role == "developer") {
|
||||||
|
if (chooseGroup.val != "") {
|
||||||
|
router.push(`/project/create/member`);
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: 'small', text1: "Pilih Lembaga Desa terlebih dahulu" })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
router.push(`/project/create/member`);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
style={[Styles.sectionActionRow, { marginBottom: entitiesMember.length > 0 ? 12 : 0 }]}
|
||||||
|
>
|
||||||
|
<View style={[Styles.sectionIconBox, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<MaterialCommunityIcons name="account-group-outline" size={18} color={colors.tabActive} />
|
||||||
|
</View>
|
||||||
|
<View style={Styles.flex1}>
|
||||||
|
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Anggota</Text>
|
||||||
|
{entitiesMember.length === 0 && (
|
||||||
|
<Text style={[Styles.textMediumNormal, { color: colors.dimmed }]}>Belum ada anggota dipilih</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
{entitiesMember.length > 0 && (
|
||||||
|
<View style={[Styles.sectionBadge, { backgroundColor: colors.tabActive + '18' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.tabActive }]}>{entitiesMember.length} orang</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<MaterialCommunityIcons name="chevron-right" size={18} color={colors.dimmed} />
|
||||||
|
</Pressable>
|
||||||
|
{entitiesMember.length > 0 && (
|
||||||
|
<View style={{ gap: 6 }}>
|
||||||
|
{entitiesMember.map((item: { img: any; name: any; position?: string }, index: any) => (
|
||||||
|
<View
|
||||||
|
key={index}
|
||||||
|
style={[Styles.listItemCard, { borderColor: colors.icon + '18' }]}
|
||||||
|
>
|
||||||
|
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
|
||||||
|
<Text style={[Styles.textDefault, Styles.flex1, { color: colors.text }]} numberOfLines={1}>{item.name}</Text>
|
||||||
|
{item.position && (
|
||||||
|
<View style={[Styles.positionBadge, { backgroundColor: colors.dimmed + '15' }]}>
|
||||||
|
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]} numberOfLines={1}>{item.position}</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
{error.member && (
|
||||||
|
<Text style={[Styles.textMediumNormal, Styles.mt05, { color: colors.error }]}>
|
||||||
|
Anggota tidak boleh kosong
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<Ionicons name="trash" color="black" size={25} />}
|
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||||
title="Hapus"
|
title="Hapus"
|
||||||
onPress={() => { deleteFile(indexDelFile) }}
|
onPress={() => { deleteFile(indexDelFile) }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { apiGetUser } from "@/lib/api";
|
import { apiGetUser } from "@/lib/api";
|
||||||
import { setMemberChoose } from "@/lib/memberChoose";
|
import { setMemberChoose } from "@/lib/memberChoose";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
import { AntDesign } from "@expo/vector-icons";
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
@@ -23,6 +24,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AddMemberCreateProject() {
|
export default function AddMemberCreateProject() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession()
|
||||||
const [data, setData] = useState<Props[]>([])
|
const [data, setData] = useState<Props[]>([])
|
||||||
@@ -59,6 +61,21 @@ export default function AddMemberCreateProject() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isAllSelected = data.length > 0 && data.every((item: any) =>
|
||||||
|
selectMember.some((s: any) => s.idUser == item.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
function handleSelectAll() {
|
||||||
|
if (isAllSelected) {
|
||||||
|
setSelectMember([])
|
||||||
|
} else {
|
||||||
|
const newMembers = data
|
||||||
|
.filter((item: any) => !selectMember.some((s: any) => s.idUser == item.id))
|
||||||
|
.map((item: any) => ({ idUser: item.id, name: item.name, img: item.img }))
|
||||||
|
setSelectMember([...selectMember, ...newMembers])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleAddMember() {
|
async function handleAddMember() {
|
||||||
try {
|
try {
|
||||||
dispatch(setMemberChoose(selectMember))
|
dispatch(setMemberChoose(selectMember))
|
||||||
@@ -103,7 +120,7 @@ export default function AddMemberCreateProject() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15, { flex: 1 }]}>
|
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<InputSearch onChange={(val) => setSearch(val)} value={search} />
|
<InputSearch onChange={(val) => setSearch(val)} value={search} />
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -125,19 +142,29 @@ export default function AddMemberCreateProject() {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.pv05, { textAlign: 'center' }]}>Tidak ada member yang dipilih</Text>
|
<Text style={[Styles.textDefault, Styles.textCenter, { color: colors.dimmed }, Styles.pv05]}>Tidak ada member yang dipilih</Text>
|
||||||
}
|
}
|
||||||
<ScrollView
|
<ScrollView
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
|
style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
{data.length > 0 && (
|
||||||
|
<Pressable
|
||||||
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20', paddingTop: 0 }]}
|
||||||
|
onPress={handleSelectAll}
|
||||||
|
>
|
||||||
|
<Text style={[Styles.textMediumSemiBold]}>{isAllSelected ? 'Batalkan Semua' : 'Pilih Semua'}</Text>
|
||||||
|
{isAllSelected && <AntDesign name="check" size={20} color={colors.text} />}
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
{
|
{
|
||||||
data.length > 0 ?
|
data.length > 0 ?
|
||||||
data.map((item: any, index: any) => {
|
data.map((item: any, index: any) => {
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={index}
|
key={index}
|
||||||
style={[Styles.itemSelectModal]}
|
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
onChoose(item.id, item.name, item.img)
|
onChoose(item.id, item.name, item.img)
|
||||||
}}
|
}}
|
||||||
@@ -149,14 +176,14 @@ export default function AddMemberCreateProject() {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={'black'} />
|
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={colors.text} />
|
||||||
}
|
}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
<Text style={[Styles.textDefault, { textAlign: 'center' }]}>Tidak ada data</Text>
|
<Text style={[Styles.textDefault, Styles.textCenter]}>Tidak ada data</Text>
|
||||||
}
|
}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import AppHeader from "@/components/AppHeader";
|
import AppHeader from "@/components/AppHeader";
|
||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
|
import ButtonSelect from "@/components/buttonSelect";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import ModalAddDetailTugasProject from "@/components/project/modalAddDetailTugasProject";
|
import ModalAddDetailTugasProject from "@/components/project/modalAddDetailTugasProject";
|
||||||
import Text from "@/components/Text";
|
import Text from "@/components/Text";
|
||||||
@@ -7,6 +8,7 @@ import Styles from "@/constants/Styles";
|
|||||||
import { formatDateOnly } from "@/lib/fun_formatDateOnly";
|
import { formatDateOnly } from "@/lib/fun_formatDateOnly";
|
||||||
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
|
||||||
import { setTaskCreate } from "@/lib/taskCreate";
|
import { setTaskCreate } from "@/lib/taskCreate";
|
||||||
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { useHeaderHeight } from '@react-navigation/elements';
|
import { useHeaderHeight } from '@react-navigation/elements';
|
||||||
import { router, Stack } from "expo-router";
|
import { router, Stack } from "expo-router";
|
||||||
import 'intl';
|
import 'intl';
|
||||||
@@ -16,7 +18,6 @@ import React, { useEffect, useState } from "react";
|
|||||||
import {
|
import {
|
||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
Platform,
|
Platform,
|
||||||
Pressable,
|
|
||||||
SafeAreaView,
|
SafeAreaView,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
View
|
View
|
||||||
@@ -27,6 +28,7 @@ import DateTimePicker, {
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function CreateProjectAddTask() {
|
export default function CreateProjectAddTask() {
|
||||||
|
const { colors } = useTheme();
|
||||||
const headerHeight = useHeaderHeight();
|
const headerHeight = useHeaderHeight();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const [disable, setDisable] = useState(true);
|
const [disable, setDisable] = useState(true);
|
||||||
@@ -119,7 +121,7 @@ export default function CreateProjectAddTask() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
// headerLeft: () => (
|
// headerLeft: () => (
|
||||||
@@ -158,9 +160,9 @@ export default function CreateProjectAddTask() {
|
|||||||
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
|
||||||
keyboardVerticalOffset={headerHeight}
|
keyboardVerticalOffset={headerHeight}
|
||||||
>
|
>
|
||||||
<ScrollView>
|
<ScrollView style={[Styles.h100, { backgroundColor: colors.background }]}>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||||
<DateTimePicker
|
<DateTimePicker
|
||||||
mode="range"
|
mode="range"
|
||||||
startDate={range.startDate}
|
startDate={range.startDate}
|
||||||
@@ -170,52 +172,48 @@ export default function CreateProjectAddTask() {
|
|||||||
selected: Styles.selectedDate,
|
selected: Styles.selectedDate,
|
||||||
selected_label: Styles.cWhite,
|
selected_label: Styles.cWhite,
|
||||||
range_fill: Styles.selectRangeDate,
|
range_fill: Styles.selectRangeDate,
|
||||||
month_label: Styles.cBlack,
|
month_label: { color: colors.text },
|
||||||
month_selector_label: Styles.cBlack,
|
month_selector_label: { color: colors.text },
|
||||||
year_label: Styles.cBlack,
|
year_label: { color: colors.text },
|
||||||
year_selector_label: Styles.cBlack,
|
year_selector_label: { color: colors.text },
|
||||||
day_label: Styles.cBlack,
|
day_label: { color: colors.text },
|
||||||
time_label: Styles.cBlack,
|
time_label: { color: colors.text },
|
||||||
weekday_label: Styles.cBlack,
|
weekday_label: { color: colors.text },
|
||||||
|
button_next_image: { tintColor: colors.text },
|
||||||
|
button_prev_image: { tintColor: colors.text },
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={[Styles.mv10]}>
|
<View style={[Styles.mv10]}>
|
||||||
<View style={[Styles.rowSpaceBetween]}>
|
<View style={[Styles.rowSpaceBetween, Styles.mb10]}>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[{ width: "48%" }]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Mulai <Text style={Styles.cError}>*</Text>
|
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{from}</Text>
|
<Text style={Styles.textCenter}>{from}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={[{ width: "48%" }]}>
|
<View style={[{ width: "48%" }]}>
|
||||||
<Text style={[Styles.mb05]}>
|
<Text style={[Styles.mb05]}>
|
||||||
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
|
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
|
||||||
</Text>
|
</Text>
|
||||||
<View style={[Styles.wrapPaper, Styles.p10]}>
|
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
|
||||||
<Text style={{ textAlign: "center" }}>{to}</Text>
|
<Text style={Styles.textCenter}>{to}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{
|
{
|
||||||
(error.endDate || error.startDate) && <Text style={[Styles.textInformation, Styles.cError, Styles.mt05]}>Tanggal tidak boleh kosong</Text>
|
(error.endDate || error.startDate) && <Text style={[Styles.textInformation, Styles.mt05, { color: colors.error }]}>Tanggal tidak boleh kosong</Text>
|
||||||
}
|
}
|
||||||
<Pressable
|
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} disabled={from == "" || to == ""} />
|
||||||
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
|
|
||||||
disabled={dsbButton}
|
|
||||||
onPress={() => { setModalDetail(true) }}
|
|
||||||
>
|
|
||||||
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
</View>
|
||||||
<InputForm
|
<InputForm
|
||||||
label="Judul Tugas"
|
label="Judul Tugas"
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Judul Tugas"
|
placeholder="Judul Tugas"
|
||||||
required
|
required
|
||||||
bg="white"
|
bg={colors.card}
|
||||||
value={title}
|
value={title}
|
||||||
error={error.title}
|
error={error.title}
|
||||||
errorText="Judul tidak boleh kosong"
|
errorText="Judul tidak boleh kosong"
|
||||||
|
|||||||