@towsila/expo-ui-library 4.9.4 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Modal, Text, View } from "react-native";
|
|
2
|
+
import Warning from "@/assets/images/icons/warning.svg";
|
|
3
|
+
import { useAppTheme } from "../../context/ThemeContext";
|
|
4
|
+
import TemplateSubPage from "../reusable/templateSubPage";
|
|
5
|
+
import Select from "../ui/select";
|
|
6
|
+
import Input from "../ui/input";
|
|
7
|
+
import SharpButton from "../ui/sharpButton";
|
|
8
|
+
import { Fonts, textSize } from "../../tokens/typography";
|
|
9
|
+
|
|
10
|
+
type Option = { label: string; value: string };
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
title: string;
|
|
14
|
+
onBack: () => void;
|
|
15
|
+
onHideToast: () => void;
|
|
16
|
+
|
|
17
|
+
reason: {
|
|
18
|
+
label: string;
|
|
19
|
+
placeholder: string;
|
|
20
|
+
options: Option[];
|
|
21
|
+
value: string;
|
|
22
|
+
error: string;
|
|
23
|
+
onChange: (v: string) => void;
|
|
24
|
+
};
|
|
25
|
+
password: {
|
|
26
|
+
label: string;
|
|
27
|
+
placeholder: string;
|
|
28
|
+
value: string;
|
|
29
|
+
error: string;
|
|
30
|
+
show: boolean;
|
|
31
|
+
onChange: (v: string) => void;
|
|
32
|
+
onToggleShow: () => void;
|
|
33
|
+
onClearError: () => void;
|
|
34
|
+
};
|
|
35
|
+
confirmPassword: {
|
|
36
|
+
label: string;
|
|
37
|
+
placeholder: string;
|
|
38
|
+
value: string;
|
|
39
|
+
error: string;
|
|
40
|
+
show: boolean;
|
|
41
|
+
onChange: (v: string) => void;
|
|
42
|
+
onToggleShow: () => void;
|
|
43
|
+
onClearError: () => void;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
button: string;
|
|
47
|
+
onPressDelete: () => void;
|
|
48
|
+
|
|
49
|
+
modal: {
|
|
50
|
+
visible: boolean;
|
|
51
|
+
title: string;
|
|
52
|
+
subtitle: string;
|
|
53
|
+
confirm: string;
|
|
54
|
+
cancel: string;
|
|
55
|
+
loading: boolean;
|
|
56
|
+
onConfirm: () => void;
|
|
57
|
+
onCancel: () => void;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default function ConfirmDeleteScreen({
|
|
62
|
+
title, onBack,
|
|
63
|
+
reason, password, confirmPassword,
|
|
64
|
+
button, onPressDelete, modal,
|
|
65
|
+
}: Props) {
|
|
66
|
+
const { colors } = useAppTheme();
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<TemplateSubPage title={title} text={""} onBack={onBack}>
|
|
71
|
+
<Select
|
|
72
|
+
label={reason.label}
|
|
73
|
+
placeholder={reason.placeholder}
|
|
74
|
+
options={reason.options}
|
|
75
|
+
value={reason.value}
|
|
76
|
+
onChange={reason.onChange}
|
|
77
|
+
error={reason.error}
|
|
78
|
+
/>
|
|
79
|
+
|
|
80
|
+
<Input
|
|
81
|
+
label={password.label}
|
|
82
|
+
value={password.value}
|
|
83
|
+
onChangeText={password.onChange}
|
|
84
|
+
placeholder={password.placeholder}
|
|
85
|
+
iconLeft="lock-closed-outline"
|
|
86
|
+
iconRight={password.show ? "eye-off-outline" : "eye-outline"}
|
|
87
|
+
onPressIconRight={password.onToggleShow}
|
|
88
|
+
secureTextEntry={!password.show}
|
|
89
|
+
textContentType="password"
|
|
90
|
+
returnKeyType="next"
|
|
91
|
+
error={password.error}
|
|
92
|
+
onClearError={password.onClearError}
|
|
93
|
+
/>
|
|
94
|
+
|
|
95
|
+
<Input
|
|
96
|
+
label={confirmPassword.label}
|
|
97
|
+
value={confirmPassword.value}
|
|
98
|
+
onChangeText={confirmPassword.onChange}
|
|
99
|
+
placeholder={confirmPassword.placeholder}
|
|
100
|
+
iconLeft="lock-closed-outline"
|
|
101
|
+
iconRight={confirmPassword.show ? "eye-off-outline" : "eye-outline"}
|
|
102
|
+
onPressIconRight={confirmPassword.onToggleShow}
|
|
103
|
+
secureTextEntry={!confirmPassword.show}
|
|
104
|
+
textContentType="password"
|
|
105
|
+
returnKeyType="done"
|
|
106
|
+
error={confirmPassword.error}
|
|
107
|
+
onClearError={confirmPassword.onClearError}
|
|
108
|
+
/>
|
|
109
|
+
|
|
110
|
+
<SharpButton text={button} bgColor={colors.semantic.error} onPress={onPressDelete} />
|
|
111
|
+
|
|
112
|
+
<Modal visible={modal.visible} transparent animationType="fade" onRequestClose={modal.onCancel}>
|
|
113
|
+
<View style={{ flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "rgba(0,0,0,0.5)", paddingHorizontal: 24 }}>
|
|
114
|
+
<View
|
|
115
|
+
style={{
|
|
116
|
+
width: "100%",
|
|
117
|
+
maxWidth: 400,
|
|
118
|
+
backgroundColor: colors.background.card,
|
|
119
|
+
borderWidth: 1.5,
|
|
120
|
+
borderColor: colors.text.primary,
|
|
121
|
+
borderRadius: 16,
|
|
122
|
+
padding: 20,
|
|
123
|
+
gap: 15,
|
|
124
|
+
alignItems: "center",
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
<View style={{ alignItems: "center", gap: 15, width: "100%" }}>
|
|
128
|
+
<Warning width={50} height={50} color={colors.semantic.error} />
|
|
129
|
+
<View style={{ width: "100%" }}>
|
|
130
|
+
<Text style={{ fontFamily: Fonts.montserrat.bold, fontSize: textSize.md, color: colors.text.primary, textAlign: "center" }}>
|
|
131
|
+
{modal.title}
|
|
132
|
+
</Text>
|
|
133
|
+
<Text style={{ fontFamily: Fonts.montserrat.bold, fontSize: textSize.md, color: colors.semantic.error, textAlign: "center" }}>
|
|
134
|
+
{modal.subtitle}
|
|
135
|
+
</Text>
|
|
136
|
+
</View>
|
|
137
|
+
</View>
|
|
138
|
+
|
|
139
|
+
<View style={{ height: 1, width: "100%", backgroundColor: colors.semantic.border }} />
|
|
140
|
+
|
|
141
|
+
<View style={{ width: "100%", gap: 12 }}>
|
|
142
|
+
<SharpButton text={modal.confirm} bgColor={colors.semantic.error} onPress={modal.onConfirm} loading={modal.loading} />
|
|
143
|
+
<SharpButton text={modal.cancel} bgColor={colors.semantic.warning} onPress={modal.onCancel} />
|
|
144
|
+
</View>
|
|
145
|
+
</View>
|
|
146
|
+
</View>
|
|
147
|
+
</Modal>
|
|
148
|
+
</TemplateSubPage>
|
|
149
|
+
</>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { FieldConfig } from "../types/validateForm";
|
|
3
|
+
import { validateForm } from "../utils/inputValidator/registerValidator";
|
|
4
|
+
|
|
5
|
+
const fields: FieldConfig[] = [
|
|
6
|
+
{ name: "reason", type: "text", label: "reason" },
|
|
7
|
+
{ name: "password", type: "password", label: "password" },
|
|
8
|
+
{ name: "confirmPassword", type: "password", label: "confirmPassword" },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
export function useConfirmDeleteForm({
|
|
12
|
+
onDelete,
|
|
13
|
+
}: {
|
|
14
|
+
onDelete: (data: { reason: string; password: string }) => Promise<void>;
|
|
15
|
+
}) {
|
|
16
|
+
const [reason, setReasonState] = useState("");
|
|
17
|
+
const [password, setPassword] = useState("");
|
|
18
|
+
const [confirmPassword, setConfirmPassword] = useState("");
|
|
19
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
20
|
+
const [showConfirm, setShowConfirm] = useState(false);
|
|
21
|
+
const [errors, setErrors] = useState<Record<string, string>>({});
|
|
22
|
+
const [visible, setVisible] = useState(false);
|
|
23
|
+
const [loading, setLoading] = useState(false);
|
|
24
|
+
|
|
25
|
+
const clearError = (name: string) =>
|
|
26
|
+
setErrors((prev) => ({ ...prev, [name]: "" }));
|
|
27
|
+
|
|
28
|
+
const setReason = (v: string) => {
|
|
29
|
+
setReasonState(v);
|
|
30
|
+
clearError("reason");
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const requestDelete = () => {
|
|
34
|
+
const newErrors = validateForm(fields, { reason, password, confirmPassword });
|
|
35
|
+
setErrors(newErrors);
|
|
36
|
+
if (Object.keys(newErrors).length > 0) return;
|
|
37
|
+
setVisible(true);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const confirmDelete = async () => {
|
|
41
|
+
setLoading(true);
|
|
42
|
+
try {
|
|
43
|
+
await onDelete({ reason, password });
|
|
44
|
+
} finally {
|
|
45
|
+
setLoading(false);
|
|
46
|
+
setVisible(false);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
reason, setReason,
|
|
52
|
+
password, setPassword,
|
|
53
|
+
confirmPassword, setConfirmPassword,
|
|
54
|
+
showPassword, toggleShowPassword: () => setShowPassword((s) => !s),
|
|
55
|
+
showConfirm, toggleShowConfirm: () => setShowConfirm((s) => !s),
|
|
56
|
+
errors, clearError,
|
|
57
|
+
visible, closeModal: () => setVisible(false),
|
|
58
|
+
loading,
|
|
59
|
+
requestDelete,
|
|
60
|
+
confirmDelete,
|
|
61
|
+
};
|
|
62
|
+
}
|