diff --git a/src/components/ChangePasswordModal.tsx b/src/components/ChangePasswordModal.tsx index 4164618..30ec8bf 100644 --- a/src/components/ChangePasswordModal.tsx +++ b/src/components/ChangePasswordModal.tsx @@ -1,10 +1,10 @@ -import React, {useState} from "react"; +import React, {useRef, useState} from "react"; import { Paragraph} from "react-native-paper"; import {useTheme} from "@/src/context/ThemeProvider"; import {StyleSheet, View} from "react-native"; import {ApiResponse, RestService} from "@/src/services/RestService"; import {useAuth} from "@/src/context/AuthProvider"; -import CustomModal from "@/src/components/themed/CustomModal"; +import CustomModal, {CustomModalHandles} from "@/src/components/themed/CustomModal"; import PasswordInput from "@/src/components/PasswordInput"; import ThemedButton from "@/src/components/themed/ThemedButton"; @@ -15,11 +15,11 @@ export default function ChangePasswordModal() { const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [apiResponse, setApiResponse] = useState | null>(null); + const modalRef = useRef(null); + const handleConfirm = () => { if (!password || !confirmPassword) { - - setApiResponse({ok: false, data: {message: "Bitte füllen Sie alle Felder aus!"}}); return; } @@ -49,7 +49,7 @@ export default function ChangePasswordModal() { return ( <> - + Passwort ändern {apiResponse && apiResponse.data?.message && ( @@ -77,6 +77,10 @@ export default function ChangePasswordModal() { + { + modalRef.current?.close(); + resetModal(); + }} title={"Abbrechen"} /> diff --git a/src/components/themed/CustomColorPicker.tsx b/src/components/themed/CustomColorPicker.tsx index 72c84ed..86b3822 100644 --- a/src/components/themed/CustomColorPicker.tsx +++ b/src/components/themed/CustomColorPicker.tsx @@ -1,7 +1,7 @@ -import React, {useEffect, useState} from 'react'; +import React, {useEffect, useRef, useState} from 'react'; import {StyleSheet, View, Dimensions} from 'react-native'; import ColorPicker, {Panel1, Swatches, Preview, HueSlider, ColorFormatsObject} from 'reanimated-color-picker'; -import CustomModal from "@/src/components/themed/CustomModal"; +import CustomModal, {CustomModalHandles} from "@/src/components/themed/CustomModal"; import ThemedButton from "@/src/components/themed/ThemedButton"; import {useTheme} from "@/src/context/ThemeProvider"; @@ -12,6 +12,7 @@ interface CustomColorPickerProps { export default function CustomColorPicker({defaultColor = [255, 255, 255], onSelect}: CustomColorPickerProps) { const [currentColor, setCurrentColor] = useState(defaultColor); + const modalRef = useRef(null); const {theme} = useTheme(); const rgbToHex = ([r, g, b]: [number, number, number]) => @@ -40,6 +41,8 @@ export default function CustomColorPicker({defaultColor = [255, 255, 255], onSel setCurrentColor(rgb); onSelect(rgb); console.log(rgb) + console.log(modalRef.current) + modalRef.current?.close(); }; const resetModal = () => { @@ -48,7 +51,7 @@ export default function CustomColorPicker({defaultColor = [255, 255, 255], onSel return ( - + void; + close: () => void; +} + export interface Props { resetCallback: () => void; children: React.ReactNode; @@ -10,25 +15,39 @@ export interface Props { buttonMode?: 'text' | 'outlined' | 'contained'; } -export default function CustomModal({resetCallback, children, buttonTitle, buttonMode = "outlined"}: Props) { - const [isVisible, setIsVisible] = useState(false); +const CustomModal = forwardRef( + ({resetCallback, children, buttonTitle, buttonMode = "outlined"}, ref) => { + const [isVisible, setIsVisible] = useState(false); - const resetModal = () => { - setIsVisible(false); - resetCallback(); + const resetModal = () => { + setIsVisible(false); + resetCallback(); + }; + + useImperativeHandle(ref, () => ({ + open: () => setIsVisible(true), + close: () => setIsVisible(false), + })); + + return ( + <> + setIsVisible(true)} title={buttonTitle} /> + + + {children} + + + + ); } +); - return ( - <> - setIsVisible(true)} title={buttonTitle} /> - - - {children} - - - - ); -} +export default CustomModal; const styles = StyleSheet.create({ modalContent: {