Done.js
1 month ago
Integrations.js
1 month ago
PremiumFeatures.js
1 month ago
UserInfo.js
1 month ago
Welcome.js
1 month ago
UserInfo.js
178 lines
| 1 | import { useState } from "react"; |
| 2 | import { |
| 3 | Button, |
| 4 | Text, |
| 5 | Title, |
| 6 | Container, |
| 7 | Input, |
| 8 | Checkbox, |
| 9 | } from "@bsf/force-ui"; |
| 10 | import { ChevronRight, ChevronLeft } from "lucide-react"; |
| 11 | import wpApiFetch from "@wordpress/api-fetch"; |
| 12 | import { toast } from "@bsf/force-ui"; |
| 13 | |
| 14 | const { __ } = wp.i18n; |
| 15 | |
| 16 | const UserInfo = ({ goToNextStep, goToPreviousStep, userInfoData = {}, setUserInfoData }) => { |
| 17 | const formData = userInfoData; |
| 18 | const [isSaving, setIsSaving] = useState(false); |
| 19 | |
| 20 | const updateField = (field, value) => { |
| 21 | setUserInfoData((prev) => ({ ...prev, [field]: value })); |
| 22 | }; |
| 23 | |
| 24 | const handleSubmit = async () => { |
| 25 | setIsSaving(true); |
| 26 | |
| 27 | try { |
| 28 | await wpApiFetch({ |
| 29 | path: "/presto-player/v1/onboarding/save-user-info", |
| 30 | method: "POST", |
| 31 | data: { |
| 32 | firstName: formData.firstName, |
| 33 | lastName: formData.lastName, |
| 34 | email: formData.email, |
| 35 | optIn: formData.optIn, |
| 36 | }, |
| 37 | }); |
| 38 | } catch (error) { |
| 39 | toast.error(__("Error!", "presto-player"), { |
| 40 | description: __("Failed to save your information. Please try again.", "presto-player"), |
| 41 | }); |
| 42 | setIsSaving(false); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | setIsSaving(false); |
| 47 | goToNextStep(); |
| 48 | }; |
| 49 | |
| 50 | const handleSkip = () => { |
| 51 | goToNextStep(); |
| 52 | }; |
| 53 | |
| 54 | return ( |
| 55 | <div> |
| 56 | <Container direction="column" gap="lg" className="gap-6"> |
| 57 | {/* Header */} |
| 58 | <Container direction="column" gap="xs"> |
| 59 | <Title |
| 60 | size="lg" |
| 61 | tag="h2" |
| 62 | title={__("Get the best start", "presto-player")} |
| 63 | /> |
| 64 | <Text size={14} weight={400} color="secondary"> |
| 65 | {__( |
| 66 | "Get helpful updates, new features, and tips to make your website better, while helping us improve Presto Player.", |
| 67 | "presto-player" |
| 68 | )} |
| 69 | </Text> |
| 70 | </Container> |
| 71 | |
| 72 | {/* Form Fields */} |
| 73 | <div className="grid grid-cols-2 gap-6"> |
| 74 | {/* First Name */} |
| 75 | <div> |
| 76 | <Input |
| 77 | size="md" |
| 78 | label={__("First Name", "presto-player")} |
| 79 | placeholder={__("First Name", "presto-player")} |
| 80 | value={formData.firstName} |
| 81 | onChange={(value) => updateField("firstName", value)} |
| 82 | /> |
| 83 | </div> |
| 84 | |
| 85 | {/* Last Name */} |
| 86 | <div> |
| 87 | <Input |
| 88 | size="md" |
| 89 | label={__("Last Name", "presto-player")} |
| 90 | placeholder={__("Last Name", "presto-player")} |
| 91 | value={formData.lastName} |
| 92 | onChange={(value) => updateField("lastName", value)} |
| 93 | /> |
| 94 | </div> |
| 95 | |
| 96 | {/* Email - full width */} |
| 97 | <div className="col-span-2"> |
| 98 | <Input |
| 99 | size="md" |
| 100 | type="email" |
| 101 | label={__("Email", "presto-player")} |
| 102 | placeholder={__("Email", "presto-player")} |
| 103 | value={formData.email} |
| 104 | onChange={(value) => updateField("email", value)} |
| 105 | /> |
| 106 | </div> |
| 107 | |
| 108 | {/* Opt-In Checkbox */} |
| 109 | <div className="col-span-2 flex items-start gap-2 [&>div]:mt-[1px]"> |
| 110 | <Checkbox |
| 111 | size="sm" |
| 112 | id="optIn" |
| 113 | checked={formData.optIn} |
| 114 | onChange={(checked) => updateField("optIn", checked)} |
| 115 | /> |
| 116 | <label htmlFor="optIn" className="cursor-pointer"> |
| 117 | <Text size={14} weight={400} color="secondary"> |
| 118 | {__( |
| 119 | "Get notified about updates, tips and new features. Plus help us improve by sharing how you use the plugin.", |
| 120 | "presto-player" |
| 121 | )}{" "} |
| 122 | <a |
| 123 | href="https://prestoplayer.com/share-usage-data/" |
| 124 | target="_blank" |
| 125 | rel="noopener noreferrer" |
| 126 | className="text-text-secondary underline" |
| 127 | onClick={(e) => e.stopPropagation()} |
| 128 | > |
| 129 | {__("Learn more", "presto-player")} |
| 130 | </a> |
| 131 | </Text> |
| 132 | </label> |
| 133 | </div> |
| 134 | </div> |
| 135 | |
| 136 | {/* Divider */} |
| 137 | <hr className="border-t border-solid border-border-subtle border-b-0 m-0 w-full" /> |
| 138 | |
| 139 | {/* Footer Buttons */} |
| 140 | <Container |
| 141 | direction="row" |
| 142 | align="center" |
| 143 | className="justify-between" |
| 144 | > |
| 145 | <Button |
| 146 | icon={<ChevronLeft />} |
| 147 | variant="outline" |
| 148 | onClick={goToPreviousStep} |
| 149 | > |
| 150 | {__("Back", "presto-player")} |
| 151 | </Button> |
| 152 | <Container direction="row" align="center" gap="sm"> |
| 153 | <Button |
| 154 | className="text-text-tertiary" |
| 155 | variant="ghost" |
| 156 | onClick={handleSkip} |
| 157 | > |
| 158 | {__("Skip", "presto-player")} |
| 159 | </Button> |
| 160 | <Button |
| 161 | iconPosition="right" |
| 162 | icon={<ChevronRight />} |
| 163 | onClick={handleSubmit} |
| 164 | disabled={isSaving} |
| 165 | > |
| 166 | {isSaving |
| 167 | ? __("Saving...", "presto-player") |
| 168 | : __("Continue", "presto-player")} |
| 169 | </Button> |
| 170 | </Container> |
| 171 | </Container> |
| 172 | </Container> |
| 173 | </div> |
| 174 | ); |
| 175 | }; |
| 176 | |
| 177 | export default UserInfo; |
| 178 |