summaryrefslogtreecommitdiff
path: root/src/app/page.tsx
blob: aed6b8d0926f361cc978b76362fabca9f7825daf (plain) (blame)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"use client";
import VCardExport from "@/components/VCardExport";
import VCardForm from "@/components/VCardForm";
import { useState } from "react";
import { SelectionItem } from "@/lib/definitions";

export default function Home() {
  // Declare and initialize selection array
  const [section, setSection] = useState("form");
  const [selection, setSelection] = useState<SelectionItem[]>([
    {
      field: "Vorname",
      value: "",
      placeholder: "Max",
      required: true,
    },
    {
      field: "Nachname",
      value: "",
      placeholder: "Mustermann",
      required: true,
    },
    {
      field: "Spitzname",
      value: "",
      placeholder: "Maxi",
      required: false,
    },
    {
      field: "Email",
      value: "",
      placeholder: "max@example.com",
      required: false,
    },
    {
      field: "Telefonnummer (Zuhause)",
      value: "",
      placeholder: "+49 123 456789",
      required: false,
    },
    {
      field: "Telefonnummer (Mobile)",
      value: "",
      placeholder: "+49 123 456789",
      required: false,
    },
    {
      field: "Telefonnummer (Arbeit)",
      value: "",
      placeholder: "+49 123 456789",
      required: false,
    },
    {
      field: "Land",
      value: "",
      placeholder: "Deutschland",
      required: false,
    },
    {
      field: "Ort",
      value: "",
      placeholder: "Musterstadt",
      required: false,
    },
    {
      field: "Straße",
      value: "",
      placeholder: "Musterstraße 1",
      required: false,
    },
    {
      field: "Postleitzahl",
      value: "",
      placeholder: "12345",
      required: false,
    },
    {
      field: "Geburtstag",
      value: "",
      placeholder: "1990-01-01 (jahr-monat-tag)",
      required: false,
    },
    {
      field: "Firma",
      value: "",
      placeholder: "Beispiel GmbH",
      required: false,
    },
    {
      field: "Abteilung",
      value: "",
      placeholder: "Entwicklung",
      required: false,
    },
    {
      field: "Berufsbezeichnung",
      value: "",
      placeholder: "Softwareentwickler",
      required: false,
    },
    {
      field: "Rolle im Unternehmen",
      value: "",
      placeholder: "Projektleiter",
      required: false,
    },
    {
      field: "Homepage/Persönliche Webseite",
      value: "",
      placeholder: "https://example.com",
      required: false,
    },
    {
      field: "Notizen",
      value: "",
      placeholder: "Zusätzliche Informationen...",
      required: false,
    },
  ]);
  const [vcardData, setVcardData] = useState<string>("");

  // Setting value for field when value changes
  const handleValueChange = (field: string, value: string) => {
    setSelection((prev) =>
      prev.map((item) => (item.field === field ? { ...item, value } : item)),
    );
  };

  const handleSectionChange = (section: string) => {
    setSection(section);
  };

  return (
    <div className="flex flex-col items-center mt-5 min-h-screen">
      <h1 className="text-2xl font-bold mb-8">Leo&apos;s VCard Generator</h1>
      {/* Show Component based on section */}
      <div className="flex justify-center gap-8 w-full">
        {section == "form" && (
          <VCardForm
            selection={selection}
            onValueChange={handleValueChange}
            sectionChange={handleSectionChange}
            onGenerate={(data: any) => setVcardData(data)}
          />
        )}
        {section == "export" && (
          <VCardExport
            sectionChange={handleSectionChange}
            vcardText={vcardData}
          />
        )}
      </div>
    </div>
  );
}