Compare commits

...

59 Commits

Author SHA1 Message Date
6021d17b5a feat: tambah error logger ke monitoring dashboard dengan offline queue
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 15:25:10 +08:00
b7165c5990 hapus komen 2026-04-20 17:45:19 +08:00
7dc51bd2b9 fix: variable yg tidak terpakai 2026-04-20 17:12:41 +08:00
de5ad545a7 upd: hapus console.log 2026-04-20 17:07:49 +08:00
47cb146c5a upd: claude 2026-04-20 17:05:40 +08:00
8b8ea61a13 fix: grafik bar 2026-04-20 16:27:44 +08:00
5dac451754 fix: grafik jumlah dokumen 2026-04-20 14:37:36 +08:00
ccf8ee1caf upd: caching data
Deskripsi:
- update caching pada fitur utama -yg fitur divisi belom
2026-04-20 14:23:14 +08:00
772551a917 upd: page kosong atau data udah di hapus pada pengumuman 2026-04-17 16:46:49 +08:00
555b9e4037 upd: fix laopran grafik divisi 2026-04-17 15:26:06 +08:00
d4b4db4251 upd: fix: jumlah dokumen grafik pada home 2026-04-17 15:01:14 +08:00
17d92cba25 Merge pull request 'amalia/10-mar-26' (#36) from amalia/10-mar-26 into join
Reviewed-on: #36
2026-03-10 16:30:52 +08:00
e1b62be6da upd:build number 2026-03-10 15:31:57 +08:00
b2b125c410 upd: build eas 2026-03-10 15:19:40 +08:00
1cfecbbdd5 upd : border di android 2026-03-10 11:09:19 +08:00
21006e8eee upd: gambar caraousel 2026-03-10 11:02:26 +08:00
91231d60e4 upd: md 2026-03-09 16:43:04 +08:00
7174e27be1 upd: version dan prebuild 2026-03-09 14:17:36 +08:00
9d4b931aa6 Merge pull request 'amalia/05-mar-26' (#35) from amalia/05-mar-26 into join
Reviewed-on: #35
2026-03-05 16:19:03 +08:00
166d8f1c16 upd: notifikasi
Deskripsi:
- update notifikasi android

No Issues
2026-03-05 14:38:45 +08:00
7060a2d165 upd: otp
Deskripsi:
- link otp baru

NOIssues
2026-03-05 14:15:36 +08:00
d6217aecf1 Merge pull request 'upd: notifikasi' (#34) from amalia/04-mar-26 into join
Reviewed-on: #34
2026-03-04 16:39:05 +08:00
608381673f upd: notifikasi
Deskripsi:
- notifikasi saat allowed device
- ios dan android

No Issues
2026-03-04 16:35:59 +08:00
3cc7f76346 Merge pull request 'amalia/03-mar-26' (#33) from amalia/03-mar-26 into join
Reviewed-on: #33
2026-03-03 16:46:19 +08:00
868b712fbb upd: notifikasi
Deskripsi:
- belom selesai notifikasi

No Issues
2026-03-03 16:44:02 +08:00
a53b99b39d version 2026-03-03 10:57:55 +08:00
25d521f013 Merge pull request 'amalia/26-feb-26' (#32) from amalia/26-feb-26 into join
Reviewed-on: #32
2026-02-26 17:48:06 +08:00
aee0823cb1 upd: fiksasi 2026-02-26 17:42:33 +08:00
2a0e1f4c1f upd: bun lock 2026-02-26 14:54:51 +08:00
ef08c821fa Merge pull request 'upd: fiksasi' (#30) from amalia/25-feb-26 into join
Reviewed-on: #30
2026-02-25 16:09:31 +08:00
fd5d582092 upd: fiksasi
Deskripsi:
-tampilan

No Issues
2026-02-25 16:07:17 +08:00
7729dc38f8 Merge pull request 'amalia/24-feb-26' (#29) from amalia/24-feb-26 into join
Reviewed-on: #29
2026-02-24 18:01:29 +08:00
8c6ff06216 upd: toast alert 2026-02-24 17:44:49 +08:00
214a243e44 upd: upd version
Deskripsi:
- tampilan jika update versi terbaru atau sedang maintenance

NO Issues
2026-02-24 15:51:29 +08:00
449f6f96cc Merge pull request 'upd: redesign' (#28) from amalia/23-feb-26 into join
Reviewed-on: #28
2026-02-24 13:36:49 +08:00
d1dec49784 upd: redesign 2026-02-23 14:20:26 +08:00
e351f54f6c Merge pull request 'upd: redesign' (#27) from amalia/20-feb-26 into join
Reviewed-on: #27
2026-02-23 10:17:00 +08:00
3809d382fa upd: redesign 2026-02-20 16:32:35 +08:00
d58a35bde2 Merge pull request 'amalia/19-feb-26' (#26) from amalia/19-feb-26 into join
Reviewed-on: #26
2026-02-20 10:50:38 +08:00
86b9fa6396 upd: bug bg saat pindah page 2026-02-19 15:45:08 +08:00
6770d40b41 upd: refactor style 2026-02-19 15:27:02 +08:00
77f478b7ca upd: redesign
Deskripsi:
- pengumuman
- list dan detail diskusi umum
- list dan detail diskusi divisi

NO Issues
2026-02-19 11:36:48 +08:00
e2a601c590 Merge pull request 'amalia/18-feb-26' (#25) from amalia/18-feb-26 into join
Reviewed-on: #25
2026-02-18 17:32:10 +08:00
4681f0a0cc upd: redesign 2026-02-18 17:26:19 +08:00
31b7cf6a30 upd: refresh control
deskripsi:
- warna refresh control pada semua fitur
- warna bottom pada modal select

No Issues
2026-02-18 16:35:04 +08:00
64aaafa2be upd: setting
Deskripsi:
- buat halaman setting
- isinya edit profile, ganti tema aplikasi, nonaktifkan notifikasi, sign out

No Issues
2026-02-18 15:45:45 +08:00
42cb7c8f8e fix: coding 2026-02-14 15:54:25 +08:00
8c63c08bc3 upd: redesign
Deskripsi:
- login dan konfirmasi kode otp
- firebase code env

No Issues
2026-02-14 15:43:38 +08:00
6ca935483a upd: fix
Deskripsi
- fix tinggi page saat pada tambah anggota pada fitur diskusi umum
- isdetrukstif false

No Issues
2026-02-14 14:12:25 +08:00
039b26f5aa upd: modal konfirmasi
Deskripsi:
- menerapkan semua modal baru pada semua fitur

No Issues''
2026-02-14 14:01:41 +08:00
10212aa5de upd: redesign 2026-02-14 10:58:53 +08:00
f0373ef479 Merge pull request 'upd: redesign' (#24) from amalia/13-feb-26 into join
Reviewed-on: http://wibugit.wibudev.com/wibu/mobile-darmasaba/pulls/24
2026-02-13 17:26:53 +08:00
acacf9c125 upd: redesign 2026-02-13 17:22:15 +08:00
700192dd8d Merge pull request 'upd: redesign' (#23) from amalia/12-feb-26 into join
Reviewed-on: http://wibugit.wibudev.com/wibu/mobile-darmasaba/pulls/23
2026-02-12 17:53:14 +08:00
4df0a44ac9 upd: redesign 2026-02-12 17:52:19 +08:00
27b0b7d51f Merge pull request 'redesign aplikasi' (#22) from amalia/11-feb-26 into join
Reviewed-on: http://wibugit.wibudev.com/wibu/mobile-darmasaba/pulls/22
2026-02-11 17:07:40 +08:00
65278df750 Merge pull request 'upd: redesign aplikasi' (#21) from amalia/10-feb-26 into join
Reviewed-on: http://wibugit.wibudev.com/wibu/mobile-darmasaba/pulls/21
2026-02-10 17:34:54 +08:00
8b98fee632 Merge pull request 'upd: redesign' (#20) from amalia/09-feb-25 into join
Reviewed-on: http://wibugit.wibudev.com/wibu/mobile-darmasaba/pulls/20
2026-02-09 17:50:22 +08:00
e254cf8ed2 Merge pull request 'upd: panduan' (#18) from amalia/06-feb-26 into join
Reviewed-on: http://wibugit.wibudev.com/wibu/mobile-darmasaba/pulls/18
2026-02-06 17:48:37 +08:00
199 changed files with 7054 additions and 2449 deletions

72
CLAUDE.md Normal file
View File

@@ -0,0 +1,72 @@
# 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
### Routing (Expo Router — file-based)
- `app/index.tsx` — Login/splash (public); OTP verification is handled inline via `components/auth/viewVerification.tsx` (not a separate route)
- `app/(application)/` — All authenticated screens; Expo Router enforces auth guard here
- Deep-link navigation is handled by `lib/pushToPage.ts`, which maps notification payloads to routes
### State Management (three layers)
1. **Context** (`providers/`) — Auth (token encryption/decryption via CryptoES.AES), Theme (light/dark, persisted to AsyncStorage), and React Query client
2. **Redux Toolkit** (`lib/store.ts` + slices) — Feature-level state for CRUD operations. Slices follow a naming pattern: `*Slice.ts` for read state, `*Update.ts`/`*Create.ts` for mutation state
3. **TanStack React Query** — All server data fetching; configured with 5-min stale time, 24-hour cache retention, 2 retries, and AsyncStorage persistence for offline support
### API Layer (`lib/api.ts`)
Single 773-line file defining 50+ Axios-based endpoints. The Axios instance reads `baseURL` from `Constants.expoConfig.extra.URL_API` (set in `.env` via `app.config.js`). Authentication uses Bearer tokens in headers. File uploads use `FormData` with `multipart/form-data`.
Three separate backend services are integrated:
- **REST API** (axios) — main business logic
- **WhatsApp server** — OTP delivery (separate token in `.env`)
- **Firebase** — real-time database (`lib/firebaseDatabase.ts`) and push notifications (`lib/useNotification.ts`, `lib/registerForPushNotificationsAsync.ts`)
### Providers Initialization Order
`app/_layout.tsx` wraps the app in: `ErrorBoundary``NotifierWrapper``ThemeProvider``QueryProvider``AuthProvider` → navigation stack. Redux `store` is provided inside `app/(application)/_layout.tsx`, not at the root.
### Error Boundary
`components/ErrorBoundary.tsx` is a class component (required by React) wrapping the entire app. It uses React Native's built-in `Text`**do not replace it with the custom `components/Text.tsx`** as that pulls in `ThemeProvider``AsyncStorage`, which breaks Jest tests.
Tests for ErrorBoundary live in `__tests__/ErrorBoundary-test.tsx` and use `@testing-library/react-native`.
## Key Conventions
**Imports:** Use `@/` alias (maps to project root, configured in `tsconfig.json`). Never use relative paths like `../../`.
**Utility functions:** Prefixed with `fun_` (e.g., `lib/fun_stringToDate.ts`, `lib/fun_validateName.ts`).
**Styling:** Use theme-aware colors from `useTheme()` hook. Global `StyleSheet` definitions live in `constants/Styles.ts`. Color tokens are in `constants/Colors.ts` with explicit `light`/`dark` variants.
**Component structure:** Feature-specific subdirectories under `components/` (e.g., `components/announcement/`) typically contain a header component alongside list/card components for that feature.
**Environment config:** All env vars are declared in `.env`, exposed through `app.config.js` `extra` field, and accessed via `Constants.expoConfig.extra.*` or the `constants/ConstEnv.ts` wrapper.
**EAS builds:** Profiles are `development`, `preview`, and `production` in `eas.json`. Production builds auto-increment the app version via the `bump` script.

View File

@@ -1,6 +1,6 @@
# 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

View 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();
});
});

View File

@@ -92,8 +92,8 @@ android {
applicationId 'mobiledarmasaba.app'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 6
versionName "1.0.2"
versionCode 16
versionName "2.1.0"
}
signingConfigs {
debug {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 904 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@@ -1,9 +1,9 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<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="android:statusBarColor">#ffffff</item>
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
</style>
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/splashscreen_background</item>

View File

@@ -4,7 +4,7 @@ export default {
expo: {
name: "Desa+",
slug: "mobile-darmasaba",
version: "2.0.5", // Versi aplikasi (App Store)
version: "2.1.0", // Versi aplikasi (App Store)
jsEngine: "jsc",
orientation: "portrait",
icon: "./assets/images/logo-icon-small.png",
@@ -14,7 +14,7 @@ export default {
ios: {
supportsTablet: true,
bundleIdentifier: "mobiledarmasaba.app",
buildNumber: "7",
buildNumber: "9",
infoPlist: {
ITSAppUsesNonExemptEncryption: false,
CFBundleDisplayName: "Desa+"
@@ -23,7 +23,7 @@ export default {
},
android: {
package: "mobiledarmasaba.app",
versionCode: 15,
versionCode: 16,
adaptiveIcon: {
foregroundImage: "./assets/images/logo-icon-small.png",
backgroundColor: "#ffffff"
@@ -79,6 +79,14 @@ export default {
URL_FIREBASE_DB: process.env.URL_FIREBASE_DB,
PASS_ENC: process.env.PASS_ENC,
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,
}
}
};

View File

@@ -1,5 +1,6 @@
import HeaderRightAnnouncementList from "@/components/announcement/headerAnnouncementList";
import AppHeader from "@/components/AppHeader";
import Styles from "@/constants/Styles";
import HeaderDiscussionGeneral from "@/components/discussion_general/headerDiscussionGeneral";
import HeaderRightDivisionList from "@/components/division/headerDivisionList";
import HeaderRightGroupList from "@/components/group/headerGroupList";
@@ -8,28 +9,106 @@ import HeaderRightPositionList from "@/components/position/headerRightPositionLi
import HeaderRightProjectList from "@/components/project/headerProjectList";
import Text from "@/components/Text";
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 store from "@/lib/store";
import { useAuthSession } from "@/providers/AuthProvider";
import AsyncStorage from "@react-native-async-storage/async-storage";
import Constants from "expo-constants";
import { getApp } from "@react-native-firebase/app";
import { getMessaging, onMessage } from "@react-native-firebase/messaging";
import { Redirect, router, Stack, usePathname } from "expo-router";
import { StatusBar } from 'expo-status-bar';
import { useEffect } from "react";
import { Easing, Notifier } from 'react-native-notifier';
import { StatusBar } from 'expo-status-bar';
import { useEffect, useState } from "react";
import { Easing, Notifier, NotifierComponents } from 'react-native-notifier';
import { Provider } from "react-redux";
import { useTheme } from "@/providers/ThemeProvider";
export default function RootLayout() {
const { token, decryptToken, isLoading } = useAuthSession()
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) {
try {
if (title != "Komentar Baru") {
if (title !== "Komentar Baru") {
const hasil = await decryptToken(String(token?.current))
const response = await apiReadOneNotification({ user: hasil, id: id })
await apiReadOneNotification({ user: hasil, id: id })
}
pushToPage(category, idContent)
} catch (error) {
@@ -65,12 +144,34 @@ export default function RootLayout() {
} else if (pathname !== `/${category}/${content}`) {
Notifier.showNotification({
title: title,
description: remoteMessage.notification?.body,
description: String(remoteMessage.notification?.body),
duration: 3000,
animationDuration: 300,
showEasing: Easing.ease,
onPress: () => handleReadNotification(String(id), String(category), String(content), String(title)),
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={{
headerShown: true,
animation: "slide_from_right",
// ⬇️ PENTING BANGET
animationTypeForReplace: "pop",
fullScreenGestureEnabled: true,
gestureEnabled: true,
contentStyle: { backgroundColor: colors.header },
}} >
<Stack.Screen name="home" options={{ title: 'Home' }} />
<Stack.Screen name="feature" options={{ title: 'Fitur' }} />
<Stack.Screen name="search" options={{ title: 'Pencarian' }} />
<Stack.Screen name="notification" options={{
title: 'Notifikasi',
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
headerTitle: 'Notifikasi',
headerTitleAlign: 'center',
header: () => (
@@ -112,11 +210,19 @@ export default function RootLayout() {
)
}} />
<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={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
title: 'Anggota',
headerTitleAlign: 'center',
// headerRight: () => <HeaderMemberList />
header: () => (
<AppHeader title="Anggota"
showBack={true}
@@ -126,10 +232,8 @@ export default function RootLayout() {
)
}} />
<Stack.Screen name="discussion/index" options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
title: 'Diskusi Umum',
headerTitleAlign: 'center',
// headerRight: () => <HeaderDiscussionGeneral />
header: () => (
<AppHeader
title="Diskusi Umum"
@@ -140,10 +244,8 @@ export default function RootLayout() {
)
}} />
<Stack.Screen name="project/index" options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
title: 'Kegiatan',
headerTitleAlign: 'center',
// headerRight: () => <HeaderRightProjectList />
header: () => (
<AppHeader title="Kegiatan"
showBack={true}
@@ -153,10 +255,8 @@ export default function RootLayout() {
)
}} />
<Stack.Screen name="division/index" options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
title: 'Divisi',
headerTitleAlign: 'center',
// headerRight: () => <HeaderRightDivisionList />
header: () => (
<AppHeader title="Divisi"
showBack={true}
@@ -167,10 +267,8 @@ export default function RootLayout() {
}} />
<Stack.Screen name="division/[id]/(fitur-division)" options={{ headerShown: false }} />
<Stack.Screen name="group/index" options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
headerTitle: 'Lembaga Desa',
headerTitleAlign: 'center',
// headerRight: () => <HeaderRightGroupList />
header: () => (
<AppHeader title="Lembaga Desa"
showBack={true}
@@ -180,10 +278,8 @@ export default function RootLayout() {
)
}} />
<Stack.Screen name="position/index" options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
headerTitle: 'Jabatan',
headerTitleAlign: 'center',
// headerRight: () => <HeaderRightPositionList />
header: () => (
<AppHeader title="Jabatan"
showBack={true}
@@ -194,10 +290,8 @@ export default function RootLayout() {
}} />
<Stack.Screen name="announcement/index"
options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
headerTitle: 'Pengumuman',
headerTitleAlign: 'center',
// headerRight: () => <HeaderRightAnnouncementList />
header: () => (
<AppHeader title="Pengumuman"
showBack={true}
@@ -210,6 +304,13 @@ export default function RootLayout() {
</Stack>
<StatusBar style={'light'} translucent={false} backgroundColor="black" />
<ToastCustom />
<ModalUpdateMaintenance
visible={modalUpdateMaintenance}
type={modalType}
isForceUpdate={isForceUpdate}
customDescription={updateMessage}
onDismiss={handleDismissUpdate}
/>
</Provider>
)
}

View File

@@ -3,6 +3,7 @@ import AppHeader from "@/components/AppHeader";
import BorderBottomItem from "@/components/borderBottomItem";
import Skeleton from "@/components/skeleton";
import Text from '@/components/Text';
import ErrorView from "@/components/ErrorView";
import { ConstEnv } from "@/constants/ConstEnv";
import { isImageFile } from "@/constants/FileExtensions";
import Styles from "@/constants/Styles";
@@ -65,6 +66,7 @@ export default function DetailAnnouncement() {
const [loadingOpen, setLoadingOpen] = useState(false)
const [preview, setPreview] = useState(false)
const [chooseFile, setChooseFile] = useState<FileData>()
const [isError, setIsError] = useState(false)
/**
* Opens the image preview modal for the selected image file
@@ -79,6 +81,7 @@ export default function DetailAnnouncement() {
async function handleLoad(loading: boolean) {
try {
setIsError(false)
setLoading(loading)
const hasil = await decryptToken(String(token?.current))
const response: ApiResponse = await apiGetAnnouncementOne({ id: id, user: hasil })
@@ -87,11 +90,15 @@ export default function DetailAnnouncement() {
setDataMember(response.member)
setDataFile(response.file)
} else {
setIsError(true)
Toast.show({ type: 'small', text1: response.message })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Gagal mengambil data' })
} catch (error: any) {
console.error(error);
setIsError(true)
const message = error?.response?.data?.message || "Gagal mengambil data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -177,7 +184,7 @@ export default function DetailAnnouncement() {
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
@@ -200,108 +207,114 @@ export default function DetailAnnouncement() {
<RefreshControl
refreshing={refreshing}
onRefresh={() => handleRefresh()}
tintColor={colors.primary}
tintColor={colors.icon}
/>
}
>
<View style={[Styles.p15, Styles.mb50]}>
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
{
loading ?
<View>
<View style={[Styles.rowOnly]}>
<Skeleton width={30} height={30} borderRadius={10} />
<View style={[{ flex: 1 }, Styles.ph05]}>
<Skeleton width={100} widthType="percent" height={30} borderRadius={10} />
</View>
</View>
<Skeleton width={100} 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>
:
<>
<View style={[Styles.rowItemsCenter, { alignItems: 'flex-start' }]}>
<MaterialIcons name="campaign" size={25} color={colors.text} style={[Styles.mr05]} />
<Text style={[Styles.textDefaultSemiBold, Styles.w90, Styles.mt02]}>{data?.title}</Text>
</View>
<View style={[Styles.mt10]}>
{
hasHtmlTags(data?.desc) ?
<RenderHTML
contentWidth={contentWidth}
source={{ html: data?.desc }}
baseStyle={{ color: colors.text }}
/>
:
<Text>{data?.desc}</Text>
}
</View>
</>
}
{isError && !loading ? (
<View style={[Styles.mv50]}>
<ErrorView />
</View>
{
dataFile.length > 0 && (
<View style={[Styles.wrapPaper, Styles.mt10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.mb05]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
</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={colors.text}
/>}
title={item.name + '.' + item.extension}
titleWeight="normal"
onPress={() => {
isImageFile(item.extension) ?
handleChooseFile(item)
: openFile(item)
}}
/>
))}
</View>
)
}
<View style={[Styles.wrapPaper, Styles.mt10, { backgroundColor: colors.card, borderColor: colors.background }]}>
{
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 style={[Styles.p15, Styles.mb50]}>
<View style={[Styles.wrapPaper, Styles.borderAll, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
loading ?
<View>
<View style={[Styles.rowOnly]}>
<Skeleton width={30} height={30} borderRadius={10} />
<View style={[Styles.flex1, Styles.ph05]}>
<Skeleton width={100} widthType="percent" height={30} borderRadius={10} />
</View>
</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>
<Skeleton width={100} 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>
:
<>
<View style={[Styles.rowOnly, Styles.alignStart]}>
<MaterialIcons name="campaign" size={25} color={colors.text} style={[Styles.mr05]} />
<Text style={[Styles.textDefaultSemiBold, Styles.w90, Styles.mt02]}>{data?.title}</Text>
</View>
<View style={[Styles.mt10]}>
{
dataMember[v].map((item: any, x: any) => {
return (
<View key={x} style={[Styles.rowItemsCenter, Styles.w90]}>
<Entypo name="dot-single" size={24} color={colors.text} />
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{item.division}</Text>
</View>
)
})
hasHtmlTags(data?.desc) ?
<RenderHTML
contentWidth={contentWidth}
source={{ html: data?.desc }}
baseStyle={{ color: colors.text }}
/>
:
<Text>{data?.desc}</Text>
}
</View>
)
})
</>
}
</View>
{
dataFile.length > 0 && (
<View style={[Styles.wrapPaper, Styles.borderAll, Styles.mt10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<View style={[Styles.mb05]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
</View>
{dataFile.map((item, index) => (
<BorderBottomItem
key={`${item.id}-${index}`}
borderType={index === dataFile.length - 1 ? 'none' : 'bottom'}
icon={<MaterialCommunityIcons
name={isImageFile(item.extension) ? "file-image-outline" : "file-document-outline"}
size={25}
color={colors.text}
/>}
title={item.name + '.' + item.extension}
titleWeight="normal"
onPress={() => {
isImageFile(item.extension) ?
handleChooseFile(item)
: openFile(item)
}}
/>
))}
</View>
)
}
<View style={[Styles.wrapPaper, Styles.borderAll, Styles.mt10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
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={colors.text} />
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{item.division}</Text>
</View>
)
})
}
</View>
)
})
}
</View>
</View>
</View>
)}
</ScrollView>
<ImageViewing
@@ -318,7 +331,7 @@ export default function DetailAnnouncement() {
accessibilityRole="button"
accessibilityLabel="Close image viewer"
>
<Text style={{ color: 'white', fontSize: 26 }}></Text>
<Text style={[Styles.textWhite, Styles.font26]}></Text>
</Pressable>
{/* MENU */}
@@ -328,17 +341,17 @@ export default function DetailAnnouncement() {
accessibilityLabel="Download or share image"
disabled={loadingOpen}
>
<Text style={{ color: loadingOpen ? 'gray' : 'white', fontSize: 22 }}></Text>
<Text style={[{ color: loadingOpen ? 'gray' : 'white' }, Styles.font26]}></Text>
</Pressable>
</View>
)}
FooterComponent={({ imageIndex }) => (
<View style={{
paddingBottom: 20,
paddingHorizontal: 16,
alignItems: 'center',
}}>
<Text style={{ color: 'white', fontSize: 16 }}>{chooseFile?.name}.{chooseFile?.extension}</Text>
<View style={[
Styles.pb20,
Styles.ph16,
Styles.alignCenter,
]}>
<Text style={[Styles.textWhite, Styles.font16]}>{chooseFile?.name}.{chooseFile?.extension}</Text>
</View>
)}
/>

View File

@@ -4,7 +4,7 @@ import ButtonSaveHeader from "@/components/buttonSaveHeader";
import ButtonSelect from "@/components/buttonSelect";
import DrawerBottom from "@/components/drawerBottom";
import { InputForm } from "@/components/inputForm";
import LoadingOverlay from "@/components/loadingOverlay";
import LoadingCenter from "@/components/loadingCenter";
import MenuItemRow from "@/components/menuItemRow";
import ModalSelectMultiple from "@/components/modalSelectMultiple";
import Text from "@/components/Text";
@@ -17,7 +17,7 @@ import { Entypo, Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
import * as DocumentPicker from "expo-document-picker";
import { router, Stack } from "expo-router";
import React, { useEffect, useState } from "react";
import { SafeAreaView, ScrollView, StyleSheet, View } from "react-native";
import { SafeAreaView, ScrollView, View } from "react-native";
import Toast from "react-native-toast-message";
import { useDispatch, useSelector } from "react-redux";
@@ -95,17 +95,21 @@ export default function CreateAnnouncement() {
const response = await apiCreateAnnouncement(fd)
// const response = await apiCreateAnnouncement({
// data: { ...dataForm, user: hasil, groups: divisionMember },
// });
if (response.success) {
dispatch(setUpdateAnnouncement(!update))
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
router.back();
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Tidak dapat terhubung ke server"
Toast.show({
type: 'small',
text1: message
})
} finally {
setLoading(false)
}
@@ -131,7 +135,7 @@ export default function CreateAnnouncement() {
}
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (
@@ -174,7 +178,7 @@ export default function CreateAnnouncement() {
)
}}
/>
<LoadingOverlay visible={loading} />
{loading && <LoadingCenter />}
<ScrollView
showsVerticalScrollIndicator={false}
style={[Styles.h100, { backgroundColor: colors.background }]}
@@ -205,21 +209,27 @@ export default function CreateAnnouncement() {
{
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={colors.text} />}
title={item.name}
titleWeight="normal"
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
/>
))
}
</View>
<>
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
<Text style={[Styles.textDefault]}>{fileForm.length} file</Text>
</View>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, Styles.mb10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
fileForm.map((item, index) => (
<BorderBottomItem
key={index}
borderType={fileForm.length - 1 == index ? "none" : "bottom"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name}
bgColor="transparent"
titleWeight="normal"
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
/>
))
}
</View>
</>
}
<ButtonSelect
@@ -232,25 +242,30 @@ export default function CreateAnnouncement() {
{
divisionMember.length > 0
&&
<View style={[Styles.borderAll, Styles.round10, Styles.p10]}>
{
divisionMember.map((item: { name: any; Division: any }, index: any) => {
return (
<View key={index}>
<Text style={[Styles.textDefaultSemiBold]}>{item.name}</Text>
{
item.Division.map((division: any, i: any) => (
<View key={i} style={[Styles.rowItemsCenter, Styles.w90]}>
<Entypo name="dot-single" size={24} color={colors.text} />
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{division.name}</Text>
</View>
))
}
</View>
)
})
}
</View>
<>
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
<Text style={[Styles.textDefaultSemiBold]}>Divisi</Text>
</View>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
divisionMember.map((item: { name: any; Division: any }, index: any) => {
return (
<View key={index}>
<Text style={[Styles.textDefaultSemiBold]}>{item.name}</Text>
{
item.Division.map((division: any, i: any) => (
<View key={i} style={[Styles.rowItemsCenter, Styles.w90]}>
<Entypo name="dot-single" size={24} color={colors.text} />
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{division.name}</Text>
</View>
))
}
</View>
)
})
}
</View>
</>
}
</View>
</ScrollView>
@@ -280,15 +295,4 @@ export default function CreateAnnouncement() {
);
}
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
},
});

View File

@@ -4,7 +4,7 @@ import ButtonSaveHeader from "@/components/buttonSaveHeader";
import ButtonSelect from "@/components/buttonSelect";
import DrawerBottom from "@/components/drawerBottom";
import { InputForm } from "@/components/inputForm";
import LoadingOverlay from "@/components/loadingOverlay";
import LoadingCenter from "@/components/loadingCenter";
import MenuItemRow from "@/components/menuItemRow";
import ModalSelectMultiple from "@/components/modalSelectMultiple";
import Text from '@/components/Text';
@@ -144,9 +144,14 @@ export default function EditAnnouncement() {
dispatch(setUpdateAnnouncement(!update))
Toast.show({ type: 'small', text1: 'Berhasil mengubah data', })
router.back();
} else {
Toast.show({ type: 'small', text1: 'Gagal mengubah data', })
}
} catch (error) {
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengubah data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -225,7 +230,7 @@ export default function EditAnnouncement() {
)
}}
/>
<LoadingOverlay visible={loading} />
{loading && <LoadingCenter />}
<ScrollView
showsVerticalScrollIndicator={false}
style={[Styles.h100, { backgroundColor: colors.background }]}
@@ -258,33 +263,40 @@ export default function EditAnnouncement() {
{
(fileForm.length > 0 || dataFile.filter((val) => !val.delete).length > 0)
&&
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
{
dataFile.filter((val) => !val.delete).map((item, index) => (
<BorderBottomItem
key={index}
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name + '.' + item.extension}
titleWeight="normal"
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
/>
))
}
{
fileForm.map((item, index) => (
<BorderBottomItem
key={index}
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name}
titleWeight="normal"
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
/>
))
}
</View>
<>
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
<Text style={[Styles.textDefault]}>{fileForm.length + dataFile.filter((val) => !val.delete).length} file</Text>
</View>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, Styles.mb10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
dataFile.filter((val) => !val.delete).map((item, index) => (
<BorderBottomItem
key={index}
borderType={dataFile.filter((val) => !val.delete).length - 1 == index && fileForm.length == 0 ? "none" : "bottom"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name + '.' + item.extension}
titleWeight="normal"
bgColor="transparent"
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
/>
))
}
{
fileForm.map((item, index) => (
<BorderBottomItem
key={index}
borderType={fileForm.length - 1 == index ? "none" : "bottom"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name}
titleWeight="normal"
bgColor="transparent"
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
/>
))
}
</View>
</>
}
<ButtonSelect
value="Pilih divisi penerima pengumuman"
@@ -295,25 +307,30 @@ export default function EditAnnouncement() {
{
dataMember.length > 0
&&
<View style={[Styles.borderAll, Styles.round10, Styles.p10]}>
{
dataMember.map((item: { name: any; Division: any }, index: any) => {
return (
<View key={index}>
<Text style={[Styles.textDefaultSemiBold]}>{item.name}</Text>
{
item.Division.map((division: any, i: any) => (
<View key={i} style={[Styles.rowItemsCenter, Styles.w90]}>
<Entypo name="dot-single" size={24} color={colors.text} />
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{division.name}</Text>
</View>
))
}
</View>
)
})
}
</View>
<>
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
<Text style={[Styles.textDefaultSemiBold]}>Divisi</Text>
</View>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
dataMember.map((item: { name: any; Division: any }, index: any) => {
return (
<View key={index}>
<Text style={[Styles.textDefaultSemiBold]}>{item.name}</Text>
{
item.Division.map((division: any, i: any) => (
<View key={i} style={[Styles.rowItemsCenter, Styles.w90]}>
<Entypo name="dot-single" size={24} color={colors.text} />
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{division.name}</Text>
</View>
))
}
</View>
)
})
}
</View>
</>
}
</View>
</ScrollView>

View File

@@ -2,14 +2,14 @@ import BorderBottomItem from "@/components/borderBottomItem";
import InputSearch from "@/components/inputSearch";
import SkeletonContent from "@/components/skeletonContent";
import Text from '@/components/Text';
import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { apiGetAnnouncement } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { MaterialIcons } from "@expo/vector-icons";
import { useInfiniteQuery } from "@tanstack/react-query";
import { router } from "expo-router";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { RefreshControl, View, VirtualizedList } from "react-native";
import { useSelector } from "react-redux";
@@ -20,89 +20,81 @@ type Props = {
createdAt: string
}
export default function Announcement() {
const { token, decryptToken } = useAuthSession()
const { colors } = useTheme();
const [data, setData] = useState<Props[]>([])
const [search, setSearch] = useState('')
const update = useSelector((state: any) => state.announcementUpdate)
const [loading, setLoading] = useState(true)
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [page, setPage] = useState(1)
const [waiting, setWaiting] = useState(false)
const [refreshing, setRefreshing] = useState(false)
async function handleLoad(loading: boolean, thisPage: number) {
try {
setWaiting(true)
setLoading(loading)
setPage(thisPage)
// TanStack Query Infinite Query
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
isLoading,
refetch,
isRefetching
} = useInfiniteQuery({
queryKey: ['announcements', search],
queryFn: async ({ pageParam = 1 }) => {
const hasil = await decryptToken(String(token?.current))
const response = await apiGetAnnouncement({ user: hasil, search: search, page: thisPage })
if (thisPage == 1) {
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)
}
}
const response = await apiGetAnnouncement({
user: hasil,
search: search,
page: pageParam
})
return response.data
},
initialPageParam: 1,
getNextPageParam: (lastPage, allPages) => {
return lastPage.length > 0 ? allPages.length + 1 : undefined
},
})
// Trigger refetch when Redux state 'update' changes
useEffect(() => {
handleLoad(false, 1)
}, [update])
refetch()
}, [update, refetch])
useEffect(() => {
handleLoad(true, 1)
}, [search])
// Flatten data from pages
const flattenedData = useMemo(() => {
return data?.pages.flat() || []
}, [data])
const loadMoreData = () => {
if (waiting) return
setTimeout(() => {
handleLoad(false, page + 1)
}, 1000);
};
const handleRefresh = async () => {
setRefreshing(true)
handleLoad(false, 1)
await new Promise(resolve => setTimeout(resolve, 2000));
setRefreshing(false)
if (hasNextPage && !isFetchingNextPage) {
fetchNextPage()
}
};
const getItem = (_data: unknown, index: number): Props => ({
id: data[index].id,
title: data[index].title,
desc: data[index].desc,
createdAt: data[index].createdAt,
id: flattenedData[index].id,
title: flattenedData[index].title,
desc: flattenedData[index].desc,
createdAt: flattenedData[index].createdAt,
})
return (
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
<View>
<InputSearch onChange={setSearch} />
</View>
<View style={[{ flex: 2 }, Styles.mt05]}>
<View style={[Styles.flex2, Styles.mt05]}>
{
loading ?
isLoading && !flattenedData.length ?
arrSkeleton.map((item, index) => {
return (
<SkeletonContent key={index} />
)
})
:
data.length > 0
flattenedData.length > 0
?
<VirtualizedList
data={data}
getItemCount={() => data.length}
data={flattenedData}
getItemCount={() => flattenedData.length}
getItem={getItem}
renderItem={({ item, index }: { item: Props, index: number }) => {
return (
@@ -110,10 +102,9 @@ export default function Announcement() {
key={index}
onPress={() => { router.push(`/announcement/${item.id}`) }}
borderType="bottom"
bgColor="transparent"
icon={
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
<MaterialIcons name="campaign" size={25} color={'#384288'} />
</View>
<MaterialIcons name="campaign" size={25} color={colors.text} />
}
title={item.title}
desc={item.desc.replace(/<[^>]*>?/gm, '').replace(/\r?\n|\r/g, ' ')}
@@ -121,20 +112,20 @@ export default function Announcement() {
/>
)
}}
keyExtractor={(item, index) => String(index)}
keyExtractor={(item, index) => String(item.id || index)}
onEndReached={loadMoreData}
onEndReachedThreshold={0.5}
showsVerticalScrollIndicator={false}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
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, { color: colors.dimmed }]}>Tidak ada pengumuman</Text>
}
</View>
</View>

View File

@@ -1,6 +1,7 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import { InputForm } from "@/components/inputForm";
import LoadingCenter from "@/components/loadingCenter";
import Text from "@/components/Text";
import { ConstEnv } from "@/constants/ConstEnv";
import Styles from "@/constants/Styles";
@@ -105,16 +106,18 @@ export default function EditBanner() {
} else {
Toast.show({ type: 'small', text1: 'Gagal mengupdate data', })
}
} catch (error) {
} catch (error: any) {
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 {
setLoading(false)
}
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (
@@ -145,6 +148,7 @@ export default function EditBanner() {
)
}}
/>
{loading && <LoadingCenter />}
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, { backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.mb100]}>
<View style={[Styles.mb15]}>
@@ -156,7 +160,7 @@ export default function EditBanner() {
? selectedImage
: selectedImage.uri
}
style={{ resizeMode: "contain", width: "100%", height: 100 }}
style={[Styles.resizeContain, Styles.w100, { height: 100 }]}
/>
</Pressable>
) : (
@@ -165,7 +169,7 @@ export default function EditBanner() {
style={[Styles.wrapPaper, Styles.contentItemCenter]}
>
<View
style={{ justifyContent: "center", alignItems: "center" }}
style={[Styles.contentItemCenter]}
>
<Entypo name="image" size={50} color={"#aeaeae"} />
<Text style={[Styles.textInformation, Styles.mt05]}>

View File

@@ -1,6 +1,7 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import { InputForm } from "@/components/inputForm";
import LoadingCenter from "@/components/loadingCenter";
import Text from "@/components/Text";
import Styles from "@/constants/Styles";
import { apiCreateBanner, apiGetBanner } from "@/lib/api";
@@ -87,36 +88,22 @@ export default function CreateBanner() {
} else {
Toast.show({ type: 'small', text1: 'Gagal menambahkan data', })
}
} catch (error) {
} catch (error: any) {
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 {
setLoading(false)
}
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (
// <ButtonBackHeader
// onPress={() => {
// router.back();
// }}
// />
// ),
headerTitle: "Tambah Banner",
headerTitleAlign: "center",
// headerRight: () => (
// <ButtonSaveHeader
// disable={title == "" || selectedImage == undefined || error || loading ? true : false}
// category="create"
// onPress={() => {
// handleCreateEntity();
// }}
// />
// ),
header: () => (
<AppHeader
title="Fitur"
@@ -135,6 +122,7 @@ export default function CreateBanner() {
)
}}
/>
{loading && <LoadingCenter />}
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, { backgroundColor: colors.background }]}>
<View style={[Styles.p15]}>
<View style={[Styles.mb15]}>
@@ -142,19 +130,19 @@ export default function CreateBanner() {
<Pressable onPress={pickImageAsync}>
<Image
src={selectedImage}
style={{ resizeMode: "contain", width: "100%", height: 100 }}
style={[Styles.resizeContain, Styles.w100, { height: 100 }]}
/>
</Pressable>
) : (
<Pressable
onPress={pickImageAsync}
style={[Styles.wrapPaper, Styles.contentItemCenter]}
style={[Styles.wrapPaper, Styles.contentItemCenter, Styles.borderAll, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}
>
<View
style={{ justifyContent: "center", alignItems: "center" }}
style={[Styles.contentItemCenter]}
>
<Entypo name="image" size={50} color={"#aeaeae"} />
<Text style={[Styles.textInformation, Styles.mt05]}>
<Entypo name="image" size={50} color={colors.dimmed} />
<Text style={[Styles.textInformation, Styles.mt05, { color: colors.dimmed }]}>
Mohon unggah gambar dalam resolusi 1650 x 720 pixel untuk
memastikan
</Text>

View File

@@ -1,10 +1,12 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi"
import styles from "@/components/AppHeader"
import AppHeader from "@/components/AppHeader"
import HeaderRightBannerList from "@/components/banner/headerBannerList"
import BorderBottomItem from "@/components/borderBottomItem"
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"
@@ -13,11 +15,12 @@ import { setEntities } from "@/lib/bannerSlice"
import { useAuthSession } from "@/providers/AuthProvider"
import { useTheme } from "@/providers/ThemeProvider"
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import * as FileSystem from 'expo-file-system'
import { startActivityAsync } from 'expo-intent-launcher'
import { router, Stack } from "expo-router"
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 ImageViewing from 'react-native-image-viewing'
import * as mime from 'react-native-mime-types'
@@ -42,34 +45,52 @@ export default function BannerList() {
const [refreshing, setRefreshing] = useState(false)
const [loadingOpen, setLoadingOpen] = useState(false)
const [viewImg, setViewImg] = useState(false)
const [showDeleteModal, setShowDeleteModal] = useState(false)
const queryClient = useQueryClient()
const handleDeleteEntity = async () => {
try {
const hasil = await decryptToken(String(token?.current));
const deletedEntity = await apiDeleteBanner({ user: hasil }, dataId);
if (deletedEntity.success) {
Toast.show({ type: 'small', text1: 'Berhasil menghapus data', })
apiGetBanner({ user: hasil }).then((data) =>
dispatch(setEntities(data.data))
);
} else {
Toast.show({ type: 'small', text1: 'Gagal menghapus data', })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} finally {
setModal(false)
// 1. Fetching logic with useQuery
const { data: bannersRes, isLoading } = useQuery({
queryKey: ['banners'],
queryFn: async () => {
const hasil = await decryptToken(String(token?.current))
const response = await apiGetBanner({ user: hasil })
return response.data || []
},
enabled: !!token?.current,
staleTime: 0,
})
// Sync results with Redux
useEffect(() => {
if (bannersRes) {
dispatch(setEntities(bannersRes))
}
}, [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 () => {
setRefreshing(true)
const hasil = await decryptToken(String(token?.current));
apiGetBanner({ user: hasil }).then((data) =>
dispatch(setEntities(data.data))
);
await new Promise(resolve => setTimeout(resolve, 2000));
await queryClient.invalidateQueries({ queryKey: ['banners'] })
setRefreshing(false)
};
@@ -107,7 +128,7 @@ export default function BannerList() {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
@@ -132,42 +153,45 @@ export default function BannerList() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
tintColor={colors.icon}
/>
}
style={[Styles.h100, { backgroundColor: colors.background }]}
>
{
entities.length > 0
?
<View style={[Styles.p15, Styles.mb100]}>
{entities.map((index: any, key: number) => (
<BorderBottomItem
key={key}
onPress={() => {
setDataId(index.id)
setSelectFile(index)
setModal(true)
}}
borderType="all"
icon={
<Image
source={{ uri: `${ConstEnv.url_storage}/files/${index.image}` }}
style={[Styles.imgListBanner]}
/>
}
title={index.title}
width={65}
/>
))}
</View>
:
<View style={[Styles.p15, Styles.mb100]}>
<Text style={[Styles.textDefault, { textAlign: 'center' }]}>Tidak ada data</Text>
</View>
}
<View style={[Styles.p15, Styles.mb100]}>
{
isLoading ? (
<>
<Skeleton width={100} height={150} borderRadius={10} widthType="percent" />
<Skeleton width={100} height={150} borderRadius={10} widthType="percent" />
<Skeleton width={100} height={150} borderRadius={10} widthType="percent" />
</>
) :
entities.length > 0 ?
entities.map((index: any, key: number) => (
<BorderBottomItem
key={key}
onPress={() => {
setDataId(index.id)
setSelectFile(index)
setModal(true)
}}
borderType="all"
icon={
<Image
source={{ uri: `${ConstEnv.url_storage}/files/${index.image}` }}
style={[Styles.imgListBanner]}
/>
}
title={index.title}
/>
))
:
<View style={[Styles.p15, Styles.mb100]}>
<Text style={[Styles.textDefault, Styles.textCenter]}>Tidak ada data</Text>
</View>
}
</View>
</ScrollView>
<DrawerBottom animation="slide" isVisible={isModal} setVisible={() => setModal(false)} title="Menu">
@@ -196,11 +220,9 @@ export default function BannerList() {
title="Hapus"
onPress={() => {
setModal(false)
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah anda yakin ingin menghapus data?',
onPress: () => { handleDeleteEntity() }
})
setTimeout(() => {
setShowDeleteModal(true)
}, 600)
}}
/>
</View>
@@ -213,6 +235,19 @@ export default function BannerList() {
onRequestClose={() => setViewImg(false)}
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>
)
}

View File

@@ -1,4 +1,3 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi";
import AppHeader from "@/components/AppHeader";
import BorderBottomItem from "@/components/borderBottomItem";
import BorderBottomItem2 from "@/components/borderBottomItem2";
@@ -8,10 +7,10 @@ import ImageUser from "@/components/imageNew";
import { InputForm } from "@/components/inputForm";
import LabelStatus from "@/components/labelStatus";
import MenuItemRow from "@/components/menuItemRow";
import ModalConfirmation from "@/components/ModalConfirmation";
import Skeleton from "@/components/skeleton";
import SkeletonContent from "@/components/skeletonContent";
import Text from '@/components/Text';
import { ColorsStatus } from "@/constants/ColorsStatus";
import { ConstEnv } from "@/constants/ConstEnv";
import { regexOnlySpacesOrEnter } from "@/constants/OnlySpaceOrEnter";
import Styles from "@/constants/Styles";
@@ -81,6 +80,7 @@ export default function DetailDiscussionGeneral() {
comment: ''
})
const [viewEdit, setViewEdit] = useState(false)
const [showDeleteModal, setShowDeleteModal] = useState(false)
useEffect(() => {
const onValueChange = reference.on('value', snapshot => {
@@ -158,8 +158,11 @@ export default function DetailDiscussionGeneral() {
Toast.show({ type: 'small', text1: response.message })
}
}
} catch (error) {
console.error(error)
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoadingSendKomentar(false)
}
@@ -175,8 +178,11 @@ export default function DetailDiscussionGeneral() {
} else {
Toast.show({ type: 'small', text1: response.message })
}
} catch (error) {
console.error(error)
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengupdate data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoadingSendKomentar(false)
handleViewEditKomentar()
@@ -193,8 +199,11 @@ export default function DetailDiscussionGeneral() {
} else {
Toast.show({ type: 'small', text1: response.message })
}
} catch (error) {
console.error(error)
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menghapus data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoadingSendKomentar(false)
setVisible(false)
@@ -239,7 +248,7 @@ export default function DetailDiscussionGeneral() {
)
}}
/>
<View style={{ flex: 1, backgroundColor: colors.background }}>
<View style={[Styles.flex1, { backgroundColor: colors.background }]}>
<ScrollView
showsVerticalScrollIndicator={false}
style={[Styles.h100, { backgroundColor: colors.background }]}
@@ -247,7 +256,7 @@ export default function DetailDiscussionGeneral() {
<RefreshControl
refreshing={refreshing}
onRefresh={() => handleRefresh()}
tintColor={colors.primary}
tintColor={colors.icon}
/>
}
>
@@ -259,7 +268,8 @@ export default function DetailDiscussionGeneral() {
<BorderBottomItem2
dataFile={fileDiscussion}
descEllipsize={false}
borderType="bottom"
borderType="all"
bgColor="white"
icon={
<View style={[Styles.iconContent]}>
<MaterialIcons name="chat" size={25} color={'black'} />
@@ -287,7 +297,7 @@ export default function DetailDiscussionGeneral() {
}
/>
}
<View style={[Styles.p15]}>
<View style={[Styles.mt10]}>
{
loadingKomentar ?
arrSkeleton.map((item: any, i: number) => {
@@ -300,7 +310,7 @@ export default function DetailDiscussionGeneral() {
return (
<BorderBottomItem
key={i}
borderType="bottom"
borderType="all"
colorPress
icon={
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
@@ -310,7 +320,7 @@ export default function DetailDiscussionGeneral() {
desc={item.comment}
rightBottomInfo={item.isEdited ? "Edited" : ""}
descEllipsize={detailMore.includes(item.id) ? false : true}
bgColor="transparent"
bgColor="white"
onPress={() => {
setDetailMore((prev: any) => {
if (prev.includes(item.id)) {
@@ -370,7 +380,7 @@ export default function DetailDiscussionGeneral() {
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"))) ? {color:colors.dimmed} : {color:colors.tint}} />
<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"))) ? { color: colors.dimmed } : { color: colors.tint }} />
</Pressable>
}
/>
@@ -396,13 +406,13 @@ export default function DetailDiscussionGeneral() {
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"))) ? {color: colors.dimmed} : {color:colors.tint}} />
<MaterialIcons name="send" size={25} style={(loadingSendKomentar || komentar == '' || regexOnlySpacesOrEnter.test(komentar) || data?.status === 2 || !data?.isActive || (!memberDiscussion && (entityUser.role == "user" || entityUser.role == "coadmin"))) ? { color: colors.dimmed } : { color: colors.tint }} />
</Pressable>
}
/>
:
<View style={[Styles.pv20, { alignItems: 'center' }]}>
<Text style={[Styles.textInformation, Styles.cGray]}>
<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 diskusi yang dapat memberikan komentar"
}
@@ -425,17 +435,27 @@ export default function DetailDiscussionGeneral() {
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
title="Hapus"
onPress={() => {
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah anda yakin ingin menghapus komentar?',
onPress: () => {
handleDeleteKomentar()
}
})
setVisible(false)
setTimeout(() => {
setShowDeleteModal(true)
}, 600)
}}
/>
</View>
</DrawerBottom>
<ModalConfirmation
visible={showDeleteModal}
title="Konfirmasi"
message="Apakah anda yakin ingin menghapus komentar?"
onConfirm={() => {
setShowDeleteModal(false)
handleDeleteKomentar()
}}
onCancel={() => setShowDeleteModal(false)}
confirmText="Hapus"
cancelText="Batal"
/>
</>
)
}

View File

@@ -84,9 +84,11 @@ export default function AddMemberDiscussionDetail() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Gagal menambahkan anggota', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan anggota"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -94,7 +96,7 @@ export default function AddMemberDiscussionDetail() {
return (
<SafeAreaView>
<>
<Stack.Screen
options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
@@ -127,7 +129,7 @@ export default function AddMemberDiscussionDetail() {
)
}}
/>
<View style={[Styles.p15, { backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
<InputSearch onChange={setSearch} value={search} />
{
@@ -149,7 +151,7 @@ export default function AddMemberDiscussionDetail() {
</View>
:
<Text style={[Styles.textDefault, Styles.pv05, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada member yang dipilih</Text>
<Text style={[Styles.textDefault, Styles.pv05, Styles.textCenter, { color: colors.dimmed }]}>Tidak ada member yang dipilih</Text>
}
<ScrollView
showsVerticalScrollIndicator={false}
@@ -172,7 +174,7 @@ export default function AddMemberDiscussionDetail() {
<View style={[Styles.ml10]}>
<Text style={[Styles.textDefault]}>{item.name}</Text>
{
found && <Text style={[Styles.textInformation, {color: colors.dimmed}]}>sudah menjadi anggota</Text>
found && <Text style={[Styles.textInformation, { color: colors.dimmed }]}>sudah menjadi anggota</Text>
}
</View>
</View>
@@ -184,10 +186,10 @@ export default function AddMemberDiscussionDetail() {
}
)
:
<Text style={[Styles.textDefault, { textAlign: 'center' }]}>Tidak ada data</Text>
<Text style={[Styles.textDefault, Styles.textCenter]}>Tidak ada data</Text>
}
</ScrollView>
</View>
</SafeAreaView>
</>
)
}

View File

@@ -5,7 +5,7 @@ import ButtonSelect from "@/components/buttonSelect";
import DrawerBottom from "@/components/drawerBottom";
import ImageUser from "@/components/imageNew";
import { InputForm } from "@/components/inputForm";
import LoadingOverlay from "@/components/loadingOverlay";
import LoadingCenter from "@/components/loadingCenter";
import MenuItemRow from "@/components/menuItemRow";
import ModalSelect from "@/components/modalSelect";
import SelectForm from "@/components/selectForm";
@@ -156,16 +156,18 @@ export default function CreateDiscussionGeneral() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error: any) {
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 {
setLoading(false)
}
}
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (
@@ -206,8 +208,8 @@ export default function CreateDiscussionGeneral() {
)
}}
/>
<LoadingOverlay visible={loading} />
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, { backgroundColor: colors.background }]}>
{loading && <LoadingCenter />}
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.mb100]}>
{
(entityUser.role == "supadmin" ||
@@ -253,21 +255,27 @@ export default function CreateDiscussionGeneral() {
{
fileForm.length > 0
&&
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10, { borderColor: colors.icon }]}>
<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={colors.text} />}
title={item.name}
titleWeight="normal"
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
/>
))
}
</View>
<>
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
<Text style={[Styles.textDefault]}>{fileForm.length} file</Text>
</View>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, Styles.mb10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
fileForm.map((item, index) => (
<BorderBottomItem
key={index}
borderType={fileForm.length - 1 == index ? "none" : "bottom"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name}
bgColor="transparent"
titleWeight="normal"
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
/>
))
}
</View>
</>
}
<ButtonSelect
value="Pilih Anggota"
@@ -292,21 +300,22 @@ export default function CreateDiscussionGeneral() {
entitiesMember.length > 0 &&
<View>
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
<Text>Anggota</Text>
<Text>Total {entitiesMember.length} Anggota</Text>
<Text style={[Styles.textDefaultSemiBold]}>Anggota</Text>
<Text style={[Styles.textDefault]}>{entitiesMember.length} Anggota</Text>
</View>
<View style={[Styles.borderAll, Styles.round10, Styles.p10, { borderColor: colors.icon }]}>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
entitiesMember.map((item: { img: any; name: any; }, index: any) => {
return (
<BorderBottomItem
key={index}
borderType="bottom"
borderType={entitiesMember.length - 1 == index ? "none" : "bottom"}
icon={
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="sm" />
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
}
title={item.name}
bgColor="transparent"
/>
)
})

View File

@@ -5,7 +5,7 @@ import ButtonSaveHeader from "@/components/buttonSaveHeader";
import ButtonSelect from "@/components/buttonSelect";
import DrawerBottom from "@/components/drawerBottom";
import { InputForm } from "@/components/inputForm";
import LoadingOverlay from "@/components/loadingOverlay";
import LoadingCenter from "@/components/loadingCenter";
import MenuItemRow from "@/components/menuItemRow";
import Styles from "@/constants/Styles";
import { apiEditDiscussionGeneral, apiGetDiscussionGeneralOne } from "@/lib/api";
@@ -154,17 +154,21 @@ export default function EditDiscussionGeneral() {
dispatch(setUpdateDiscussionGeneralDetail(!update))
Toast.show({ type: 'small', text1: 'Berhasil mengubah data', })
router.back();
} else {
Toast.show({ type: 'small', text1: 'Gagal mengubah data', })
}
} catch (error) {
} catch (error: any) {
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 {
setLoading(false)
}
}
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (
@@ -199,8 +203,8 @@ export default function EditDiscussionGeneral() {
)
}}
/>
<LoadingOverlay visible={loading} />
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, { backgroundColor: colors.background }]}>
{loading && <LoadingCenter />}
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}>
<View style={[Styles.p15]}>
<InputForm
label="Judul"
@@ -229,33 +233,40 @@ export default function EditDiscussionGeneral() {
{
(fileForm.length > 0 || dataFile.filter((val) => !val.delete).length > 0)
&&
<View>
<Text style={[Styles.textDefault]}>File</Text>
{
dataFile.filter((val) => !val.delete).map((item, index) => (
<BorderBottomItem
key={index}
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name + '.' + item.extension}
titleWeight="normal"
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
/>
))
}
{
fileForm.map((item, index) => (
<BorderBottomItem
key={index}
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name}
titleWeight="normal"
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
/>
))
}
</View>
<>
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
<Text style={[Styles.textDefault]}>{fileForm.length + dataFile.filter((val) => !val.delete).length} file</Text>
</View>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, Styles.mb10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
dataFile.filter((val) => !val.delete).map((item, index) => (
<BorderBottomItem
key={index}
borderType={dataFile.filter((val) => !val.delete).length - 1 == index && fileForm.length == 0 ? "none" : "bottom"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name + '.' + item.extension}
titleWeight="normal"
bgColor="transparent"
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
/>
))
}
{
fileForm.map((item, index) => (
<BorderBottomItem
key={index}
borderType={fileForm.length - 1 == index ? "none" : "bottom"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name}
titleWeight="normal"
bgColor="transparent"
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
/>
))
}
</View>
</>
}
</View>
</ScrollView>

View File

@@ -11,8 +11,9 @@ import { apiGetDiscussionGeneral } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { AntDesign, Feather, Ionicons, MaterialIcons } from "@expo/vector-icons";
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
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 { useSelector } from "react-redux";
@@ -32,74 +33,80 @@ export default function Discussion() {
const { colors } = useTheme();
const { active, group } = useLocalSearchParams<{ active?: string, group?: string }>()
const [search, setSearch] = useState('')
const [nameGroup, setNameGroup] = useState('')
const [data, setData] = useState<Props[]>([])
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
const [loading, setLoading] = useState(true)
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [status, setStatus] = useState<'true' | 'false'>('true')
const [page, setPage] = useState(1)
const [waiting, setWaiting] = useState(false)
const queryClient = useQueryClient()
const [status, setStatus] = useState<'true' | 'false'>(active == 'false' ? 'false' : 'true')
const [refreshing, setRefreshing] = useState(false)
async function handleLoad(loading: boolean, thisPage: number) {
try {
setWaiting(true)
setLoading(loading)
setPage(thisPage)
// TanStack Query for Discussions with Infinite Scroll
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
isLoading,
refetch
} = useInfiniteQuery({
queryKey: ['discussions', { status, search, group }],
queryFn: async ({ pageParam = 1 }) => {
const hasil = await decryptToken(String(token?.current))
const response = await apiGetDiscussionGeneral({ user: hasil, active: status, search: search, group: String(group), page: thisPage })
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)
}
}
const response = await apiGetDiscussionGeneral({
user: hasil,
active: status,
search: search,
group: String(group),
page: pageParam
})
return response;
},
initialPageParam: 1,
getNextPageParam: (lastPage, allPages) => {
return lastPage.data.length > 0 ? allPages.length + 1 : undefined;
},
enabled: !!token?.current,
staleTime: 0,
})
// Flatten pages into a single data array
const flatData = useMemo(() => {
return data?.pages.flatMap(page => page.data) || [];
}, [data])
// Get nameGroup from the first available page
const nameGroup = useMemo(() => {
return data?.pages[0]?.filter?.name || "";
}, [data])
// Refetch when manual update state changes
useEffect(() => {
handleLoad(false, 1)
}, [update])
useEffect(() => {
handleLoad(true, 1)
}, [status, search, group])
const loadMoreData = () => {
if (waiting) return
setTimeout(() => {
handleLoad(false, page + 1)
}, 1000);
};
refetch()
}, [update, refetch])
const handleRefresh = async () => {
setRefreshing(true)
handleLoad(false, 1)
await new Promise(resolve => setTimeout(resolve, 2000));
await queryClient.invalidateQueries({ queryKey: ['discussions'] })
setRefreshing(false)
};
const loadMoreData = () => {
if (hasNextPage && !isFetchingNextPage) {
fetchNextPage()
}
};
const arrSkeleton = [0, 1, 2, 3, 4]
const getItem = (_data: unknown, index: number): Props => ({
id: data[index].id,
title: data[index].title,
desc: data[index].desc,
status: data[index].status,
total_komentar: data[index].total_komentar,
createdAt: data[index].createdAt,
id: flatData[index]?.id,
title: flatData[index]?.title,
desc: flatData[index]?.desc,
status: flatData[index]?.status,
total_komentar: flatData[index]?.total_komentar,
createdAt: flatData[index]?.createdAt,
})
return (
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
<View>
{
entityUser.role != "user" && entityUser.role != "coadmin" &&
@@ -130,20 +137,20 @@ export default function Discussion() {
</View>
}
</View>
<View style={[{ flex: 2 }, Styles.mt05]}>
<View style={[Styles.flex2, Styles.mt05]}>
{
loading ?
isLoading ?
arrSkeleton.map((item: any, i: number) => {
return (
<SkeletonContent key={i} />
)
})
:
data.length > 0
flatData.length > 0
?
<VirtualizedList
data={data}
getItemCount={() => data.length}
data={flatData}
getItemCount={() => flatData.length}
getItem={getItem}
renderItem={({ item, index }: { item: Props, index: number }) => {
return (
@@ -153,20 +160,18 @@ export default function Discussion() {
onPress={() => { router.push(`/discussion/${item.id}`) }}
borderType="bottom"
icon={
<View style={[Styles.iconContent]}>
<MaterialIcons name="chat" size={25} color={'black'} />
</View>
<MaterialIcons name="chat" size={25} color={colors.text} />
}
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, ' ')}
desc={item.desc?.replace(/<[^>]*>?/gm, ' ').replace(/\r?\n|\r/g, ' ')}
leftBottomInfo={
<View style={[Styles.rowItemsCenter]}>
<Ionicons name="chatbox-ellipses-outline" size={18} color={colors.dimmed} style={Styles.mr05} />
<Text style={[Styles.textInformation, {color: colors.dimmed}, Styles.mb05]}>Diskusikan</Text>
<Text style={[Styles.textInformation, { color: colors.dimmed }, Styles.mb05]}>Diskusikan</Text>
</View>
}
rightBottomInfo={`${item.total_komentar} Komentar`}
@@ -182,12 +187,12 @@ export default function Discussion() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
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>

View File

@@ -1,9 +1,9 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi";
import AppHeader from "@/components/AppHeader";
import BorderBottomItem from "@/components/borderBottomItem";
import DrawerBottom from "@/components/drawerBottom";
import ImageUser from "@/components/imageNew";
import MenuItemRow from "@/components/menuItemRow";
import ModalConfirmation from "@/components/ModalConfirmation";
import SkeletonTwoItem from "@/components/skeletonTwoItem";
import Text from '@/components/Text';
import { ColorsStatus } from "@/constants/ColorsStatus";
@@ -36,6 +36,8 @@ export default function MemberDiscussionDetail() {
const update = useSelector((state: any) => state.discussionGeneralDetailUpdate)
const [loading, setLoading] = useState(true)
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [showDeleteModal, setShowDeleteModal] = useState(false)
async function handleLoad(loading: boolean) {
try {
@@ -65,15 +67,18 @@ export default function MemberDiscussionDetail() {
await apiDeleteMemberDiscussionGeneral({ user: hasil, idUser: chooseUser.idUser }, id)
Toast.show({ type: 'small', text1: 'Berhasil mengeluarkan anggota dari diskusi', })
handleLoad(false)
} catch (error) {
console.error(error)
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengeluarkan anggota"
Toast.show({ type: 'small', text1: message })
} finally {
setModal(false)
}
}
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
@@ -88,7 +93,7 @@ export default function MemberDiscussionDetail() {
)
}}
/>
<ScrollView style={{ backgroundColor: colors.background }}>
<ScrollView style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}>
<View style={[Styles.p15]}>
<Text style={[Styles.textDefault, Styles.mv05]}>{data.length} Anggota</Text>
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
@@ -151,20 +156,28 @@ export default function MemberDiscussionDetail() {
title="Keluarkan"
onPress={() => {
setModal(false)
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah Anda yakin ingin mengeluarkan anggota?',
onPress: () => {
handleDeleteUser()
}
})
setTimeout(() => {
setShowDeleteModal(true)
}, 600)
}}
/>
}
</View>
</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>
)
}

View File

@@ -92,9 +92,11 @@ export default function AddMemberCalendarEvent() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan anggota"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -156,7 +158,7 @@ export default function AddMemberCalendarEvent() {
</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
showsVerticalScrollIndicator={false}
@@ -169,7 +171,7 @@ export default function AddMemberCalendarEvent() {
return (
<Pressable
key={index}
style={[Styles.itemSelectModal]}
style={[Styles.itemSelectModal, {borderColor: colors.icon + '20'}]}
onPress={() => {
!found && onChoose(item.idUser, item.name, item.img)
}}
@@ -179,7 +181,7 @@ export default function AddMemberCalendarEvent() {
<View style={[Styles.ml10, { width: '80%' }]}>
<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 File

@@ -57,9 +57,11 @@ export default function EditEventCalendar() {
setData({ ...response.data, dateStart: moment(response.data.dateStartFormat, 'DD-MM-YYYY').format('DD-MM-YYYY') })
setIdCalendar(response.data.idCalendar)
setChoose({ val: response.data.repeatEventTyper, label: valueTypeEventRepeat.find((item) => item.id == response.data.repeatEventTyper)?.name || "" })
} catch (error) {
} catch (error: any) {
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 })
}
}
@@ -154,9 +156,11 @@ export default function EditEventCalendar() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengubah acara"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}

View File

@@ -1,4 +1,4 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi"
import ModalConfirmation from "@/components/ModalConfirmation"
import AppHeader from "@/components/AppHeader"
import BorderBottomItem from "@/components/borderBottomItem"
import ButtonBackHeader from "@/components/buttonBackHeader"
@@ -57,6 +57,7 @@ export default function DetailEventCalendar() {
const dispatch = useDispatch()
const entityUser = useSelector((state: any) => state.user);
const [isMemberDivision, setIsMemberDivision] = useState(false);
const [showDeleteModal, setShowDeleteModal] = useState(false)
const [loading, setLoading] = useState(true)
const [refreshing, setRefreshing] = useState(false)
@@ -136,9 +137,11 @@ export default function DetailEventCalendar() {
dispatch(setUpdateCalendar({ ...update, member: !update.member }));
}
Toast.show({ type: 'small', text1: response.message, })
} catch (error) {
} catch (error: any) {
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 {
setModalMember(false)
}
@@ -179,6 +182,7 @@ export default function DetailEventCalendar() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
>
@@ -301,18 +305,26 @@ export default function DetailEventCalendar() {
title="Keluarkan"
onPress={() => {
setModalMember(false)
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah Anda yakin ingin mengeluarkan anggota?',
onPress: () => {
handleDeleteUser()
}
})
setTimeout(() => {
setShowDeleteModal(true)
}, 600)
}}
/>
</View>
</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>
)
}

View File

@@ -83,9 +83,11 @@ export default function CreateCalendarAddMember() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal membuat acara"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -143,7 +145,7 @@ export default function CreateCalendarAddMember() {
</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
showsVerticalScrollIndicator={false}
@@ -156,7 +158,7 @@ export default function CreateCalendarAddMember() {
return (
<Pressable
key={index}
style={[Styles.itemSelectModal]}
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
onPress={() => { onChoose(item.idUser, item.name, item.img) }}
>
<View style={[Styles.rowItemsCenter, Styles.w70]}>

View File

@@ -1,7 +1,6 @@
import InputSearch from "@/components/inputSearch";
import Skeleton from "@/components/skeleton";
import Text from "@/components/Text";
import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { apiGetCalendarHistory } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
@@ -70,7 +69,7 @@ export default function CalendarHistory() {
<View>
<InputSearch onChange={(val) => setSearch(val)} />
</View>
<View style={[{ flex: 2, }]}>
<View style={[{ flex: 2 }, Styles.mt10]}>
{
loading ?
arrSkeleton.map((item, index) => (
@@ -83,7 +82,7 @@ export default function CalendarHistory() {
getItem={getItem}
renderItem={({ item, index }: { item: Props, index: number }) => {
return (
<View key={index} style={[{ flexDirection: 'row' }, Styles.mv05, activeTheme === 'dark' ? { backgroundColor: colors.card } : ColorsStatus.lightGreen, Styles.p10, Styles.round10, { borderBottomWidth: 1, borderColor: colors.background }]}>
<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]}>
<Text style={[Styles.textSubtitle]}>{String(item.dateStart)}</Text>
<Text style={[Styles.textDefault, { textAlign: 'center' }]}>{item.year}</Text>
@@ -91,7 +90,7 @@ export default function CalendarHistory() {
<View style={[{ flex: 1 }]}>
<FlatList data={item.data}
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.textDefault]}>{item.timeStart} | {item.timeEnd}</Text>
</View>

View File

@@ -155,6 +155,7 @@ export default function CalendarDivision() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
style={[Styles.h100]}
@@ -204,7 +205,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 File

@@ -4,7 +4,7 @@ import ButtonSaveHeader from "@/components/buttonSaveHeader";
import ButtonSelect from "@/components/buttonSelect";
import DrawerBottom from "@/components/drawerBottom";
import { InputForm } from "@/components/inputForm";
import LoadingOverlay from "@/components/loadingOverlay";
import LoadingCenter from "@/components/loadingCenter";
import MenuItemRow from "@/components/menuItemRow";
import Text from "@/components/Text";
import Styles from "@/constants/Styles";
@@ -89,9 +89,11 @@ export default function DiscussionDivisionEdit() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error: any) {
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 {
setLoading(false)
}
@@ -168,7 +170,7 @@ export default function DiscussionDivisionEdit() {
)
}}
/>
<LoadingOverlay visible={loading} />
{loading && <LoadingCenter />}
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
<View style={[Styles.p15]}>
<InputForm
@@ -186,33 +188,38 @@ export default function DiscussionDivisionEdit() {
{
(fileForm.length > 0 || dataFile.filter((val) => !val.delete).length > 0)
&&
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10, { borderColor: colors.background, backgroundColor: colors.card }]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
{
dataFile.filter((val) => !val.delete).map((item, index) => (
<BorderBottomItem
key={index}
borderType={(fileForm.length + dataFile.length) > 1 ? "bottom" : "none"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name + '.' + item.extension}
titleWeight="normal"
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
/>
))
}
{
fileForm.map((item, index) => (
<BorderBottomItem
key={index}
borderType={fileForm.length > 1 ? "bottom" : "none"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name}
titleWeight="normal"
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
/>
))
}
</View>
<>
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
<Text style={[Styles.textDefault]}>{fileForm.length + dataFile.filter((val) => !val.delete).length} file</Text>
</View>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, Styles.mb10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
dataFile.filter((val) => !val.delete).map((item, index) => (
<BorderBottomItem
key={index}
borderType={dataFile.filter((val) => !val.delete).length - 1 == index && fileForm.length == 0 ? "none" : "bottom"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name + '.' + item.extension}
titleWeight="normal"
onPress={() => { setIndexDelFile({ id: item.id, cat: "oldFile" }); setModalFile(true) }}
/>
))
}
{
fileForm.map((item, index) => (
<BorderBottomItem
key={index}
borderType={fileForm.length - 1 == index ? "none" : "bottom"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name}
titleWeight="normal"
onPress={() => { setIndexDelFile({ id: index, cat: "newFile" }); setModalFile(true) }}
/>
))
}
</View>
</>
}
</View>
</ScrollView>

View File

@@ -1,4 +1,3 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi";
import AppHeader from "@/components/AppHeader";
import BorderBottomItem from "@/components/borderBottomItem";
import BorderBottomItem2 from "@/components/borderBottomItem2";
@@ -8,6 +7,7 @@ import ImageUser from "@/components/imageNew";
import { InputForm } from "@/components/inputForm";
import LabelStatus from "@/components/labelStatus";
import MenuItemRow from "@/components/menuItemRow";
import ModalConfirmation from "@/components/ModalConfirmation";
import Skeleton from "@/components/skeleton";
import SkeletonContent from "@/components/skeletonContent";
import Text from "@/components/Text";
@@ -23,9 +23,9 @@ import {
} from "@/lib/api";
import { getDB } from "@/lib/firebaseDatabase";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { Feather, Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
import { ref } from "@react-native-firebase/database";
import { useTheme } from "@/providers/ThemeProvider";
import { useHeaderHeight } from '@react-navigation/elements';
import { router, Stack, useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
@@ -92,6 +92,7 @@ export default function DiscussionDetail() {
comment: ''
})
const [viewEdit, setViewEdit] = useState(false)
const [showDeleteModal, setShowDeleteModal] = useState(false)
@@ -201,8 +202,11 @@ export default function DiscussionDetail() {
setKomentar("")
updateTrigger()
}
} catch (error) {
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan komentar"
Toast.show({ type: 'small', text1: message })
} finally {
setLoadingSend(false);
}
@@ -221,8 +225,11 @@ export default function DiscussionDetail() {
} else {
Toast.show({ type: 'small', text1: response.message })
}
} catch (error) {
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengedit komentar"
Toast.show({ type: 'small', text1: message })
} finally {
setLoadingSend(false);
handleViewEditKomentar()
@@ -242,8 +249,11 @@ export default function DiscussionDetail() {
} else {
Toast.show({ type: 'small', text1: response.message })
}
} catch (error) {
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menghapus komentar"
Toast.show({ type: 'small', text1: message })
} finally {
setLoadingSend(false)
setVisible(false)
@@ -297,7 +307,7 @@ export default function DiscussionDetail() {
showBack={true}
onPressLeft={() => router.back()}
right={
(entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision || isCreator ?
((entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision || isCreator) ?
<HeaderRightDiscussionDetail
id={detail}
status={data?.status}
@@ -314,6 +324,7 @@ export default function DiscussionDetail() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
>
@@ -325,7 +336,8 @@ export default function DiscussionDetail() {
<BorderBottomItem2
dataFile={fileDiscussion}
descEllipsize={false}
borderType="bottom"
bgColor="white"
borderType="all"
icon={
<ImageUser
src={`${ConstEnv.url_storage}/files/${data?.user_img}`}
@@ -354,7 +366,7 @@ export default function DiscussionDetail() {
color="grey"
style={Styles.mr05}
/>
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]} >
<Text style={[Styles.textInformation, { color: colors.dimmed }, Styles.mb05]} >
{dataComment.length} Komentar
</Text>
</View>
@@ -362,7 +374,7 @@ export default function DiscussionDetail() {
/>
}
<View style={[Styles.p15]}>
<View style={[Styles.mt10]}>
{
loadingKomentar ?
arrSkeleton.map((item, index) => (
@@ -372,7 +384,7 @@ export default function DiscussionDetail() {
dataComment.map((item, index) => (
<BorderBottomItem
key={index}
borderType="bottom"
borderType="all"
colorPress
icon={
<ImageUser
@@ -385,6 +397,7 @@ export default function DiscussionDetail() {
desc={item.comment}
rightBottomInfo={item.isEdited ? "Edited" : ""}
descEllipsize={detailMore.includes(item.id) ? false : true}
bgColor="white"
onPress={() => {
setDetailMore((prev: any) => {
if (prev.includes(item.id)) {
@@ -462,8 +475,8 @@ export default function DiscussionDetail() {
size={25}
style={
[selectKomentar.comment == "" || regexOnlySpacesOrEnter.test(selectKomentar.comment) || loadingSend || ((entityUser.role == "user" || entityUser.role == "coadmin") && !isMemberDivision)
? Styles.cGray
: Styles.cDefault,
? { color: colors.dimmed }
: { color: colors.tint },
]
}
/>
@@ -476,7 +489,6 @@ export default function DiscussionDetail() {
isMemberDivision)
?
<InputForm
bg={colors.card}
type="default"
round
multiline
@@ -509,8 +521,8 @@ export default function DiscussionDetail() {
size={25}
style={
[komentar == "" || regexOnlySpacesOrEnter.test(komentar) || loadingSend || ((entityUser.role == "user" || entityUser.role == "coadmin") && !isMemberDivision)
? Styles.cGray
: Styles.cDefault,
? { color: colors.dimmed }
: { color: colors.tint }
]
}
/>
@@ -519,7 +531,7 @@ export default function DiscussionDetail() {
/>
:
<View style={[Styles.pv20, { alignItems: 'center' }]}>
<Text style={[Styles.textInformation, Styles.cGray]}>
<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"
}
@@ -541,17 +553,27 @@ export default function DiscussionDetail() {
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
title="Hapus"
onPress={() => {
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah anda yakin ingin menghapus komentar?',
onPress: () => {
handleDeleteKomentar()
}
})
setVisible(false)
setTimeout(() => {
setShowDeleteModal(true)
}, 600)
}}
/>
</View>
</DrawerBottom>
<ModalConfirmation
visible={showDeleteModal}
title="Konfirmasi"
message="Apakah anda yakin ingin menghapus komentar?"
onConfirm={() => {
setShowDeleteModal(false)
handleDeleteKomentar()
}}
onCancel={() => setShowDeleteModal(false)}
confirmText="Hapus"
cancelText="Batal"
/>
</>
);
}

View File

@@ -4,7 +4,7 @@ import ButtonSaveHeader from "@/components/buttonSaveHeader"
import ButtonSelect from "@/components/buttonSelect"
import DrawerBottom from "@/components/drawerBottom"
import { InputForm } from "@/components/inputForm"
import LoadingOverlay from "@/components/loadingOverlay"
import LoadingCenter from "@/components/loadingCenter"
import MenuItemRow from "@/components/menuItemRow"
import Text from "@/components/Text"
import Styles from "@/constants/Styles"
@@ -81,9 +81,11 @@ export default function CreateDiscussionDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -119,7 +121,7 @@ export default function CreateDiscussionDivision() {
)
}}
/>
<LoadingOverlay visible={loading} />
{loading && <LoadingCenter />}
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
<View style={[Styles.p15, Styles.mb100]}>
<InputForm
@@ -135,21 +137,27 @@ export default function CreateDiscussionDivision() {
{
fileForm.length > 0
&&
<View style={[Styles.borderAll, Styles.round10, Styles.p10, Styles.mb10, { borderColor: colors.background, backgroundColor: colors.card }]}>
<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={colors.text} />}
title={item.name}
titleWeight="normal"
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
/>
))
}
</View>
<>
<View style={[Styles.rowSpaceBetween, Styles.mv05]}>
<Text style={[Styles.textDefaultSemiBold]}>File</Text>
<Text style={[Styles.textDefault]}>{fileForm.length} file</Text>
</View>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, Styles.mb10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
{
fileForm.map((item, index) => (
<BorderBottomItem
key={index}
borderType={fileForm.length - 1 == index ? "none" : "bottom"}
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
title={item.name}
titleWeight="normal"
onPress={() => { setIndexDelFile(index); setModalFile(true) }}
/>
))
}
</View>
</>
}
</View>
</ScrollView>

View File

@@ -177,7 +177,7 @@ export default function DiscussionDivision() {
onPress={() => { router.push(`./discussion/${item.id}`) }}
borderType="bottom"
icon={
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="sm" />
<ImageUser src={`${ConstEnv.url_storage}/files/${item.img}`} size="xs" />
}
title={item.user_name}
subtitle={
@@ -187,11 +187,12 @@ export default function DiscussionDivision() {
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>
<Ionicons name="chatbox-ellipses-outline" size={18} color={colors.dimmed} style={Styles.mr05} />
<Text style={[Styles.textInformation, { color: colors.dimmed }, Styles.mb05]}>Diskusikan</Text>
</View>
}
rightBottomInfo={item.total_komentar + ' Komentar'}
bgColor="transparent"
/>
)
}}
@@ -203,11 +204,12 @@ export default function DiscussionDivision() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
/>
:
(<Text style={[Styles.textDefault, Styles.cGray, Styles.mv10, { textAlign: "center" }]}>Tidak ada diskusi</Text>)
(<Text style={[Styles.textDefault, Styles.mv10, { textAlign: "center", color: colors.dimmed }]}>Tidak ada diskusi</Text>)
}
</View>
</View>

View File

@@ -1,4 +1,4 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi";
import ModalConfirmation from "@/components/ModalConfirmation";
import AppHeader from "@/components/AppHeader";
import { ButtonHeader } from "@/components/buttonHeader";
import HeaderRightDocument from "@/components/document/headerDocument";
@@ -12,7 +12,6 @@ import ModalLoading from "@/components/modalLoading";
import ModalSelectMultiple from "@/components/modalSelectMultiple";
import Skeleton from "@/components/skeleton";
import Text from "@/components/Text";
import { ColorsStatus } from "@/constants/ColorsStatus";
import { ConstEnv } from "@/constants/ConstEnv";
import Styles from "@/constants/Styles";
import {
@@ -90,6 +89,7 @@ export default function DocumentDivision() {
const [loadingOpen, setLoadingOpen] = useState(false)
const [isMemberDivision, setIsMemberDivision] = useState(false)
const entityUser = useSelector((state: any) => state.user)
const [showDeleteModal, setShowDeleteModal] = useState(false)
const [bodyRename, setBodyRename] = useState({
id: "",
name: "",
@@ -235,9 +235,11 @@ export default function DocumentDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoadingRename(false)
setRename(false)
@@ -258,9 +260,11 @@ export default function DocumentDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
console.error(error);
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
const message = error?.response?.data?.message || "Gagal menghapus"
Toast.show({ type: 'small', text1: message })
}
}
@@ -284,9 +288,11 @@ export default function DocumentDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setShare(false);
}
@@ -382,7 +388,7 @@ export default function DocumentDivision() {
showBack={(selectedFiles.length > 0 || dariSelectAll) ? false : true}
left={
<ButtonHeader
item={<MaterialIcons name="close" size={20} color="white" />}
item={<MaterialIcons name="close" size={25} color="white" />}
onPress={() => {
handleBatal();
}}
@@ -395,7 +401,7 @@ export default function DocumentDivision() {
selectedFiles.length > 0 || dariSelectAll ? (
<ButtonHeader
item={
<MaterialIcons name="checklist-rtl" size={20} color="white" />
<MaterialIcons name="checklist-rtl" size={25} color="white" />
}
onPress={() => {
handleSelectAll();
@@ -415,6 +421,7 @@ export default function DocumentDivision() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}>
<View style={[Styles.p15, Styles.mb100]}>
@@ -480,14 +487,7 @@ export default function DocumentDivision() {
);
})
) : (
<Text
style={[
Styles.textDefault,
Styles.cGray,
Styles.mt15,
{ textAlign: "center" },
]}
>
<Text style={[Styles.textDefault, Styles.mt15, { textAlign: "center", color: colors.dimmed }]} >
Tidak ada dokumen
</Text>
)}
@@ -495,7 +495,7 @@ export default function DocumentDivision() {
</View>
</ScrollView>
{(selectedFiles.length > 0 || dariSelectAll) && (
<View style={[ColorsStatus.primary, Styles.bottomMenuSelectDocument]}>
<View style={[Styles.bottomMenuSelectDocument, { backgroundColor: colors.header }]}>
<View style={[Styles.rowItemsCenter, { justifyContent: "center" }]}>
<MenuItemRow
icon={
@@ -507,13 +507,7 @@ export default function DocumentDivision() {
}
title="Hapus"
onPress={() => {
AlertKonfirmasi({
title: "Konfirmasi",
desc: "Apakah anda yakin ingin menghapus dokumen?",
onPress: () => {
handleDelete();
},
});
setShowDeleteModal(true)
}}
column="many"
color="white"
@@ -620,6 +614,19 @@ export default function DocumentDivision() {
value={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>
);
}

View File

@@ -120,9 +120,11 @@ export default function TaskDivisionAddFile() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}

View File

@@ -86,9 +86,11 @@ export default function AddMemberTask() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan anggota"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -151,7 +153,7 @@ export default function AddMemberTask() {
</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
showsVerticalScrollIndicator={false}
@@ -164,17 +166,17 @@ export default function AddMemberTask() {
return (
<Pressable
key={index}
style={[Styles.itemSelectModal]}
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
onPress={() => {
!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 />
<View style={[Styles.ml10]}>
<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 File

@@ -1,5 +1,6 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import ButtonSelect from "@/components/buttonSelect";
import { InputForm } from "@/components/inputForm";
import ModalAddDetailTugasTask from "@/components/task/modalAddDetailTugasTask";
import Text from "@/components/Text";
@@ -17,7 +18,8 @@ import 'intl/locale-data/jsonp/id';
import moment from "moment";
import { useEffect, useState } from "react";
import {
KeyboardAvoidingView, Platform, Pressable, SafeAreaView,
KeyboardAvoidingView, Platform,
SafeAreaView,
ScrollView,
View
} from "react-native";
@@ -131,9 +133,11 @@ export default function TaskDivisionAddTask() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}
@@ -209,31 +213,32 @@ export default function TaskDivisionAddTask() {
<View style={[Styles.rowSpaceBetween]}>
<View style={[{ width: "48%" }]}>
<Text style={[Styles.mb05]}>
Tanggal Mulai <Text style={Styles.cError}>*</Text>
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={{ textAlign: "center" }}>{from}</Text>
</View>
</View>
<View style={[{ width: "48%" }]}>
<Text style={[Styles.mb05]}>
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={{ textAlign: "center" }}>{to}</Text>
</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]}
disabled={dsbButton}
onPress={() => { setModalDetail(true) }}
>
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
</Pressable>
</Pressable> */}
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} />
</View>
<InputForm
label="Judul Tugas"

View File

@@ -62,9 +62,11 @@ export default function TaskDivisionCancel() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}

View File

@@ -80,9 +80,11 @@ export default function TaskDivisionEdit() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}

View File

@@ -127,6 +127,7 @@ export default function DetailTaskDivision() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
>

View File

@@ -80,16 +80,18 @@ export default function TaskDivisionReport() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}
}
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (

View File

@@ -105,9 +105,11 @@ export default function CreateTaskDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -198,7 +200,7 @@ export default function CreateTaskDivision() {
<Text>Total {entitiesMember.length} Anggota</Text>
</View>
<View style={[Styles.borderAll, Styles.round10, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
{entitiesMember.map(
(item: { img: any; name: any }, index: any) => {
return (

View File

@@ -121,7 +121,7 @@ export default function AddMemberCreateTask() {
</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
showsVerticalScrollIndicator={false}
@@ -133,7 +133,7 @@ export default function AddMemberCreateTask() {
return (
<Pressable
key={index}
style={[Styles.itemSelectModal]}
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
onPress={() => {
onChoose(item.idUser, item.name, item.img)
}}

View File

@@ -1,6 +1,6 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import { useTheme } from "@/providers/ThemeProvider";
import ButtonSelect from "@/components/buttonSelect";
import { InputForm } from "@/components/inputForm";
import ModalAddDetailTugasTask from "@/components/task/modalAddDetailTugasTask";
import Text from "@/components/Text";
@@ -8,6 +8,7 @@ import Styles from "@/constants/Styles";
import { formatDateOnly } from "@/lib/fun_formatDateOnly";
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
import { setTaskCreate } from "@/lib/taskCreate";
import { useTheme } from "@/providers/ThemeProvider";
import { useHeaderHeight } from '@react-navigation/elements';
import { router, Stack } from "expo-router";
import 'intl';
@@ -17,7 +18,6 @@ import { useEffect, useState } from "react";
import {
KeyboardAvoidingView,
Platform,
Pressable,
SafeAreaView,
ScrollView,
View
@@ -184,31 +184,32 @@ export default function CreateTaskAddTugas() {
<View style={[Styles.rowSpaceBetween]}>
<View style={[{ width: "48%" }]}>
<Text style={[Styles.mb05]}>
Tanggal Mulai <Text style={Styles.cError}>*</Text>
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={{ textAlign: "center" }}>{from}</Text>
</View>
</View>
<View style={[{ width: "48%" }]}>
<Text style={[Styles.mb05]}>
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={{ textAlign: "center" }}>{to}</Text>
</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]}
disabled={dsbButton}
onPress={() => { setModalDetail(true) }}
>
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
</Pressable>
</Pressable> */}
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} />
</View>
<InputForm
label="Judul Tugas"

View File

@@ -112,7 +112,7 @@ export default function ListTask() {
})
return (
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
<View>
<ScrollView horizontal style={[Styles.mb10]} showsHorizontalScrollIndicator={false}>
<ButtonTab
@@ -190,7 +190,7 @@ export default function ListTask() {
<View style={[Styles.mv05]}>
<View style={[Styles.rowOnly]}>
<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 style={[{ flex: 2 }]}>
@@ -235,6 +235,7 @@ export default function ListTask() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
/>
@@ -276,11 +277,11 @@ export default function ListTask() {
<LabelStatus
size="default"
category={
item.status === 0 ? 'primary' :
item.status === 0 ? 'secondary' :
item.status === 1 ? 'warning' :
item.status === 2 ? 'success' :
item.status === 3 ? 'error' :
'primary'
'secondary'
}
text={
item.status === 0 ? 'SEGERA' :
@@ -301,6 +302,7 @@ export default function ListTask() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
/>
@@ -340,13 +342,13 @@ export default function ListTask() {
</View>
)
) : (
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: "center" },]} >
<Text style={[Styles.textDefault, Styles.textCenter]} >
Tidak ada data
</Text>
)
}
</View>
</View>
</View >
</View >
);
}

View File

@@ -1,15 +1,16 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import ButtonSelect from "@/components/buttonSelect";
import { InputForm } from "@/components/inputForm";
import ModalAddDetailTugasTask from "@/components/task/modalAddDetailTugasTask";
import Text from "@/components/Text";
import Styles from "@/constants/Styles";
import { useTheme } from "@/providers/ThemeProvider";
import { apiEditTaskTugas, apiGetTaskTugas } from "@/lib/api";
import { formatDateOnly } from "@/lib/fun_formatDateOnly";
import { getDatesInRange } from "@/lib/fun_getDatesInRange";
import { setUpdateTask } from "@/lib/taskUpdate";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { useHeaderHeight } from '@react-navigation/elements';
import { router, Stack, useLocalSearchParams } from "expo-router";
import 'intl';
@@ -19,7 +20,6 @@ import { useEffect, useState } from "react";
import {
KeyboardAvoidingView,
Platform,
Pressable,
SafeAreaView,
ScrollView,
View
@@ -125,9 +125,11 @@ export default function UpdateProjectTaskDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoadingSubmit(false)
}
@@ -261,33 +263,34 @@ export default function UpdateProjectTaskDivision() {
<View style={[Styles.rowSpaceBetween]}>
<View style={[{ width: "48%" }]}>
<Text style={[Styles.mb05]}>
Tanggal Mulai <Text style={Styles.cError}>*</Text>
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={{ textAlign: "center" }}>{from}</Text>
</View>
</View>
<View style={[{ width: "48%" }]}>
<Text style={[Styles.mb05]}>
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={{ textAlign: "center" }}>{to}</Text>
</View>
</View>
</View>
{(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
</Text>
)}
<Pressable
{/* <Pressable
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
disabled={dsbButton}
onPress={() => { setModalDetail(true) }}
>
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
</Pressable>
</Pressable> */}
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} />
</View>
<InputForm
label="Judul Tugas"

View File

@@ -89,9 +89,11 @@ export default function AddMemberDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan anggota"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -154,7 +156,7 @@ export default function AddMemberDivision() {
</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
showsVerticalScrollIndicator={false}
@@ -177,7 +179,7 @@ export default function AddMemberDivision() {
<View style={[Styles.ml10]}>
<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 File

@@ -56,9 +56,11 @@ export default function EditDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengubah data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}

View File

@@ -78,6 +78,7 @@ export default function DetailDivisionFitur() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
showsVerticalScrollIndicator={false}

View File

@@ -1,4 +1,4 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi"
import ModalConfirmation from "@/components/ModalConfirmation"
import AppHeader from "@/components/AppHeader"
import BorderBottomItem from "@/components/borderBottomItem"
import HeaderRightDivisionInfo from "@/components/division/headerDivisionInfo"
@@ -13,8 +13,8 @@ import { ConstEnv } from "@/constants/ConstEnv"
import Styles from "@/constants/Styles"
import { apiDeleteMemberDivision, apiGetDivisionOneDetail, apiGetDivisionOneFeature, apiUpdateStatusAdminDivision } from "@/lib/api"
import { useAuthSession } from "@/providers/AuthProvider"
import { Feather, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
import { useTheme } from "@/providers/ThemeProvider"
import { Feather, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
import { router, Stack, useLocalSearchParams } from "expo-router"
import { useEffect, useState } from "react"
import { Pressable, RefreshControl, SafeAreaView, ScrollView, View } from "react-native"
@@ -59,14 +59,13 @@ export default function InformationDivision() {
name: '',
isAdmin: false
})
const [showDeleteModal, setShowDeleteModal] = useState(false)
function handleMemberOut() {
setModal(false)
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah anda yakin ingin mengeluarkan anggota?',
onPress: () => { memberOut() }
})
setTimeout(() => {
setShowDeleteModal(true)
}, 600)
}
async function memberOut() {
@@ -79,9 +78,11 @@ export default function InformationDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengeluarkan anggota"
Toast.show({ type: 'small', text1: message })
} finally {
setModal(false)
}
@@ -97,9 +98,11 @@ export default function InformationDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengubah status admin"
Toast.show({ type: 'small', text1: message })
} finally {
setModal(false)
}
@@ -187,6 +190,7 @@ export default function InformationDivision() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
style={[Styles.h100, { backgroundColor: colors.background }]}
@@ -199,7 +203,7 @@ export default function InformationDivision() {
}
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mb05]}>Deskripsi Divisi</Text>
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.wrapPaper, Styles.noShadow, { backgroundColor: colors.card, borderWidth: 1, borderColor: colors.icon + '20' }]}>
{loading ?
arrSkeleton.map((item, index) => {
return (
@@ -213,7 +217,7 @@ export default function InformationDivision() {
</View>
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefault, Styles.mv05]}>{dataMember.length} Anggota</Text>
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
<View style={[Styles.wrapPaper, Styles.noShadow, { backgroundColor: colors.card, borderWidth: 1, borderColor: colors.icon + '20' }]}>
{
((entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision) &&
dataDetail?.isActive && (
@@ -221,8 +225,8 @@ export default function InformationDivision() {
onPress={() => { router.push(`/division/${id}/add-member`) }}
borderType="none"
icon={
<View style={[Styles.iconContent, ColorsStatus.gray]}>
<Feather name="user-plus" size={25} color={colors.primary} />
<View style={[Styles.iconContent]}>
<Feather name="user-plus" size={25} color={'black'} />
</View>
}
title="Tambah Anggota"
@@ -262,8 +266,8 @@ export default function InformationDivision() {
<View>
<Pressable style={[Styles.wrapItemBorderBottom]} onPress={() => { handleMemberAdmin() }}>
<View style={[Styles.rowItemsCenter]}>
<View style={[Styles.iconContent, ColorsStatus.info]}>
<MaterialIcons name="verified-user" size={25} color={colors.primary} />
<View style={[Styles.iconContent]}>
<MaterialIcons name="verified-user" size={25} color={'black'} />
</View>
<View style={[Styles.rowSpaceBetween, { width: '88%' }]}>
<View style={[Styles.ml10]}>
@@ -287,6 +291,19 @@ export default function InformationDivision() {
</Pressable>
</View>
</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>
)
}

View File

@@ -94,8 +94,11 @@ export default function ReportDivision() {
} else {
Toast.show({ type: 'small', text1: response.message, });
}
} catch (error) {
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengambil data"
Toast.show({ type: 'small', text1: message })
}
}

View File

@@ -1,4 +1,4 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi";
import ModalConfirmation from "@/components/ModalConfirmation";
import AppHeader from "@/components/AppHeader";
import ButtonNextHeader from "@/components/buttonNextHeader";
import { InputForm } from "@/components/inputForm";
@@ -25,6 +25,7 @@ export default function CreateDivision() {
const entityUser = useSelector((state: any) => state.user)
const userLogin = useSelector((state: any) => state.entities)
const [loadingBtn, setLoadingBtn] = useState(false)
const [showWarningModal, setShowWarningModal] = useState(false)
const [error, setError] = useState({
idGroup: false,
name: false,
@@ -69,21 +70,18 @@ export default function CreateDivision() {
const response = await apiCheckDivisionName({ data: { ...dataForm }, user: hasil })
if (response.success) {
if (!response.available) {
AlertKonfirmasi({
title: 'Peringatan',
category: 'warning',
desc: 'Nama divisi sudah ada. Tidak dapat membuat divisi dengan nama yang sama',
onPress: () => { }
})
setShowWarningModal(true)
} else {
handleSetData()
}
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoadingBtn(false)
}
@@ -181,6 +179,15 @@ export default function CreateDivision() {
open={isSelect}
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>
);
}

View File

@@ -66,9 +66,11 @@ export default function CreateDivisionAddAdmin() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -125,7 +127,7 @@ export default function CreateDivisionAddAdmin() {
<View style={[Styles.ml10]}>
<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 File

@@ -108,7 +108,7 @@ export default function CreateDivisionAddMember() {
</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
showsVerticalScrollIndicator={false}
@@ -131,7 +131,7 @@ export default function CreateDivisionAddMember() {
<View style={[Styles.ml10]}>
<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 File

@@ -7,7 +7,6 @@ import Skeleton from "@/components/skeleton";
import SkeletonTwoItem from "@/components/skeletonTwoItem";
import Text from "@/components/Text";
import WrapTab from "@/components/wrapTab";
import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { apiGetDivision } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
@@ -16,11 +15,11 @@ import {
AntDesign,
Feather,
Ionicons,
MaterialCommunityIcons,
MaterialIcons,
MaterialCommunityIcons
} from "@expo/vector-icons";
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
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 { useSelector } from "react-redux";
@@ -42,23 +41,23 @@ export default function ListDivision() {
const { token, decryptToken } = useAuthSession()
const { colors } = useTheme();
const [search, setSearch] = useState("")
const [nameGroup, setNameGroup] = useState("")
const [data, setData] = useState<Props[]>([])
// ... state same ...
const queryClient = useQueryClient()
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 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)
async function handleLoad(loading: boolean, thisPage: number) {
try {
setWaiting(true)
setLoading(loading)
setPage(thisPage)
// TanStack Query for Divisions with Infinite Scroll
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
isLoading,
refetch
} = useInfiniteQuery({
queryKey: ['divisions', { status, search, group, category }],
queryFn: async ({ pageParam = 1 }) => {
const hasil = await decryptToken(String(token?.current));
const response = await apiGetDivision({
user: hasil,
@@ -66,54 +65,52 @@ export default function ListDivision() {
search: search,
group: String(group),
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) {
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)
}
}
// Refetch when manual update state changes
useEffect(() => {
handleLoad(false, 1);
}, [update]);
refetch()
}, [update, refetch])
useEffect(() => {
handleLoad(true, 1);
}, [status, search, group, category]);
// Flatten pages into a single data array
const flatData = useMemo(() => {
return data?.pages.flatMap(page => page.data) || [];
}, [data])
const loadMoreData = () => {
if (waiting) return
setTimeout(() => {
handleLoad(false, page + 1)
}, 1000);
};
// Get nameGroup from the first available page
const nameGroup = useMemo(() => {
return data?.pages[0]?.filter?.name || "";
}, [data])
const handleRefresh = async () => {
setRefreshing(true)
handleLoad(false, 1)
await new Promise(resolve => setTimeout(resolve, 2000));
await queryClient.invalidateQueries({ queryKey: ['divisions'] })
setRefreshing(false)
};
const loadMoreData = () => {
if (hasNextPage && !isFetchingNextPage) {
fetchNextPage()
}
};
const arrSkeleton = [0, 1, 2]
const getItem = (_data: unknown, index: number): Props => ({
id: data[index].id,
name: data[index].name,
desc: data[index].desc,
jumlah_member: data[index].jumlah_member,
id: flatData[index]?.id,
name: flatData[index]?.name,
desc: flatData[index]?.desc,
jumlah_member: flatData[index]?.jumlah_member,
})
@@ -206,9 +203,9 @@ export default function ListDivision() {
</View>
)}
</View>
<View style={[{ flex: 2 }, Styles.mt05]}>
<View style={[{ flex: 2 }, Styles.mt10]}>
{
loading ?
isLoading ?
isList ?
arrSkeleton.map((item, index) => (
<SkeletonTwoItem key={index} />
@@ -218,17 +215,17 @@ export default function ListDivision() {
<Skeleton key={index} width={100} height={180} widthType="percent" borderRadius={10} />
))
:
data.length == 0 ? (
flatData.length == 0 ? (
<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>
) : (
isList ? (
<View style={[Styles.h100]}>
<VirtualizedList
data={data}
data={flatData}
style={[{ paddingBottom: 100 }]}
getItemCount={() => data.length}
getItemCount={() => flatData.length}
getItem={getItem}
renderItem={({ item, index }: { item: Props, index: number }) => {
return (
@@ -236,14 +233,13 @@ export default function ListDivision() {
key={index}
onPress={() => { router.push(`/division/${item.id}`) }}
borderType="bottom"
bgColor={colors.card}
bgColor="transparent"
icon={
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
<MaterialIcons name="group" size={25} color={colors.primary} />
<View style={[Styles.iconContent]}>
<Feather name="users" size={25} color={'black'} />
</View>
}
title={item.name}
titleWeight="normal"
/>
)
}}
@@ -255,6 +251,7 @@ export default function ListDivision() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
/>
@@ -262,9 +259,9 @@ export default function ListDivision() {
) : (
<View style={[Styles.h100]}>
<VirtualizedList
data={data}
data={flatData}
style={[{ paddingBottom: 100 }]}
getItemCount={() => data.length}
getItemCount={() => flatData.length}
getItem={getItem}
renderItem={({ item, index }: { item: Props, index: number }) => {
return (
@@ -290,6 +287,7 @@ export default function ListDivision() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
/>

View File

@@ -112,8 +112,11 @@ export default function Report() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengambil data"
Toast.show({ type: 'small', text1: message })
}
}

View File

@@ -1,4 +1,4 @@
import ButtonBackHeader from "@/components/buttonBackHeader";
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import { InputForm } from "@/components/inputForm";
import ModalSelect from "@/components/modalSelect";
@@ -188,9 +188,14 @@ export default function EditProfile() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Gagal mengupdate data', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengupdate data"
Toast.show({
type: 'small',
text1: message
})
} finally {
setLoading(false)
}
@@ -216,27 +221,43 @@ export default function EditProfile() {
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
headerLeft: () => (
<ButtonBackHeader
onPress={() => {
router.back();
}}
/>
),
// headerLeft: () => (
// <ButtonBackHeader
// onPress={() => {
// router.back();
// }}
// />
// ),
headerTitle: "Edit Profile",
headerTitleAlign: "center",
headerRight: () => (
<ButtonSaveHeader
disable={disableBtn || loading ? true : false}
category="update"
onPress={() => {
handleEdit()
}}
header: () => (
<AppHeader
title="Edit Profile"
showBack={true}
onPressLeft={() => router.back()}
right={
<ButtonSaveHeader
disable={disableBtn || loading ? true : false}
category="update"
onPress={() => {
handleEdit()
}}
/>
}
/>
),
)
// headerRight: () => (
// <ButtonSaveHeader
// disable={disableBtn || loading ? true : false}
// category="update"
// onPress={() => {
// handleEdit()
// }}
// />
// ),
}}
/>
<KeyboardAvoidingView
@@ -246,7 +267,7 @@ export default function EditProfile() {
>
<ScrollView showsVerticalScrollIndicator={false}>
<View style={[Styles.p15]}>
<View style={{ justifyContent: "center", alignItems: "center" }}>
<View style={[Styles.contentItemCenter]}>
{
selectedImage != undefined ? (
<Pressable onPress={pickImageAsync}>

View File

@@ -1,4 +1,4 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi";
import ModalConfirmation from "@/components/ModalConfirmation";
import BorderBottomItem from "@/components/borderBottomItem";
import { ButtonForm } from "@/components/buttonForm";
import ButtonTab from "@/components/buttonTab";
@@ -9,14 +9,14 @@ import MenuItemRow from "@/components/menuItemRow";
import SkeletonTwoItem from "@/components/skeletonTwoItem";
import Text from "@/components/Text";
import WrapTab from "@/components/wrapTab";
import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { apiDeleteGroup, apiEditGroup, apiGetGroup } from "@/lib/api";
import { setUpdateGroup } from "@/lib/groupSlice";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { AntDesign, Feather, Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
import { useEffect, useState } from "react";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useEffect, useMemo, useState } from "react";
import { RefreshControl, View, VirtualizedList } from "react-native";
import Toast from "react-native-toast-message";
import { useDispatch, useSelector } from "react-redux";
@@ -32,15 +32,14 @@ export default function Index() {
const { colors } = useTheme();
const [isModal, setModal] = useState(false)
const [isVisibleEdit, setVisibleEdit] = useState(false)
const [data, setData] = useState<Props[]>([])
const [search, setSearch] = useState('')
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [loading, setLoading] = useState(true)
const [showDeleteModal, setShowDeleteModal] = useState(false)
const [status, setStatus] = useState<'true' | 'false'>('true')
const [loadingSubmit, setLoadingSubmit] = useState(false)
const [idChoose, setIdChoose] = useState('')
const [activeChoose, setActiveChoose] = useState(true)
const [titleChoose, setTitleChoose] = useState('')
const queryClient = useQueryClient()
const [refreshing, setRefreshing] = useState(false)
const dispatch = useDispatch()
@@ -49,12 +48,38 @@ export default function Index() {
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() {
try {
setLoadingSubmit(true)
const hasil = await decryptToken(String(token?.current))
const response = await apiEditGroup({ user: hasil, name: titleChoose }, idChoose)
await queryClient.invalidateQueries({ queryKey: ['groups'] })
dispatch(setUpdateGroup(!update))
} catch (error) {
console.error(error)
@@ -71,6 +96,7 @@ export default function Index() {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiDeleteGroup({ user: hasil, isActive: activeChoose }, idChoose)
await queryClient.invalidateQueries({ queryKey: ['groups'] })
dispatch(setUpdateGroup(!update))
} catch (error) {
console.error(error)
@@ -80,32 +106,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 () => {
setRefreshing(true)
handleLoad(false)
await new Promise(resolve => setTimeout(resolve, 2000));
await queryClient.invalidateQueries({ queryKey: ['groups'] })
setRefreshing(false)
};
@@ -129,6 +132,8 @@ export default function Index() {
const arrSkeleton = [0, 1, 2, 3, 4]
return (
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
<View style={[Styles.mb10]}>
@@ -150,9 +155,9 @@ export default function Index() {
</WrapTab>
<InputSearch onChange={setSearch} />
</View>
<View style={[{ flex: 2 }, Styles.mt05]}>
<View style={[{ flex: 2 }, Styles.mt10]}>
{
loading ?
isLoading ?
arrSkeleton.map((item, index) => {
return (
<SkeletonTwoItem key={index} />
@@ -190,12 +195,12 @@ export default function Index() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
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>
@@ -206,11 +211,9 @@ export default function Index() {
title={activeChoose ? "Non Aktifkan" : "Aktifkan"}
onPress={() => {
setModal(false)
AlertKonfirmasi({
title: 'Konfirmasi',
desc: activeChoose ? 'Apakah anda yakin ingin menonaktifkan data?' : 'Apakah anda yakin ingin mengaktifkan data?',
onPress: () => { handleDelete() }
})
setTimeout(() => {
setShowDeleteModal(true)
}, 600)
}}
/>
<MenuItemRow
@@ -245,6 +248,19 @@ export default function Index() {
</View>
</View>
</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 File

@@ -12,6 +12,7 @@ import { apiGetProfile } from "@/lib/api";
import { setEntities } from "@/lib/entitiesSlice";
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 { useEffect, useState } from "react";
@@ -23,33 +24,51 @@ import { useDispatch, useSelector } from "react-redux";
export default function Home() {
const entities = useSelector((state: any) => state.entities)
const dispatch = useDispatch()
const queryClient = useQueryClient()
const { token, decryptToken, signOut } = useAuthSession()
const { colors } = useTheme();
const insets = useSafeAreaInsets()
const [refreshing, setRefreshing] = useState(false)
useEffect(() => {
handleUserLogin()
}, [dispatch]);
const { data: profile, isError } = useQuery({
queryKey: ['profile'],
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() {
const hasil = await decryptToken(String(token?.current))
apiGetProfile({ id: hasil })
.then((data) => dispatch(setEntities(data.data)))
.catch((error) => {
signOut()
});
}
// Sync to Redux for global usage
useEffect(() => {
if (profile) {
dispatch(setEntities(profile))
}
}, [profile, dispatch])
// Auto Sign Out if profile fetch fails (e.g. invalid/expired token)
useEffect(() => {
if (isError) {
signOut()
}
}, [isError, signOut])
const handleRefresh = async () => {
setRefreshing(true)
handleUserLogin()
await new Promise(resolve => setTimeout(resolve, 2000));
// Invalidate all queries related to the home screen
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)
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
title: 'Home',
@@ -67,23 +86,25 @@ export default function Home() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
tintColor={colors.icon}
/>
}
showsVerticalScrollIndicator={false}
style={{ backgroundColor: colors.background }}
style={[Styles.h100, { backgroundColor: colors.background }]}
>
<LinearGradient
colors={[colors.header, colors.header, colors.header, colors.header, colors.homeGradient]}
style={{
position: 'absolute',
width: Dimensions.get('window').width * 1.5,
height: Dimensions.get('window').width * 1.5,
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,
zIndex: -1,
}}
style={[
Styles.posAbsolute,
Styles.zIndexMinus1,
{
width: Dimensions.get('window').width * 1.5,
height: Dimensions.get('window').width * 1.5,
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]}>

View File

@@ -55,9 +55,11 @@ export default function MemberDetail() {
} else {
Toast.show({ type: 'small', text1: response.message })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Gagal mengambil data' })
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengambil data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -77,7 +79,7 @@ export default function MemberDetail() {
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
headerTitle: 'Anggota',
@@ -99,7 +101,7 @@ export default function MemberDetail() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.text}
tintColor={colors.icon}
/>
}
>
@@ -119,7 +121,7 @@ export default function MemberDetail() {
<Pressable onPress={() => setPreview(true)}>
<ImageUser src={`${ConstEnv.url_storage}/files/${data?.img}`} size="lg" onError={setErrorImg} />
</Pressable>
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10, { textAlign: 'center' }]}>{data?.name}</Text>
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10, Styles.textCenter]}>{data?.name}</Text>
<Text style={[Styles.textMediumNormal, Styles.cWhite]}>{data?.role}</Text>
</>

View File

@@ -1,6 +1,7 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import { InputForm } from "@/components/inputForm";
import LoadingCenter from "@/components/loadingCenter";
import ModalSelect from "@/components/modalSelect";
import SelectForm from "@/components/selectForm";
import Text from "@/components/Text";
@@ -184,9 +185,11 @@ export default function CreateMember() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -208,7 +211,7 @@ export default function CreateMember() {
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
headerTitle: "Tambah Anggota",
@@ -228,6 +231,7 @@ export default function CreateMember() {
)
}}
/>
{loading && <LoadingCenter />}
<KeyboardAvoidingView
style={[Styles.h100, { backgroundColor: colors.background }]}
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
@@ -235,7 +239,7 @@ export default function CreateMember() {
>
<ScrollView showsVerticalScrollIndicator={false}>
<View style={[Styles.p15]}>
<View style={{ justifyContent: "center", alignItems: "center" }}>
<View style={[Styles.contentItemCenter]}>
{selectedImage != undefined ? (
<Pressable onPress={pickImageAsync}>
<Image src={selectedImage} style={[Styles.userProfileBig]} />

View File

@@ -1,6 +1,7 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import { InputForm } from "@/components/inputForm";
import LoadingCenter from "@/components/loadingCenter";
import ModalSelect from "@/components/modalSelect";
import SelectForm from "@/components/selectForm";
import Text from "@/components/Text";
@@ -210,9 +211,11 @@ export default function EditMember() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -238,7 +241,7 @@ export default function EditMember() {
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
headerTitle: "Edit Anggota",
@@ -261,7 +264,7 @@ export default function EditMember() {
)
}}
/>
{loading && <LoadingCenter />}
<KeyboardAvoidingView
style={[Styles.h100, { backgroundColor: colors.background }]}
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
@@ -269,7 +272,7 @@ export default function EditMember() {
>
<ScrollView showsVerticalScrollIndicator={false} style={[Styles.h100]}>
<View style={[Styles.p15]}>
<View style={{ justifyContent: "center", alignItems: "center" }}>
<View style={[Styles.contentItemCenter]}>
{
errorImg ?
<Pressable onPress={pickImageAsync}>

View File

@@ -12,8 +12,9 @@ import { apiGetUser } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
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 { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { RefreshControl, View, VirtualizedList } from "react-native";
import { useSelector } from "react-redux";
@@ -37,73 +38,81 @@ export default function Index() {
const entityUser = useSelector((state: any) => state.user)
const { colors } = useTheme();
const [search, setSearch] = useState('')
const [nameGroup, setNameGroup] = useState('')
const [data, setData] = useState<Props[]>([])
const update = useSelector((state: any) => state.memberUpdate)
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [loading, setLoading] = useState(true)
const [status, setStatus] = useState<'true' | 'false'>('true')
const [page, setPage] = useState(1)
const [waiting, setWaiting] = useState(false)
const queryClient = useQueryClient()
const [status, setStatus] = useState<'true' | 'false'>(active == 'false' ? 'false' : 'true')
const [refreshing, setRefreshing] = useState(false)
async function handleLoad(loading: boolean, thisPage: number) {
try {
setWaiting(true)
setLoading(loading)
setPage(thisPage)
// TanStack Query for Members with Infinite Scroll
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
isLoading,
refetch
} = useInfiniteQuery({
queryKey: ['members', { status, search, group }],
queryFn: async ({ pageParam = 1 }) => {
const hasil = await decryptToken(String(token?.current))
const response = await apiGetUser({ user: hasil, active: status, search, group: String(group), page: thisPage })
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)
}
}
const response = await apiGetUser({
user: hasil,
active: status,
search,
group: String(group),
page: pageParam
})
return response;
},
initialPageParam: 1,
getNextPageParam: (lastPage, allPages) => {
return lastPage.data.length > 0 ? allPages.length + 1 : undefined;
},
enabled: !!token?.current,
staleTime: 0,
})
const loadMoreData = () => {
if (waiting) return
setTimeout(() => {
handleLoad(false, page + 1)
}, 1000);
};
// Flatten pages into a single data array
const flatData = useMemo(() => {
return data?.pages.flatMap(page => page.data) || [];
}, [data])
// Get nameGroup from the first available page
const nameGroup = useMemo(() => {
return data?.pages[0]?.filter?.name || "";
}, [data])
// Refetch when manual update state changes
useEffect(() => {
handleLoad(false, 1)
}, [update])
useEffect(() => {
handleLoad(true, 1)
}, [group, search, status])
refetch()
}, [update, refetch])
const handleRefresh = async () => {
setRefreshing(true)
handleLoad(false, 1)
await new Promise(resolve => setTimeout(resolve, 2000));
await queryClient.invalidateQueries({ queryKey: ['members'] })
setRefreshing(false)
};
const loadMoreData = () => {
if (hasNextPage && !isFetchingNextPage) {
fetchNextPage()
}
};
const arrSkeleton = [0, 1, 2, 3, 4]
const getItem = (_data: unknown, index: number): Props => ({
id: data[index].id,
name: data[index].name,
nik: data[index].nik,
email: data[index].email,
phone: data[index].phone,
gender: data[index].gender,
position: data[index].position,
group: data[index].group,
img: data[index].img,
isActive: data[index].isActive,
role: data[index].role,
id: flatData[index]?.id,
name: flatData[index]?.name,
nik: flatData[index]?.nik,
email: flatData[index]?.email,
phone: flatData[index]?.phone,
gender: flatData[index]?.gender,
position: flatData[index]?.position,
group: flatData[index]?.group,
img: flatData[index]?.img,
isActive: flatData[index]?.isActive,
role: flatData[index]?.role,
});
return (
@@ -134,20 +143,20 @@ export default function Index() {
</View>
}
</View>
<View style={[{ flex: 2 }, Styles.mt05]}>
<View style={[{ flex: 2 }, Styles.mt10]}>
{
loading ?
isLoading ?
arrSkeleton.map((item, index) => {
return (
<SkeletonTwoItem key={index} />
)
})
:
data.length > 0
flatData.length > 0
?
<VirtualizedList
data={data}
getItemCount={() => data.length}
data={flatData}
getItemCount={() => flatData.length}
getItem={getItem}
renderItem={({ item, index }: { item: Props, index: number }) => {
return (
@@ -171,12 +180,12 @@ export default function Index() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
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 File

@@ -1,4 +1,4 @@
import BorderBottomItem from "@/components/borderBottomItem";
import BorderBottomItemVertical from "@/components/borderBottomItemVertical";
import SkeletonTwoItem from "@/components/skeletonTwoItem";
import Text from "@/components/Text";
import { ColorsStatus } from "@/constants/ColorsStatus";
@@ -9,7 +9,8 @@ import { pushToPage } from "@/lib/pushToPage";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { Feather } from "@expo/vector-icons";
import { useEffect, useState } from "react";
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
import { useEffect, useMemo, useState } from "react";
import { RefreshControl, SafeAreaView, View, VirtualizedList } from "react-native";
import { useDispatch, useSelector } from "react-redux";
@@ -26,64 +27,61 @@ type Props = {
export default function Notification() {
const { token, decryptToken } = useAuthSession()
const { colors } = useTheme();
const [loading, setLoading] = useState(false)
const [data, setData] = useState<Props[]>([])
const [page, setPage] = useState(1)
const [waiting, setWaiting] = useState(false)
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const queryClient = useQueryClient()
const dispatch = useDispatch()
const updateNotification = useSelector((state: any) => state.notificationUpdate)
const [refreshing, setRefreshing] = useState(false)
async function handleLoad(loading: boolean, thisPage: number) {
try {
setLoading(loading)
setPage(thisPage)
setWaiting(true)
// TanStack Query for Notifications with Infinite Scroll
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
isLoading,
refetch
} = useInfiniteQuery({
queryKey: ['notifications'],
queryFn: async ({ pageParam = 1 }) => {
const hasil = await decryptToken(String(token?.current))
const response = await apiGetNotification({ user: hasil, page: thisPage })
if (thisPage == 1) {
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)
}
}
const response = await apiGetNotification({ user: hasil, page: pageParam })
return response;
},
initialPageParam: 1,
getNextPageParam: (lastPage, allPages) => {
return lastPage.data.length > 0 ? allPages.length + 1 : undefined;
},
enabled: !!token?.current,
staleTime: 0,
})
// Flatten pages into a single data array
const flatData = useMemo(() => {
return data?.pages.flatMap(page => page.data) || [];
}, [data])
const loadMoreData = () => {
if (waiting) return
setTimeout(() => {
handleLoad(false, page + 1)
}, 1000);
// Refetch when manual update state changes
useEffect(() => {
refetch()
}, [updateNotification, refetch])
const handleRefresh = async () => {
setRefreshing(true)
await queryClient.invalidateQueries({ queryKey: ['notifications'] })
setRefreshing(false)
};
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,
});
const loadMoreData = () => {
if (hasNextPage && !isFetchingNextPage) {
fetchNextPage()
}
};
async function handleReadNotification(id: string, category: string, idContent: string) {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiReadOneNotification({ user: hasil, id: id })
await queryClient.invalidateQueries({ queryKey: ['notifications'] })
pushToPage(category, idContent)
dispatch(setUpdateNotification(!updateNotification))
} catch (error) {
@@ -91,36 +89,41 @@ export default function Notification() {
}
}
const handleRefresh = async () => {
setRefreshing(true)
handleLoad(false, 1)
await new Promise(resolve => setTimeout(resolve, 2000));
setRefreshing(false)
};
const arrSkeleton = [0, 1, 2, 3, 4]
const getItem = (_data: unknown, index: number): Props => ({
id: flatData[index]?.id,
title: flatData[index]?.title,
desc: flatData[index]?.desc,
category: flatData[index]?.category,
idContent: flatData[index]?.idContent,
isRead: flatData[index]?.isRead,
createdAt: flatData[index]?.createdAt,
});
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<View style={[Styles.p15]}>
{
loading ?
isLoading ?
arrSkeleton.map((item, index) => {
return (
<SkeletonTwoItem key={index} />
)
})
:
data.length > 0 ?
flatData.length > 0 ?
<VirtualizedList
data={data}
getItemCount={() => data.length}
data={flatData}
getItemCount={() => flatData.length}
getItem={getItem}
renderItem={({ item, index }: { item: Props, index: number }) => {
return (
<BorderBottomItem
<BorderBottomItemVertical
borderType="bottom"
icon={
<View style={[Styles.iconContent, item.isRead ? ColorsStatus.secondary : ColorsStatus.primary]}>
<Feather name="bell" size={25} color="white" />
<View style={[Styles.iconContent, item.isRead && ColorsStatus.secondary]}>
<Feather name="bell" size={25} color="black" />
</View>
}
title={item.title}
@@ -129,8 +132,8 @@ export default function Notification() {
textColor={item.isRead ? 'gray' : colors.text}
onPress={() => {
handleReadNotification(item.id, item.category, item.idContent)
}}
bgColor={'transparent'}
/>
)
}}
@@ -142,12 +145,12 @@ export default function Notification() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
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>
</SafeAreaView>

View File

@@ -1,4 +1,3 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi";
import BorderBottomItem from "@/components/borderBottomItem";
import { ButtonForm } from "@/components/buttonForm";
import ButtonTab from "@/components/buttonTab";
@@ -7,18 +6,19 @@ import { InputForm } from "@/components/inputForm";
import InputSearch from "@/components/inputSearch";
import LabelStatus from "@/components/labelStatus";
import MenuItemRow from "@/components/menuItemRow";
import ModalConfirmation from "@/components/ModalConfirmation";
import SkeletonTwoItem from "@/components/skeletonTwoItem";
import Text from "@/components/Text";
import WrapTab from "@/components/wrapTab";
import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { apiDeletePosition, apiEditPosition, apiGetPosition } from "@/lib/api";
import { setUpdatePosition } from "@/lib/positionSlice";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { AntDesign, Feather, MaterialCommunityIcons } from "@expo/vector-icons";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { RefreshControl, View, VirtualizedList } from "react-native";
import Toast from "react-native-toast-message";
import { useDispatch, useSelector } from "react-redux";
@@ -32,50 +32,53 @@ type Props = {
}
export default function Index() {
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [loading, setLoading] = useState(true)
const { token, decryptToken } = useAuthSession()
const { colors } = useTheme()
const [status, setStatus] = useState<'true' | 'false'>('true')
const entityUser = useSelector((state: any) => state.user)
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 [isVisibleEdit, setVisibleEdit] = useState(false)
const [data, setData] = useState<Props[]>([])
const [search, setSearch] = useState('')
const [nameGroup, setNameGroup] = useState('')
const [loadingSubmit, setLoadingSubmit] = useState(false)
const [chooseData, setChooseData] = useState({ name: '', id: '', active: false, idGroup: '' })
const [error, setError] = useState({
name: false,
});
const queryClient = useQueryClient()
const [refreshing, setRefreshing] = useState(false)
const [showDeleteModal, setShowDeleteModal] = useState(false)
const dispatch = useDispatch()
const update = useSelector((state: any) => state.positionUpdate)
async function handleLoad(loading: boolean) {
try {
setLoading(loading)
// TanStack Query for Positions
const {
data: queryData,
isLoading,
refetch
} = useQuery({
queryKey: ['positions', { status, search, group }],
queryFn: async () => {
const hasil = await decryptToken(String(token?.current))
const response = await apiGetPosition({ user: hasil, active: status, search: search, group: String(group) })
setData(response.data)
setNameGroup(response.filter.name)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
const response = await apiGetPosition({
user: hasil,
active: status,
search: search,
group: String(group)
})
return response;
},
enabled: !!token?.current,
staleTime: 0,
})
const data = useMemo(() => queryData?.data || [], [queryData])
const nameGroup = useMemo(() => queryData?.filter?.name || "", [queryData])
useEffect(() => {
handleLoad(false)
}, [update])
useEffect(() => {
handleLoad(true)
}, [status, search, group])
refetch()
}, [update, refetch])
function handleChooseData(id: string, name: string, active: boolean, group: string) {
@@ -88,8 +91,11 @@ export default function Index() {
const hasil = await decryptToken(String(token?.current))
const response = await apiDeletePosition({ user: hasil, isActive: chooseData.active }, chooseData.id)
dispatch(setUpdatePosition(!update))
} catch (error) {
console.error(error)
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menghapus data"
Toast.show({ type: 'small', text1: message })
} finally {
setModal(false)
Toast.show({ type: 'small', text1: 'Berhasil mengupdate data', })
@@ -107,8 +113,11 @@ export default function Index() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengubah data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoadingSubmit(false)
setVisibleEdit(false)
@@ -132,10 +141,11 @@ export default function Index() {
handleEdit()
}
const arrSkeleton = [0, 1, 2, 3, 4]
const handleRefresh = async () => {
setRefreshing(true)
handleLoad(false)
await new Promise(resolve => setTimeout(resolve, 2000));
await queryClient.invalidateQueries({ queryKey: ['positions'] })
setRefreshing(false)
};
@@ -149,7 +159,7 @@ export default function Index() {
});
return (
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
<View>
<WrapTab>
<ButtonTab
@@ -176,9 +186,9 @@ export default function Index() {
</View>
}
</View>
<View style={[{ flex: 2 }, Styles.mt05]}>
<View style={[Styles.flex2, Styles.mt10]}>
{
loading ?
isLoading ?
arrSkeleton.map((item, index) => {
return (
<SkeletonTwoItem key={index} />
@@ -215,12 +225,12 @@ export default function Index() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
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>
<DrawerBottom animation="slide" isVisible={isModal} setVisible={() => setModal(false)} title={chooseData.name}>
@@ -230,11 +240,9 @@ export default function Index() {
title={chooseData.active ? 'Non Aktifkan' : "Aktifkan"}
onPress={() => {
setModal(false)
AlertKonfirmasi({
title: 'Konfirmasi',
desc: chooseData.active ? 'Apakah anda yakin ingin menonaktifkan data?' : 'Apakah anda yakin ingin mengaktifkan data?',
onPress: () => { handleDelete() }
})
setTimeout(() => {
setShowDeleteModal(true)
}, 600)
}}
/>
<MenuItemRow
@@ -252,7 +260,7 @@ export default function Index() {
<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>
<InputForm
type="default"
@@ -271,6 +279,19 @@ export default function Index() {
</View>
</View>
</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 File

@@ -1,4 +1,3 @@
import AlertKonfirmasi from "@/components/alertKonfirmasi";
import AppHeader from "@/components/AppHeader";
import { ButtonHeader } from "@/components/buttonHeader";
import ItemDetailMember from "@/components/itemDetailMember";
@@ -6,42 +5,45 @@ import Text from "@/components/Text";
import { assetUserImage } from "@/constants/AssetsError";
import { ConstEnv } from "@/constants/ConstEnv";
import Styles from "@/constants/Styles";
import { apiGetProfile } from "@/lib/api";
import { setEntities } from "@/lib/entitiesSlice";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { AntDesign, Ionicons } from "@expo/vector-icons";
import { router, Stack } from "expo-router";
import { Feather } from "@expo/vector-icons";
import { LinearGradient } from "expo-linear-gradient";
import { router, Stack } from "expo-router";
import { useState } from "react";
import { Image, Modal, Pressable, SafeAreaView, ScrollView, TouchableOpacity, View } from "react-native";
import { Image, Pressable, RefreshControl, SafeAreaView, ScrollView, View } from "react-native";
import ImageViewing from 'react-native-image-viewing';
import { useSelector } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
export default function Profile() {
const { signOut } = useAuthSession()
const { theme, setTheme, colors } = useTheme();
const { colors } = useTheme();
const entities = useSelector((state: any) => state.entities)
const [error, setError] = useState(false)
const [preview, setPreview] = useState(false)
const [showThemeModal, setShowThemeModal] = useState(false)
const [refreshing, setRefreshing] = useState(false)
const dispatch = useDispatch()
const { token, decryptToken } = useAuthSession()
const ThemeOption = ({ label, value, icon }: { label: string, value: 'light' | 'dark' | 'system', icon: string }) => (
<TouchableOpacity
style={[Styles.itemSelectModal, { backgroundColor: theme === value ? colors.primary + '10' : 'transparent', borderColor: colors.icon + '20' }]}
onPress={() => {
setTheme(value);
setShowThemeModal(false);
}}
>
<View style={Styles.rowItemsCenter}>
<Ionicons name={icon as any} size={20} color={theme === value ? colors.primary : colors.text} style={{ marginRight: 10 }} />
<Text style={{ color: colors.text, fontWeight: theme === value ? 'bold' : 'normal' }}>{label}</Text>
</View>
{theme === value && <Ionicons name="checkmark" size={20} color={colors.primary} />}
</TouchableOpacity>
);
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)
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
headerTitle: 'Profile',
@@ -53,13 +55,9 @@ export default function Profile() {
onPressLeft={() => router.back()}
right={
<ButtonHeader
item={<AntDesign name="logout" size={20} color="white" />}
item={<Feather name="settings" size={20} color="white" />}
onPress={() => {
AlertKonfirmasi({
title: 'Keluar',
desc: 'Apakah anda yakin ingin keluar?',
onPress: () => { signOut() }
})
router.push('/setting')
}}
/>
}
@@ -67,8 +65,17 @@ export default function Profile() {
)
}}
/>
<ScrollView style={[Styles.h100, { backgroundColor: colors.background }]}>
<View style={{ flexDirection: 'column' }}>
<ScrollView
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
style={[Styles.h100, { backgroundColor: colors.background }]}
>
<View style={[Styles.flexColumn]}>
<LinearGradient
colors={[colors.header, colors.homeGradient]}
style={[Styles.wrapHeadViewMember]}
@@ -84,31 +91,8 @@ export default function Profile() {
<Text style={[Styles.textMediumNormal, Styles.cWhite]}>{entities.role}</Text>
</LinearGradient>
<View style={[Styles.p15]}>
<View style={[Styles.rowSpaceBetween, Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Tampilan</Text>
</View>
<TouchableOpacity
onPress={() => setShowThemeModal(true)}
style={[Styles.wrapItemBorderAll, { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', borderColor: colors.icon + '40', backgroundColor: colors.background }]}
>
<View style={Styles.rowItemsCenter}>
<Ionicons name="color-palette-outline" size={20} color={colors.text} style={{ marginRight: 10 }} />
<Text style={{ color: colors.text }}>Tema Aplikasi</Text>
</View>
<View style={Styles.rowItemsCenter}>
<Text style={{ color: colors.icon, marginRight: 5, fontSize: 13 }}>
{theme === 'light' ? 'Terang' : theme === 'dark' ? 'Gelap' : 'Sistem'}
</Text>
<Ionicons name="chevron-forward" size={16} color={colors.icon} />
</View>
</TouchableOpacity>
<View style={[Styles.rowSpaceBetween, Styles.mt15]}>
<View style={[Styles.rowSpaceBetween]}>
<Text style={[Styles.textDefaultSemiBold, { color: colors.text }]}>Informasi</Text>
{
entities.idUserRole != "developer" && <Text onPress={() => { router.push('/edit-profile') }} style={[Styles.textLink]}>Edit</Text>
}
</View>
{/* Note: ItemDetailMember might need updates to support dynamic colors if it uses default text colors */}
<ItemDetailMember category="nik" value={entities.nik} />
@@ -121,29 +105,6 @@ export default function Profile() {
</View>
</ScrollView>
<Modal
animationType="fade"
transparent={true}
visible={showThemeModal}
onRequestClose={() => setShowThemeModal(false)}
>
<TouchableOpacity style={Styles.modalBgTransparant} activeOpacity={1} onPress={() => setShowThemeModal(false)}>
<View style={[Styles.modalContent, { backgroundColor: colors.background }]}>
<View style={[Styles.titleContainer, { backgroundColor: colors.background, borderBottomColor: colors.icon + '20', borderBottomWidth: 1 }]}>
<Text style={[Styles.textSubtitle, { color: colors.text }]}>Pilih Tema</Text>
<TouchableOpacity onPress={() => setShowThemeModal(false)}>
<Ionicons name="close" size={24} color={colors.text} />
</TouchableOpacity>
</View>
<View style={{ padding: 10 }}>
<ThemeOption label="Terang" value="light" icon="sunny-outline" />
<ThemeOption label="Gelap" value="dark" icon="moon-outline" />
<ThemeOption label="Sistem" value="system" icon="phone-portrait-outline" />
</View>
</View>
</TouchableOpacity>
</Modal>
<ImageViewing
images={[{ uri: error ? assetUserImage.uri : `${ConstEnv.url_storage}/files/${entities.img}` }]}
imageIndex={0}

View File

@@ -3,6 +3,7 @@ import BorderBottomItem from "@/components/borderBottomItem"
import ButtonSaveHeader from "@/components/buttonSaveHeader"
import ButtonSelect from "@/components/buttonSelect"
import DrawerBottom from "@/components/drawerBottom"
import LoadingCenter from "@/components/loadingCenter"
import MenuItemRow from "@/components/menuItemRow"
import Styles from "@/constants/Styles"
import { apiAddFileProject, apiCheckFileProject } from "@/lib/api"
@@ -117,9 +118,11 @@ export default function ProjectAddFile() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}
@@ -129,7 +132,7 @@ export default function ProjectAddFile() {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
@@ -155,13 +158,16 @@ export default function ProjectAddFile() {
)
}}
/>
<ScrollView style={{ backgroundColor: colors.background }}>
<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} />
{
listFile.length > 0 && (
<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, { backgroundColor: colors.card, borderColor: colors.background }]}>
{
listFile.map((item, index) => (
@@ -182,9 +188,6 @@ export default function ProjectAddFile() {
{
loadingCheck && <ActivityIndicator size="small" />
}
{
loading && <ActivityIndicator size="large" />
}
</View>
</ScrollView>
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">

View File

@@ -45,9 +45,11 @@ export default function AddMemberProject() {
setIdGroup(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'))
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal mengambil data"
Toast.show({ type: 'small', text1: message })
}
}
@@ -86,9 +88,11 @@ export default function AddMemberProject() {
dispatch(setUpdateProject({ ...update, member: !update.member }))
router.back()
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan anggota"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -100,7 +104,7 @@ export default function AddMemberProject() {
<Stack.Screen
options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
headerTitle: 'Tambah Anggota Kegiatan',
headerTitle: 'Tambah Anggota',
headerTitleAlign: 'center',
// headerRight: () => (
// <ButtonSaveHeader
@@ -113,7 +117,7 @@ export default function AddMemberProject() {
// )
header: () => (
<AppHeader
title="Tambah Anggota Kegiatan"
title="Tambah Anggota"
showBack={true}
onPressLeft={() => router.back()}
right={
@@ -150,7 +154,7 @@ export default function AddMemberProject() {
</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
showsVerticalScrollIndicator={false}
@@ -165,7 +169,7 @@ export default function AddMemberProject() {
return (
<Pressable
key={index}
style={[Styles.itemSelectModal]}
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
onPress={() => {
!found && onChoose(item.id, item.name, item.img)
}}
@@ -175,7 +179,7 @@ export default function AddMemberProject() {
<View style={[Styles.ml10]}>
<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 File

@@ -1,5 +1,6 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import ButtonSelect from "@/components/buttonSelect";
import { InputForm } from "@/components/inputForm";
import ModalAddDetailTugasProject from "@/components/project/modalAddDetailTugasProject";
import Text from "@/components/Text";
@@ -19,7 +20,6 @@ import { useEffect, useState } from "react";
import {
KeyboardAvoidingView,
Platform,
Pressable,
SafeAreaView,
ScrollView,
View
@@ -126,16 +126,18 @@ export default function ProjectAddTask() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}
}
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (
@@ -174,7 +176,7 @@ export default function ProjectAddTask() {
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
keyboardVerticalOffset={headerHeight}
>
<ScrollView style={{ backgroundColor: colors.background }}>
<ScrollView style={[Styles.h100, { backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.mb100]}>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<DateTimePicker
@@ -197,34 +199,35 @@ export default function ProjectAddTask() {
/>
</View>
<View style={[Styles.mv10]}>
<View style={[Styles.rowSpaceBetween]}>
<View style={[{ width: "48%" }]}>
<View style={[Styles.rowSpaceBetween, Styles.mb10]}>
<View style={[Styles.w48]}>
<Text style={[Styles.mb05]}>
Tanggal Mulai <Text style={Styles.cError}>*</Text>
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<Text style={{ textAlign: "center" }}>{from}</Text>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={Styles.textCenter}>{from}</Text>
</View>
</View>
<View style={[{ width: "48%" }]}>
<View style={[Styles.w48]}>
<Text style={[Styles.mb05]}>
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<Text style={{ textAlign: "center" }}>{to}</Text>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={Styles.textCenter}>{to}</Text>
</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]}
disabled={dsbButton}
onPress={() => { setModalDetail(true) }}
>
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
</Pressable>
</Pressable> */}
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} />
</View>
<InputForm
label="Judul Tugas"

View File

@@ -58,16 +58,18 @@ export default function ProjectCancel() {
Toast.show({ type: 'small', text1: 'Berhasil membatalkan kegiatan', })
router.back();
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}
}
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (

View File

@@ -77,9 +77,11 @@ export default function EditProject() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}
@@ -88,7 +90,7 @@ export default function EditProject() {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (
@@ -123,7 +125,7 @@ export default function EditProject() {
)
}}
/>
<ScrollView style={{ backgroundColor: colors.background }}>
<ScrollView style={[Styles.h100, { backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.mb100]}>
<InputForm
label="Judul Kegiatan"

View File

@@ -93,7 +93,7 @@ export default function DetailProject() {
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
@@ -113,12 +113,12 @@ export default function DetailProject() {
}}
/>
<ScrollView
style={{ backgroundColor: colors.background }}
style={[Styles.h100, { backgroundColor: colors.background }]}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
tintColor={colors.icon}
/>
}
>

View File

@@ -77,9 +77,11 @@ export default function ReportProject() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoading(false)
}
@@ -88,7 +90,7 @@ export default function ReportProject() {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (

View File

@@ -5,6 +5,7 @@ import ButtonSelect from "@/components/buttonSelect";
import DrawerBottom from "@/components/drawerBottom";
import ImageUser from "@/components/imageNew";
import { InputForm } from "@/components/inputForm";
import LoadingCenter from "@/components/loadingCenter";
import MenuItemRow from "@/components/menuItemRow";
import ModalSelect from "@/components/modalSelect";
import SectionListAddTask from "@/components/project/sectionListAddTask";
@@ -150,9 +151,11 @@ export default function CreateProject() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error)
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menambahkan data"
Toast.show({ type: 'small', text1: message })
} finally {
setLoading(false)
}
@@ -192,7 +195,7 @@ export default function CreateProject() {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (
@@ -230,6 +233,9 @@ export default function CreateProject() {
)
}}
/>
{
loading && <LoadingCenter />
}
<ScrollView
showsVerticalScrollIndicator={false}
style={[Styles.h100, { backgroundColor: colors.background }]}
@@ -322,7 +328,7 @@ export default function CreateProject() {
<Text>Total {entitiesMember.length} Anggota</Text>
</View>
<View style={[Styles.borderAll, Styles.round10, Styles.p10, { borderColor: colors.icon, backgroundColor: colors.card }]}>
<View style={[Styles.borderAll, Styles.round05, Styles.p10, { borderColor: colors.icon + '20', backgroundColor: colors.card }]}>
{entitiesMember.map(
(item: { img: any; name: any }, index: any) => {
return (

View File

@@ -105,7 +105,7 @@ export default function AddMemberCreateProject() {
)
}}
/>
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
<InputSearch onChange={(val) => setSearch(val)} value={search} />
{
@@ -127,11 +127,11 @@ export default function AddMemberCreateProject() {
</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
showsVerticalScrollIndicator={false}
style={{ backgroundColor: colors.background }}
style={[Styles.h100, Styles.flex1, { backgroundColor: colors.background }]}
>
{
@@ -140,7 +140,7 @@ export default function AddMemberCreateProject() {
return (
<Pressable
key={index}
style={[Styles.itemSelectModal]}
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
onPress={() => {
onChoose(item.id, item.name, item.img)
}}
@@ -159,7 +159,7 @@ export default function AddMemberCreateProject() {
}
)
:
<Text style={[Styles.textDefault, { textAlign: 'center' }]}>Tidak ada data</Text>
<Text style={[Styles.textDefault, Styles.textCenter]}>Tidak ada data</Text>
}
</ScrollView>
</View>

View File

@@ -1,5 +1,6 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import ButtonSelect from "@/components/buttonSelect";
import { InputForm } from "@/components/inputForm";
import ModalAddDetailTugasProject from "@/components/project/modalAddDetailTugasProject";
import Text from "@/components/Text";
@@ -17,7 +18,6 @@ import React, { useEffect, useState } from "react";
import {
KeyboardAvoidingView,
Platform,
Pressable,
SafeAreaView,
ScrollView,
View
@@ -121,7 +121,7 @@ export default function CreateProjectAddTask() {
}
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => (
@@ -160,7 +160,7 @@ export default function CreateProjectAddTask() {
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
keyboardVerticalOffset={headerHeight}
>
<ScrollView style={{ backgroundColor: colors.background }}>
<ScrollView style={[Styles.h100, { backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.mb100]}>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<DateTimePicker
@@ -173,44 +173,45 @@ export default function CreateProjectAddTask() {
selected_label: Styles.cWhite,
range_fill: Styles.selectRangeDate,
month_label: { color: colors.text },
month_selector_label: Styles.cBlack,
year_label: Styles.cBlack,
year_selector_label: Styles.cBlack,
day_label: Styles.cBlack,
time_label: Styles.cBlack,
weekday_label: Styles.cBlack,
month_selector_label: { color: colors.text },
year_label: { color: colors.text },
year_selector_label: { color: colors.text },
day_label: { color: colors.text },
time_label: { color: colors.text },
weekday_label: { color: colors.text },
}}
/>
</View>
<View style={[Styles.mv10]}>
<View style={[Styles.rowSpaceBetween]}>
<View style={[Styles.rowSpaceBetween, Styles.mb10]}>
<View style={[{ width: "48%" }]}>
<Text style={[Styles.mb05]}>
Tanggal Mulai <Text style={Styles.cError}>*</Text>
Tanggal Mulai <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<Text style={{ textAlign: "center" }}>{from}</Text>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={Styles.textCenter}>{from}</Text>
</View>
</View>
<View style={[{ width: "48%" }]}>
<Text style={[Styles.mb05]}>
Tanggal Berakhir <Text style={Styles.cError}>*</Text>
Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text>
</Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<Text style={{ textAlign: "center" }}>{to}</Text>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={Styles.textCenter}>{to}</Text>
</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
{/* <Pressable
style={[Styles.btnTab, Styles.btnLainnya, dsbButton && Styles.btnDisabled]}
disabled={dsbButton}
onPress={() => { setModalDetail(true) }}
>
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
</Pressable>
</Pressable> */}
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} />
</View>
<InputForm
label="Judul Tugas"

View File

@@ -7,6 +7,7 @@ import ProgressBar from "@/components/progressBar";
import Skeleton from "@/components/skeleton";
import SkeletonTwoItem from "@/components/skeletonTwoItem";
import Text from "@/components/Text";
import WrapTab from "@/components/wrapTab";
import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { apiGetProject } from "@/lib/api";
@@ -17,8 +18,9 @@ import {
Ionicons,
MaterialCommunityIcons,
} from "@expo/vector-icons";
import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
import { router, useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { Pressable, RefreshControl, ScrollView, View, VirtualizedList } from "react-native";
import { useSelector } from "react-redux";
@@ -39,28 +41,29 @@ export default function ListProject() {
cat?: string;
year?: string;
}>();
const [statusFix, setStatusFix] = useState<'0' | '1' | '2' | '3'>('0')
const [statusFix, setStatusFix] = useState<'0' | '1' | '2' | '3'>(
(status == '1' || status == '2' || status == '3') ? status : '0'
)
const { token, decryptToken } = useAuthSession();
const { colors } = useTheme();
const entityUser = useSelector((state: any) => state.user)
const [search, setSearch] = useState("")
const [nameGroup, setNameGroup] = useState("")
// ... state same ...
const [isYear, setYear] = useState("")
const [data, setData] = useState<Props[]>([])
const [isList, setList] = useState(false)
const update = useSelector((state: any) => state.projectUpdate)
const [loading, setLoading] = useState(true)
const arrSkeleton = Array.from({ length: 3 }, (_, index) => index)
const [page, setPage] = useState(1)
const [waiting, setWaiting] = useState(false)
const queryClient = useQueryClient()
const [refreshing, setRefreshing] = useState(false)
async function handleLoad(loading: boolean, thisPage: number) {
try {
setLoading(loading)
setWaiting(true)
setPage(thisPage)
// TanStack Query for Projects with Infinite Scroll
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
isLoading,
refetch
} = useInfiniteQuery({
queryKey: ['projects', { statusFix, search, group, cat, year }],
queryFn: async ({ pageParam = 1 }) => {
const hasil = await decryptToken(String(token?.current));
const response = await apiGetProject({
user: hasil,
@@ -68,124 +71,122 @@ export default function ListProject() {
search: search,
group: String(group),
kategori: String(cat),
page: thisPage,
page: pageParam,
year: String(year)
});
return response;
},
initialPageParam: 1,
getNextPageParam: (lastPage, allPages) => {
return lastPage.data.length > 0 ? allPages.length + 1 : undefined;
},
enabled: !!token?.current,
staleTime: 0,
})
if (response.success) {
setNameGroup(response.filter.name);
setYear(response.tahun)
if (thisPage == 1) {
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)
}
}
// Refetch when manual update state changes
useEffect(() => {
handleLoad(false, 1);
}, [update.data]);
refetch()
}, [update.data, refetch])
// Flatten pages into a single data array
const flatData = useMemo(() => {
return data?.pages.flatMap(page => page.data) || [];
}, [data])
useEffect(() => {
handleLoad(true, 1);
}, [statusFix, search, group, cat, year]);
const loadMoreData = () => {
if (waiting) return
setTimeout(() => {
handleLoad(false, page + 1)
}, 1000);
}
// Get metadata from the first available page
const nameGroup = useMemo(() => data?.pages[0]?.filter?.name || "", [data])
const isYear = useMemo(() => data?.pages[0]?.tahun || "", [data])
const handleRefresh = async () => {
setRefreshing(true)
handleLoad(false, 1)
await new Promise(resolve => setTimeout(resolve, 2000));
await queryClient.invalidateQueries({ queryKey: ['projects'] })
setRefreshing(false)
}
};
const loadMoreData = () => {
if (hasNextPage && !isFetchingNextPage) {
fetchNextPage()
}
};
const arrSkeleton = [0, 1, 2]
const getItem = (_data: unknown, index: number): Props => ({
id: data[index].id,
title: data[index].title,
desc: data[index].desc,
status: data[index].status,
member: data[index].member,
progress: data[index].progress,
createdAt: data[index].createdAt,
id: flatData[index]?.id,
title: flatData[index]?.title,
desc: flatData[index]?.desc,
status: flatData[index]?.status,
member: flatData[index]?.member,
progress: flatData[index]?.progress,
createdAt: flatData[index]?.createdAt,
})
return (
<View style={[Styles.p15, { flex: 1, backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
<View>
<ScrollView horizontal style={[Styles.mb10]} showsHorizontalScrollIndicator={false}>
<ButtonTab
active={statusFix}
value="0"
onPress={() => { setStatusFix("0") }}
label="Segera"
icon={
<MaterialCommunityIcons
name="clock-alert-outline"
color={statusFix == "0" ? "white" : colors.dimmed}
size={20}
/>
}
n={4}
/>
<ButtonTab
active={statusFix}
value="1"
onPress={() => { setStatusFix("1") }}
label="Dikerjakan"
icon={
<MaterialCommunityIcons
name="progress-check"
color={statusFix == "1" ? "white" : colors.dimmed}
size={20}
/>
}
n={4}
/>
<ButtonTab
active={statusFix}
value="2"
onPress={() => { setStatusFix("2") }}
label="Selesai"
icon={
<Ionicons
name="checkmark-done-circle-outline"
color={statusFix == "2" ? "white" : colors.dimmed}
size={20}
/>
}
n={4}
/>
<ButtonTab
active={statusFix}
value="3"
onPress={() => { setStatusFix("3") }}
label="Batal"
icon={
<AntDesign
name="closecircleo"
color={statusFix == "3" ? "white" : colors.dimmed}
size={20}
/>
}
n={4}
/>
</ScrollView>
<View style={[Styles.rowSpaceBetween, { alignItems: 'center' }]}>
<WrapTab>
<ScrollView horizontal showsHorizontalScrollIndicator={false} style={[Styles.round20]}>
<ButtonTab
active={statusFix}
value="0"
onPress={() => { setStatusFix("0") }}
label="Segera"
icon={
<MaterialCommunityIcons
name="clock-alert-outline"
color={statusFix == "0" ? "white" : colors.dimmed}
size={20}
/>
}
n={4}
/>
<ButtonTab
active={statusFix}
value="1"
onPress={() => { setStatusFix("1") }}
label="Dikerjakan"
icon={
<MaterialCommunityIcons
name="progress-check"
color={statusFix == "1" ? "white" : colors.dimmed}
size={20}
/>
}
n={4}
/>
<ButtonTab
active={statusFix}
value="2"
onPress={() => { setStatusFix("2") }}
label="Selesai"
icon={
<Ionicons
name="checkmark-done-circle-outline"
color={statusFix == "2" ? "white" : colors.dimmed}
size={20}
/>
}
n={4}
/>
<ButtonTab
active={statusFix}
value="3"
onPress={() => { setStatusFix("3") }}
label="Batal"
icon={
<AntDesign
name="closecircleo"
color={statusFix == "3" ? "white" : colors.dimmed}
size={20}
/>
}
n={4}
/>
</ScrollView>
</WrapTab>
<View style={[Styles.rowSpaceBetween, Styles.rowItemsCenter]}>
<InputSearch width={68} onChange={setSearch} />
<Pressable
onPress={() => {
@@ -199,33 +200,27 @@ export default function ListProject() {
/>
</Pressable>
</View>
<View style={[Styles.mv05]}>
<View style={[Styles.mt10]}>
{
// entityUser.role != 'cosupadmin' && entityUser.role != 'admin' &&
<View style={[Styles.rowOnly]}>
<Text style={[Styles.mr05]}>Filter :</Text>
{
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
<LabelStatus size="small" category="secondary" text={nameGroup} style={{ marginRight: 5 }} />
<LabelStatus size="small" category="secondary" text={nameGroup} style={[Styles.mr05]} />
}
{
(entityUser.role == 'user' || entityUser.role == 'coadmin')
? (cat == 'null' || cat == 'undefined' || cat == undefined || cat == '' || cat == 'data-saya') ? <LabelStatus size="small" category="secondary" text="Kegiatan Saya" style={{ marginRight: 5 }} /> : <LabelStatus size="small" category="secondary" text="Semua Kegiatan" style={{ marginRight: 5 }} />
? (cat == 'null' || cat == 'undefined' || cat == undefined || cat == '' || cat == 'data-saya') ? <LabelStatus size="small" category="secondary" text="Kegiatan Saya" style={[Styles.mr05]} /> : <LabelStatus size="small" category="secondary" text="Semua Kegiatan" style={[Styles.mr05]} />
: ''
}
<LabelStatus size="small" category="secondary" text={isYear} style={{ marginRight: 5 }} />
{/* {
(entityUser.role == 'user' || entityUser.role == 'coadmin')
? (cat == 'null' || cat == 'undefined' || cat == undefined || cat == '' || cat == 'data-saya') ? <LabelStatus size="small" category="primary" text="Kegiatan Saya" /> : <LabelStatus size="small" category="primary" text="Semua Kegiatan" />
: ''
} */}
<LabelStatus size="small" category="secondary" text={isYear} style={[Styles.mr05]} />
</View>
}
</View>
</View>
<View style={[{ flex: 2 }]}>
<View style={[Styles.flex2, Styles.mt10]}>
{
loading ?
isLoading ?
isList ?
arrSkeleton.map((item, index) => (
<SkeletonTwoItem key={index} />
@@ -235,13 +230,13 @@ export default function ListProject() {
<Skeleton key={index} width={100} height={180} widthType="percent" borderRadius={10} />
))
:
data.length > 0
flatData.length > 0
?
isList ? (
<View style={[Styles.h100]}>
<VirtualizedList
data={data}
getItemCount={() => data.length}
data={flatData}
getItemCount={() => flatData.length}
getItem={getItem}
renderItem={({ item, index }: { item: Props, index: number }) => {
return (
@@ -249,12 +244,13 @@ export default function ListProject() {
key={index}
onPress={() => { router.push(`/project/${item.id}`); }}
borderType="bottom"
bgColor="transparent"
icon={
<View style={[Styles.iconContent, ColorsStatus.lightGreen]} >
<View style={[Styles.iconContent]} >
<AntDesign
name="areachart"
size={25}
color={"#384288"}
color={"black"}
/>
</View>
}
@@ -270,38 +266,16 @@ export default function ListProject() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
/>
{/* {
data.map((item, index) => {
return (
<BorderBottomItem
key={index}
onPress={() => { router.push(`/project/${item.id}`); }}
borderType="bottom"
icon={
<View
style={[Styles.iconContent, ColorsStatus.lightGreen]}
>
<AntDesign
name="areachart"
size={25}
color={"#384288"}
/>
</View>
}
title={item.title}
/>
);
})
} */}
</View>
) : (
<View style={[Styles.h100]}>
<VirtualizedList
data={data}
getItemCount={() => data.length}
data={flatData}
getItemCount={() => flatData.length}
getItem={getItem}
renderItem={({ item, index }: { item: Props, index: number }) => {
return (
@@ -313,20 +287,21 @@ export default function ListProject() {
content="page"
title={item.title}
headerColor="primary"
titleTail={2}
>
<ProgressBar value={item.progress} category="list" />
<View style={[Styles.rowSpaceBetween]}>
<Text style={[Styles.textDefault, Styles.cGray]}>
<Text style={[Styles.textDefault, { color: colors.dimmed }]}>
{item.createdAt}
</Text>
<LabelStatus
size="default"
category={
item.status === 0 ? 'primary' :
item.status === 0 ? 'secondary' :
item.status === 1 ? 'warning' :
item.status === 2 ? 'success' :
item.status === 3 ? 'error' :
'primary'
'secondary'
}
text={
item.status === 0 ? 'SEGERA' :
@@ -348,51 +323,15 @@ export default function ListProject() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.icon}
/>
}
/>
{/* {data.map((item, index) => {
return (
<PaperGridContent
key={index}
onPress={() => {
router.push(`/project/${item.id}`);
}}
content="page"
title={item.title}
headerColor="primary"
>
<ProgressBar value={item.progress} category="list" />
<View style={[Styles.rowSpaceBetween]}>
<Text style={[Styles.textDefault, Styles.cGray]}>
{item.createdAt}
</Text>
<LabelStatus
size="default"
category={
item.status === 0 ? 'primary' :
item.status === 1 ? 'warning' :
item.status === 2 ? 'success' :
item.status === 3 ? 'error' :
'primary'
}
text={
item.status === 0 ? 'SEGERA' :
item.status === 1 ? 'DIKERJAKAN' :
item.status === 2 ? 'SELESAI' :
item.status === 3 ? 'DIBATALKAN' :
'SEGERA'
}
/>
</View>
</PaperGridContent>
);
})} */}
</View>
)
:
<View style={[Styles.mt15]}>
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada kegiatan</Text>
<Text style={[Styles.textDefault, Styles.textCenter, { color: colors.dimmed }]}>Tidak ada kegiatan</Text>
</View>
}
</View>

View File

@@ -1,5 +1,6 @@
import AppHeader from "@/components/AppHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import ButtonSelect from "@/components/buttonSelect";
import { InputForm } from "@/components/inputForm";
import ModalAddDetailTugasProject from "@/components/project/modalAddDetailTugasProject";
import Text from "@/components/Text";
@@ -16,7 +17,7 @@ import 'intl';
import 'intl/locale-data/jsonp/id';
import moment from "moment";
import React, { useEffect, useState } from "react";
import { KeyboardAvoidingView, Platform, Pressable, SafeAreaView, ScrollView, View } from "react-native";
import { KeyboardAvoidingView, Platform, SafeAreaView, ScrollView, View } from "react-native";
import Toast from "react-native-toast-message";
import DateTimePicker, { DateType } from "react-native-ui-datepicker";
import { useDispatch, useSelector } from "react-redux";
@@ -117,9 +118,11 @@ export default function UpdateProjectTask() {
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
} catch (error : any ) {
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 {
setLoadingSubmit(false)
}
@@ -171,7 +174,7 @@ export default function UpdateProjectTask() {
}, [range])
return (
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
// headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
@@ -202,7 +205,7 @@ export default function UpdateProjectTask() {
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
keyboardVerticalOffset={headerHeight}
>
<ScrollView style={{ backgroundColor: colors.background }}>
<ScrollView style={[Styles.h100, { backgroundColor: colors.background }]}>
<View style={[Styles.p15, Styles.mb100]}>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
{
@@ -232,30 +235,31 @@ export default function UpdateProjectTask() {
</View>
<View style={[Styles.mv10]}>
<View style={[Styles.rowSpaceBetween]}>
<View style={[Styles.rowSpaceBetween, Styles.mb10]}>
<View style={[{ width: '48%' }]}>
<Text style={[Styles.mb05]}>Tanggal Mulai <Text style={Styles.cError}>*</Text></Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<Text style={{ textAlign: 'center' }}>{from}</Text>
<Text style={[Styles.mb05]}>Tanggal Mulai <Text style={{ color: colors.error }}>*</Text></Text>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={Styles.textCenter}>{from}</Text>
</View>
</View>
<View style={[{ width: '48%' }]}>
<Text style={[Styles.mb05]}>Tanggal Berakhir <Text style={Styles.cError}>*</Text></Text>
<View style={[Styles.wrapPaper, Styles.p10, { backgroundColor: colors.card, borderColor: colors.background }]}>
<Text style={{ textAlign: 'center' }}>{to}</Text>
<Text style={[Styles.mb05]}>Tanggal Berakhir <Text style={{ color: colors.error }}>*</Text></Text>
<View style={[Styles.wrapPaper, Styles.noShadow, Styles.borderAll, Styles.p10, { backgroundColor: colors.card, borderColor: colors.icon + '20' }]}>
<Text style={Styles.textCenter}>{to}</Text>
</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]}
disabled={dsbButton}
onPress={() => { setModalDetail(true) }}
>
<Text style={[dsbButton ? Styles.cGray : Styles.cWhite]}>Detail</Text>
</Pressable>
</Pressable> */}
<ButtonSelect value="Detail" onPress={() => { setModalDetail(true) }} />
</View>
<InputForm
label="Judul Tugas"

View File

@@ -65,9 +65,14 @@ export default function Search() {
setDataDivisi([])
setDataProject([])
}
} catch (error) {
console.error(error)
return Toast.show({ type: 'small', text1: 'Gagal melakukan pencarian', })
} catch (error: any) {
console.error(error);
const message = error?.response?.data?.message || "Gagal melakukan pencarian"
Toast.show({
type: 'small',
text1: message
})
}
}
@@ -82,7 +87,7 @@ export default function Search() {
return (
<>
<SafeAreaView style={{ flex: 1, backgroundColor: colors.background }}>
<SafeAreaView style={[Styles.flex1, { backgroundColor: colors.background }]}>
<Stack.Screen
options={{
headerTitle: 'Pencarian',
@@ -103,7 +108,7 @@ export default function Search() {
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={colors.primary}
tintColor={colors.icon}
/>
}
>

View File

@@ -0,0 +1,201 @@
import ModalConfirmation from "@/components/ModalConfirmation";
import Text from "@/components/Text";
import ButtonSetting from "@/components/buttonSetting";
import DrawerBottom from "@/components/drawerBottom";
import Styles from "@/constants/Styles";
import { apiGetCheckToken, apiRegisteredToken, apiUnregisteredToken } from "@/lib/api";
import { checkPermission, getToken, openSettings } from "@/lib/useNotification";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { Feather, Ionicons } from "@expo/vector-icons";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { router } from "expo-router";
import { useCallback, useEffect, useRef, useState } from "react";
import { AppState, AppStateStatus, Pressable, View } from "react-native";
import { useSelector } from "react-redux";
export default function ListSetting() {
const { theme, setTheme, colors } = useTheme()
const { signOut } = useAuthSession()
const [isNotificationEnabled, setIsNotificationEnabled] = useState<boolean | null>(null);
const entities = useSelector((state: any) => state.entities)
const [modalVisible, setModalVisible] = useState(false);
const [modalConfig, setModalConfig] = useState({
title: '',
message: '',
confirmText: 'Buka Pengaturan',
onConfirm: () => { }
});
const [showLogoutModal, setShowLogoutModal] = useState(false)
const [showThemeModal, setShowThemeModal] = useState(false)
const prevOsPermission = useRef<boolean | undefined>(undefined);
const registerToken = async () => {
try {
await AsyncStorage.setItem('@notification_permission', "true");
const token = await getToken();
if (token) {
await apiRegisteredToken({ user: entities.id, token, category: "register" });
}
} catch (error) {
console.warn('Error registering token:', error);
}
};
const unregisterToken = async () => {
try {
await AsyncStorage.setItem('@notification_permission', "false");
const token = await getToken();
if (token) {
await apiUnregisteredToken({ user: entities.id, token, category: "unregister" });
}
} catch (error) {
console.warn('Error unregistering token:', error);
}
};
const checkNotif = useCallback(async () => {
const osPermission = await checkPermission();
// Jika dari tidak diijinkan sistem kemudian diijinkan (setelah balik dari pengaturan device)
if (prevOsPermission.current === false && osPermission === true) {
await registerToken();
}
prevOsPermission.current = osPermission;
if (!osPermission) {
setIsNotificationEnabled(false);
return;
}
try {
const token = await getToken();
if (token) {
const response = await apiGetCheckToken({ user: entities.id, token });
setIsNotificationEnabled(!!response.data);
} else {
setIsNotificationEnabled(false);
}
} catch (error) {
console.warn('Error checking token status:', error);
setIsNotificationEnabled(false);
}
}, [entities.id]);
useEffect(() => {
checkNotif();
const subscription = AppState.addEventListener('change', (nextAppState: AppStateStatus) => {
if (nextAppState === 'active') {
checkNotif();
}
});
return () => {
subscription.remove();
};
}, [checkNotif]);
const handleToggleNotif = async () => {
const osPermission = await checkPermission();
if (!osPermission) {
setModalConfig({
title: "Aktifkan Notifikasi?",
message: "Izin notifikasi tidak diberikan. Buka pengaturan sistem untuk mengaktifkannya?",
confirmText: "Buka Pengaturan",
onConfirm: () => {
setModalVisible(false);
openSettings();
}
});
setModalVisible(true);
} else {
// OS Permission is granted, perform in-app toggle
const targetState = !isNotificationEnabled;
if (targetState) {
await registerToken();
} else {
await unregisterToken();
}
// UI will be updated by checkNotif (triggered by state change or manually here)
setIsNotificationEnabled(targetState);
}
};
const ThemeOption = ({ label, value, icon }: { label: string, value: 'light' | 'dark' | 'system', icon: string }) => (
<Pressable
style={[Styles.itemSelectModal, { borderColor: colors.icon + '20' }]}
onPress={() => {
setTheme(value);
}}
>
<View style={Styles.rowItemsCenter}>
<Ionicons name={icon as any} size={20} color={colors.text} style={Styles.mr10} />
<Text style={{ color: colors.text }}>{label}</Text>
</View>
{theme === value && <Ionicons name="checkmark" size={20} color={colors.text} />}
</Pressable>
);
return (
<View style={[Styles.p15, Styles.flex1, { backgroundColor: colors.background }]}>
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.icon + '20' }, Styles.p0, Styles.round05]}>
{
entities.idUserRole != "developer" &&
<ButtonSetting
title="Edit Profile"
icon={<Feather name="user" size={20} color={colors.text} />}
onPress={() => { router.push('/edit-profile') }}
/>
}
<ButtonSetting
title="Tema Aplikasi"
icon={<Ionicons name="color-palette-outline" size={20} color={colors.text} />}
onPress={() => setShowThemeModal(true)}
value={theme === 'light' ? 'Terang' : theme === 'dark' ? 'Gelap' : 'Sistem'}
/>
<ButtonSetting
title="Notifikasi"
icon={<Feather name="bell" size={20} color={colors.text} />}
onPress={handleToggleNotif}
value={isNotificationEnabled === null ? 'Memuat...' : isNotificationEnabled ? 'Aktif' : 'Nonaktif'}
/>
<ButtonSetting
title="Keluar"
icon={<Feather name="log-out" size={20} color={colors.text} />}
onPress={() => setShowLogoutModal(true)}
borderBottom={false}
/>
</View>
<ModalConfirmation
visible={modalVisible}
title={modalConfig.title}
message={modalConfig.message}
confirmText={modalConfig.confirmText}
onConfirm={modalConfig.onConfirm}
onCancel={() => setModalVisible(false)}
/>
<ModalConfirmation
visible={showLogoutModal}
title="Keluar"
message="Apakah anda yakin ingin keluar?"
onConfirm={() => {
setShowLogoutModal(false)
signOut()
}}
onCancel={() => setShowLogoutModal(false)}
confirmText="Keluar"
cancelText="Batal"
/>
<DrawerBottom animation="slide" isVisible={showThemeModal} setVisible={setShowThemeModal} title="Tema Aplikasi">
<ThemeOption label="Terang" value="light" icon="sunny-outline" />
<ThemeOption label="Gelap" value="dark" icon="moon-outline" />
<ThemeOption label="Sistem" value="system" icon="phone-portrait-outline" />
</DrawerBottom>
</View>
)
}

View File

@@ -1,17 +1,37 @@
import AuthProvider from '@/providers/AuthProvider';
import ThemeProvider from '@/providers/ThemeProvider';
import ThemeProvider, { useTheme } from '@/providers/ThemeProvider';
import QueryProvider from '@/providers/QueryProvider';
import ErrorBoundary from '@/components/ErrorBoundary';
import { flushErrorQueue } from '@/lib/errorLogger';
import { useFonts } from 'expo-font';
import { Stack } from 'expo-router';
import * as SplashScreen from 'expo-splash-screen';
import { StatusBar } from 'expo-status-bar';
import { useEffect } from 'react';
import { AppState } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { NotifierWrapper } from 'react-native-notifier';
import 'react-native-reanimated';
import Styles from '@/constants/Styles';
// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();
// Inner component - berada di dalam ThemeProvider, bisa pakai useTheme()
function AppStack() {
const { colors } = useTheme();
return (
<>
<Stack screenOptions={{ contentStyle: { backgroundColor: colors.header } }}>
<Stack.Screen name="index" options={{ headerShown: false }} />
<Stack.Screen name="(application)" options={{ headerShown: false }} />
</Stack>
<StatusBar style="auto" />
</>
);
}
export default function RootLayout() {
const [loaded] = useFonts({
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
@@ -20,27 +40,34 @@ export default function RootLayout() {
useEffect(() => {
if (loaded) {
SplashScreen.hideAsync();
flushErrorQueue();
}
}, [loaded]);
useEffect(() => {
const sub = AppState.addEventListener('change', (state) => {
if (state === 'active') flushErrorQueue();
});
return () => sub.remove();
}, []);
if (!loaded) {
return null;
}
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<NotifierWrapper>
<ThemeProvider>
<AuthProvider>
<Stack>
<Stack.Screen name="index" options={{ headerShown: false }} />
<Stack.Screen name="verification" options={{ headerShown: false }} />
<Stack.Screen name="(application)" options={{ headerShown: false }} />
</Stack>
<StatusBar style="auto" />
</AuthProvider>
</ThemeProvider>
</NotifierWrapper>
<GestureHandlerRootView style={Styles.flex1}>
<ErrorBoundary>
<NotifierWrapper>
<ThemeProvider>
<QueryProvider>
<AuthProvider>
<AppStack />
</AuthProvider>
</QueryProvider>
</ThemeProvider>
</NotifierWrapper>
</ErrorBoundary>
</GestureHandlerRootView>
);
}

View File

@@ -1,71 +0,0 @@
import { ButtonForm } from "@/components/buttonForm";
import Text from '@/components/Text';
import { ConstEnv } from "@/constants/ConstEnv";
import Styles from "@/constants/Styles";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import CryptoES from "crypto-es";
import React, { useState } from "react";
import { Image, View } from "react-native";
import { CodeField, Cursor, useBlurOnFulfill, useClearByFocusCell, } from 'react-native-confirmation-code-field';
export default function Index() {
const [value, setValue] = useState('');
const ref = useBlurOnFulfill({ value, cellCount: 4 });
const [props, getCellOnLayoutHandler] = useClearByFocusCell({
value,
setValue,
});
const { colors } = useTheme();
const { signIn } = useAuthSession();
const login = (): void => {
const random: string = 'contohLoginMobileDarmasaba';
var mytexttoEncryption = "contohLoginMobileDarmasaba"
const encrypted = CryptoES.AES.encrypt(mytexttoEncryption, ConstEnv.pass_encrypt).toString();
signIn(encrypted);
}
return (
<View style={[Styles.wrapLogin, { backgroundColor: colors.background }]} >
<View style={{ alignItems: "center", marginVertical: 50 }}>
<Image
source={require("../assets/images/logo.png")}
style={[{ width: 300, height: 150 }]}
width={270}
height={110}
/>
{/* <Text style={[Styles.textSubtitle]}>PERBEKEL DARMASABA</Text> */}
</View>
<View style={[Styles.mb30]}>
<Text style={[Styles.textDefaultSemiBold]}>Verifikasi Nomor Telepon</Text>
<Text style={[Styles.textMediumNormal]}>Masukkan kode yang kami kirimkan melalui WhatsApp</Text>
<Text style={[Styles.textMediumSemiBold]}>+628980185458</Text>
</View>
<CodeField
ref={ref}
{...props}
value={value}
rootStyle={{ width: '80%', alignSelf: 'center' }}
onChangeText={setValue}
cellCount={4}
keyboardType="number-pad"
renderCell={({ index, symbol, isFocused }) => (
<Text
key={index}
style={[Styles.verificationCell, isFocused && Styles.verificationFocusCell, { borderColor: isFocused ? colors.tint : colors.icon, color: colors.text }]}
onLayout={getCellOnLayoutHandler(index)}>
{symbol || (isFocused ? <Cursor /> : null)}
</Text>
)}
/>
<ButtonForm
text="SUBMIT"
// onPress={() => { router.push("/home") }}
onPress={login}
/>
<Text style={[Styles.textInformation, Styles.mt05, Styles.cDefault, { textAlign: 'center', color: colors.tint }]}>
Tidak Menerima kode verifikasi? Kirim Ulang
</Text>
</View>
);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Some files were not shown because too many files have changed in this diff Show More