-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
139 lines (132 loc) · 3.97 KB
/
Copy pathindex.tsx
File metadata and controls
139 lines (132 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React, { useEffect, useState } from "react";
import { useCounter } from "@mantine/hooks";
import { Center, Stack, Avatar, Text } from "@mantine/core";
import { useForm } from "@mantine/form";
import { IconPlus } from "@tabler/icons-react";
import { Carousel } from "@mantine/carousel";
import Modal from "@/components/Modal";
import { Participant, PaymentMethodType } from "@/types";
import PageSetPayment from "./components/PageSetPayment";
import { randomPersonEmoji } from "@/utils/randomEmoji";
import PageNotifyFinish from "./components/PageNotifyFinish";
import { validateIban } from "@/lib/validateIban";
// import { useId } from "@mantine/hooks";
const NewParticipantAvatar = () => {
return (
<Stack>
<Center>
<Avatar size="lg" radius="xl">
<IconPlus style={{ width: "70%", height: "70%" }} stroke={1.5} />
</Avatar>
</Center>
</Stack>
);
};
type AddParticipantModalProps = {
disabledPreferredPaymentMethod?: boolean;
// groupForm: UseFormReturnType<GroupFormValues>;
participants: Participant[];
setParticipants: React.Dispatch<React.SetStateAction<Participant[]>>;
// setNewParticipant?: React.Dispatch<React.SetStateAction<Participant>>;
onConfirmClick?: (newParticipant: Participant) => void;
confirmSuccess?: boolean;
setConfirmSuccess?: React.Dispatch<React.SetStateAction<boolean>>;
nextButtonIsPending?: boolean;
};
const AddParticipantModal = ({
// groupForm,
disabledPreferredPaymentMethod,
participants,
setParticipants,
// setNewParticipant,
onConfirmClick,
confirmSuccess,
setConfirmSuccess,
nextButtonIsPending,
}: AddParticipantModalProps) => {
useEffect(() => {
form.setFieldValue("avatar", { emoji: randomPersonEmoji(), unified: "" });
}, [confirmSuccess]);
const maxPage = 1;
const confirmPage = 0;
const [page, pageHandler] = useCounter(0, {
min: 0,
max: maxPage,
});
const form = useForm({
initialValues: {
avatar: { emoji: randomPersonEmoji(), unified: "" },
name: "",
accountName: "",
selectedPaymentMethod: PaymentMethodType.Iban,
paymentMethod: {
iban: "",
paypal: "",
},
},
validate: (values) => {
if (page === 0) {
return {
name:
values.name.trim().length < 1
? "Person name must include at least 1 character"
: null,
"paymentMethod.iban":
!disabledPreferredPaymentMethod &&
values.selectedPaymentMethod === PaymentMethodType.Iban &&
values.paymentMethod.iban.trim().length > 0
? validateIban(values.paymentMethod.iban)
: null,
};
}
return {};
},
});
return (
<Center>
<form onSubmit={form.onSubmit((values) => console.log(values))}>
<Modal
form={form}
page={page}
pageHandler={pageHandler}
maxPage={maxPage}
confirmPage={confirmPage}
onConfirmClick={() => {
setParticipants([...participants, form.values]);
if (onConfirmClick) {
onConfirmClick(form.values);
}
}}
onCloseModalClick={() => {
form.reset();
}}
onLastPageHandler={() => {
form.reset();
}}
confirmSuccess={confirmSuccess}
setConfirmSuccess={setConfirmSuccess}
nextButtonIsPending={nextButtonIsPending}
button={
<Stack>
<NewParticipantAvatar />
<Center>
<Text>Add</Text>
</Center>
</Stack>
}
>
<Carousel.Slide>
<PageSetPayment
disabledPreferredPaymentMethod={disabledPreferredPaymentMethod}
form={form}
/>
</Carousel.Slide>
<Carousel.Slide>
<PageNotifyFinish />
</Carousel.Slide>
</Modal>
</form>
</Center>
);
};
export default AddParticipantModal;