{"version":3,"file":"Questionnaire-B-2zhHuc.js","sources":["../../../node_modules/@mui/material/CardContent/cardContentClasses.js","../../../node_modules/@mui/material/CardContent/CardContent.js","../../../node_modules/@mui/icons-material/ArrowForward.js","../../../app/javascript/entrypoints/Questionnaire/Questionnaire.jsx"],"sourcesContent":["import generateUtilityClasses from '@mui/utils/generateUtilityClasses';\nimport generateUtilityClass from '@mui/utils/generateUtilityClass';\nexport function getCardContentUtilityClass(slot) {\n return generateUtilityClass('MuiCardContent', slot);\n}\nconst cardContentClasses = generateUtilityClasses('MuiCardContent', ['root']);\nexport default cardContentClasses;","'use client';\n\nimport _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectWithoutPropertiesLoose from \"@babel/runtime/helpers/esm/objectWithoutPropertiesLoose\";\nconst _excluded = [\"className\", \"component\"];\nimport * as React from 'react';\nimport PropTypes from 'prop-types';\nimport clsx from 'clsx';\nimport composeClasses from '@mui/utils/composeClasses';\nimport styled from '../styles/styled';\nimport { useDefaultProps } from '../DefaultPropsProvider';\nimport { getCardContentUtilityClass } from './cardContentClasses';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nconst useUtilityClasses = ownerState => {\n const {\n classes\n } = ownerState;\n const slots = {\n root: ['root']\n };\n return composeClasses(slots, getCardContentUtilityClass, classes);\n};\nconst CardContentRoot = styled('div', {\n name: 'MuiCardContent',\n slot: 'Root',\n overridesResolver: (props, styles) => styles.root\n})(() => {\n return {\n padding: 16,\n '&:last-child': {\n paddingBottom: 24\n }\n };\n});\nconst CardContent = /*#__PURE__*/React.forwardRef(function CardContent(inProps, ref) {\n const props = useDefaultProps({\n props: inProps,\n name: 'MuiCardContent'\n });\n const {\n className,\n component = 'div'\n } = props,\n other = _objectWithoutPropertiesLoose(props, _excluded);\n const ownerState = _extends({}, props, {\n component\n });\n const classes = useUtilityClasses(ownerState);\n return /*#__PURE__*/_jsx(CardContentRoot, _extends({\n as: component,\n className: clsx(classes.root, className),\n ownerState: ownerState,\n ref: ref\n }, other));\n});\nprocess.env.NODE_ENV !== \"production\" ? CardContent.propTypes /* remove-proptypes */ = {\n // ┌────────────────────────────── Warning ──────────────────────────────┐\n // │ These PropTypes are generated from the TypeScript type definitions. │\n // │ To update them, edit the d.ts file and run `pnpm proptypes`. │\n // └─────────────────────────────────────────────────────────────────────┘\n /**\n * The content of the component.\n */\n children: PropTypes.node,\n /**\n * Override or extend the styles applied to the component.\n */\n classes: PropTypes.object,\n /**\n * @ignore\n */\n className: PropTypes.string,\n /**\n * The component used for the root node.\n * Either a string to use a HTML element or a component.\n */\n component: PropTypes.elementType,\n /**\n * The system prop that allows defining system overrides as well as additional CSS styles.\n */\n sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])\n} : void 0;\nexport default CardContent;","\"use strict\";\n\"use client\";\n\nvar _interopRequireDefault = require(\"@babel/runtime/helpers/interopRequireDefault\");\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = void 0;\nvar _createSvgIcon = _interopRequireDefault(require(\"./utils/createSvgIcon\"));\nvar _jsxRuntime = require(\"react/jsx-runtime\");\nvar _default = exports.default = (0, _createSvgIcon.default)( /*#__PURE__*/(0, _jsxRuntime.jsx)(\"path\", {\n d: \"m12 4-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z\"\n}), 'ArrowForward');","import React, { useState, useEffect } from \"react\";\nimport { useLocation, useNavigate } from \"react-router-dom\";\nimport {\n Button,\n Card,\n CardContent,\n Typography,\n Box,\n CircularProgress,\n} from \"@mui/material\";\nimport axios from \"axios\";\nimport { colors } from \"../lib/theme\";\nimport PreviewCard from \"./PreviewCard\";\nimport { Link } from \"react-router-dom\";\nimport ShowGeneratedQuestions from \"./ShowGeneratedQuestions\";\nimport QuestionnaireForm from \"./QuestionnaireForm\";\nimport { Helmet } from \"react-helmet\";\nimport ArrowForwardIcon from '@mui/icons-material/ArrowForward';\n\nconst Questionnaire = ({ config }) => {\n const urlLocation = useLocation();\n const navigate = useNavigate();\n window.scrollTo(0, 0);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState(false);\n const [generatedQuestions, setGeneratedQuestions] = useState([]);\n const [cardTitle, setCardTitle] = useState(\"\");\n const [cardMessage, setCardMessage] = useState(\"\");\n const [senderClosing, setSenderClosing] = useState(\"\");\n const [additionalDetails, setAdditionalDetails] = useState(\"\");\n const [uploadedImage, setUploadedImage] = useState(null);\n const [openaiApiKey, setOpenaiApiKey] = useState(\"\");\n const [relationship, setRelationship] = useState(\"\");\n const [occasion, setOccasion] = useState(\"\");\n const [location, setLocation] = useState(\"US\");\n const [favoriteMemory, setFavoriteMemory] = useState(\"\");\n const [hobbiesInterests, setHobbiesInterests] = useState(\"\");\n const [showQuestions, setShowQuestions] = useState(false);\n const [newQuestion, setNewQuestion] = useState(\"\");\n const [showPreview, setShowPreview] = useState(false);\n const [shouldUpdateQuestions, setShouldUpdateQuestions] = useState(false);\n\n useEffect(() => {\n if (config?.openaiApiKey) {\n setOpenaiApiKey(config.openaiApiKey);\n } else {\n console.error(\"OpenAI API key is missing from the configuration\");\n setError(\"OpenAI API key is missing. Please check your configuration.\");\n }\n\n // Parse URL parameters\n const params = new URLSearchParams(urlLocation.search);\n const relationshipParam = params.get('relationship');\n const occasionParam = params.get('occasion');\n const memoryParam = params.get('memory');\n const interestsParam = params.get('interests');\n\n setRelationship(relationshipParam);\n setOccasion(occasionParam);\n setFavoriteMemory(memoryParam);\n setHobbiesInterests(interestsParam);\n setShouldUpdateQuestions(true);\n }, [config, urlLocation.search]);\n\n useEffect(() => {\n if (shouldUpdateQuestions) {\n if (relationship || occasion || favoriteMemory || hobbiesInterests) {\n updateQuestions();\n } else {\n console.error(\"State not fully updated before calling updateQuestions\");\n }\n setShouldUpdateQuestions(false);\n }\n }, [relationship, occasion, favoriteMemory, hobbiesInterests, shouldUpdateQuestions]);\n\n const handleQuestionChange = (id, newText) => {\n setGeneratedQuestions((prevQuestions) =>\n prevQuestions.map((q) => (q.id === id ? { ...q, text: newText } : q))\n );\n };\n\n const handleRemoveQuestion = (id) => {\n setGeneratedQuestions((prevQuestions) =>\n prevQuestions.filter((q) => q.id !== id)\n );\n };\n\n const handleAddQuestion = () => {\n if (newQuestion.trim()) {\n setGeneratedQuestions((prevQuestions) => [\n ...prevQuestions,\n { id: Date.now(), text: newQuestion.trim() },\n ]);\n setNewQuestion(\"\");\n }\n };\n\n const updateQuestions = async () => {\n window.scrollTo(0, 0);\n setLoading(true);\n setError(null);\n try {\n if (!openaiApiKey) {\n throw new Error(\"OpenAI API key is missing\");\n }\n const response = await axios.post(\n \"https://api.openai.com/v1/chat/completions\",\n {\n model: \"gpt-4o-2024-08-06\",\n messages: [\n {\n role: \"user\",\n content: `We're creating a gift for ${relationship} that requires the recipient to answer 15 questions about themselves on the occasion of ${occasion}.\n Generate 15 questions for a ${relationship}.\n Please only generate 15 questions. You should count them to ensure that there are only 15.\n Basic instructions: should include 15 questions that are core to interview and 5 that are specific/relevant to the additional context of the user's favorite memory of ${favoriteMemory} and their interest in ${hobbiesInterests}. We can infer if they're a Dad, that they have at least one kid.\n 1. A very short title for the gift card (format: \"Title: [your generated title]\").\n 2. A heartfelt message for the gift card (format: \"Message: [your generated message]\"). Don't add opening and closings (ie. \"Dearest [so-and-so]\" and \"Yours truly [so-and-so]\").\n 3. 15 questions to capture key moments from their life and learn more about them as a person (format: \"Questions: 1. [question1] 2. [question2] ...\").\n ${\n additionalDetails\n ? `- Additional details: ${additionalDetails}`\n : \"\"\n }\n Here are some of our favorite starter questions to ask, you should try to include some of these:\n - What is your full name and why were you named that?\n - Where and when were you born?\n - How would you describe your childhood?\n - Who were the most influential people in your early life?\n - What were your aspirations as a young person?\n - How did you meet your spouse/partner?\n - What have been the keys to a successful relationship in your opinion?\n - What was your profession and how did you choose it?\n - What did you find most rewarding about your career?\n - Are there any accomplishments you are particularly proud of?\n - What hobbies have you enjoyed?\n - Have you traveled much? What were some of your favorite places?\n - What values are most important to you?\n - What do you feel most grateful for?\n - What are some of the most important lessons you've learned in life?\n - How would you like to be remembered?\n - What are you most looking forward to right now?\n - Are there any goals or dreams you still wish to achieve?\n - Do you have a philosophy of life that guides your actions and decisions?\n - What's one thing you think everyone should try at least once in their life?\n ,`\n },\n ],\n temperature: 0.5,\n },\n {\n headers: {\n Authorization: `Bearer ${openaiApiKey}`,\n \"Content-Type\": \"application/json\",\n },\n }\n );\n\n const content = response.data.choices[0].message.content;\n\n // Extract title\n const titleMatch = content.match(/Title: (.*)/);\n const title = titleMatch\n ? titleMatch[1].replace(/\"/g, \"\")\n : `Happy ${occasion}, ${relationship}!`;\n setCardTitle(title);\n\n // Extract message\n const messageMatch = content.match(/Message: ([\\s\\S]*?)(?=Questions:)/);\n const message = messageMatch\n ? messageMatch[1].trim().replace(/\"/g, \"\")\n : \"\";\n setCardMessage(message);\n\n // Extract and process questions\n const questionsMatch = content.match(/Questions:([\\s\\S]*)/);\n const questionsContent = questionsMatch ? questionsMatch[1] : \"\";\n const questions = questionsContent\n .split(/\\d+\\.\\s/)\n .filter((q) => q.trim() !== \"\")\n .map((q, index) => ({\n id: index,\n text: q.trim(),\n }));\n\n setGeneratedQuestions(questions);\n setShowQuestions(true);\n } catch (error) {\n console.error(\"Error generating content:\", error);\n setError(\n \"Failed to generate content. Please check your API key and try again.\"\n );\n } finally {\n setLoading(false);\n }\n };\n\n const handleShowPreview = () => {\n setShowPreview(true);\n window.scrollTo(0, 0);\n };\n\n if (loading) {\n return (\n \n \n \n \n \n \n Generating personalized questions...\n \n Just a few more seconds!\n \n \n \n );\n }\n\n if (error) {\n return (\n \n \n \n {error}\n \n \n \n \n );\n }\n\n if (showPreview) {\n return (\n setShowPreview(false)}\n generatedQuestions={generatedQuestions}\n additionalDetails={additionalDetails}\n hobbiesInterests={hobbiesInterests}\n favoriteMemory={favoriteMemory}\n location={location}\n relationship={relationship}\n />\n );\n }\n\n if (showQuestions) {\n return (\n setShowQuestions(false)}\n handleQuestionChange={handleQuestionChange}\n handleRemoveQuestion={handleRemoveQuestion}\n newQuestion={newQuestion}\n setNewQuestion={setNewQuestion}\n handleAddQuestion={handleAddQuestion}\n updateQuestions={updateQuestions}\n handleShowPreview={handleShowPreview}\n />\n );\n }\n\n return (\n \n \n Create Your Gift - Golden Record\n \n \n \n Who are you creating a Golden Record with?\n \n \n Are you ready to learn more about someone through their stories?\n We'll use this information to generate a personalized gift card\n just for them, inviting them to share their stories with you.\n Not ready to create your gift yet?{` `}\n
\n \n Skip this and create an account for yourself!\n \n \n