diff --git a/.storybook/storybook.requires.js b/.storybook/storybook.requires.js index a956ef5e64..fcec5fbc18 100644 --- a/.storybook/storybook.requires.js +++ b/.storybook/storybook.requires.js @@ -1,12 +1,17 @@ /* do not change this file, it is auto generated by storybook. */ - +import { argsEnhancers } from "@storybook/addon-actions/dist/modern/preset/addArgs" +import "@storybook/addon-ondevice-actions/register" +import "@storybook/addon-ondevice-backgrounds/register" +import "@storybook/addon-ondevice-controls/register" +import "@storybook/addon-ondevice-knobs/register" +import "@storybook/addon-ondevice-notes/register" import { configure, addDecorator, addParameters, addArgsEnhancer, clearDecorators, -} from "@storybook/react-native"; +} from "@storybook/react-native" global.STORIES = [ { @@ -16,18 +21,10 @@ global.STORIES = [ importPathMatcher: "^\\.[\\\\/](?:app(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx)?)$", }, -]; - -import "@storybook/addon-ondevice-notes/register"; -import "@storybook/addon-ondevice-controls/register"; -import "@storybook/addon-ondevice-knobs/register"; -import "@storybook/addon-ondevice-backgrounds/register"; -import "@storybook/addon-ondevice-actions/register"; - -import { argsEnhancers } from "@storybook/addon-actions/dist/modern/preset/addArgs"; +] try { - argsEnhancers.forEach((enhancer) => addArgsEnhancer(enhancer)); + argsEnhancers.forEach((enhancer) => addArgsEnhancer(enhancer)) } catch {} const getStories = () => { @@ -67,7 +64,7 @@ const getStories = () => { "./app/screens/authentication-screen/authentication-check-screen.stories.tsx": require("../app/screens/authentication-screen/authentication-check-screen.stories.tsx"), "./app/screens/authentication-screen/authentication-screen.stories.tsx": require("../app/screens/authentication-screen/authentication-screen.stories.tsx"), "./app/screens/authentication-screen/pin-screen.stories.tsx": require("../app/screens/authentication-screen/pin-screen.stories.tsx"), - "./app/screens/conversation/conversation.stories.tsx": require("../app/screens/conversation/conversation.stories.tsx"), + "./app/screens/conversation/conversation.stories.tsx": require("../app/screens/chatbot-screen/chatbot.stories.tsx"), "./app/screens/conversion-flow/conversion-success-screen.stories.tsx": require("../app/screens/conversion-flow/conversion-success-screen.stories.tsx"), "./app/screens/earns-map-screen/earns-map-screen.stories.tsx": require("../app/screens/earns-map-screen/earns-map-screen.stories.tsx"), "./app/screens/earns-screen/earns-quiz.stories.tsx": require("../app/screens/earns-screen/earns-quiz.stories.tsx"), @@ -104,7 +101,7 @@ const getStories = () => { "./app/screens/settings-screen/settings-screen.stories.tsx": require("../app/screens/settings-screen/settings-screen.stories.tsx"), "./app/screens/settings-screen/theme-screen.stories.tsx": require("../app/screens/settings-screen/theme-screen.stories.tsx"), "./app/screens/transaction-detail-screen/transaction-detail-screen.stories.tsx": require("../app/screens/transaction-detail-screen/transaction-detail-screen.stories.tsx"), - }; -}; + } +} -configure(getStories, module, false); +configure(getStories, module, false) diff --git a/.storybook/storybook.tsx b/.storybook/storybook.tsx index de63055e6b..937c40ea8b 100644 --- a/.storybook/storybook.tsx +++ b/.storybook/storybook.tsx @@ -22,7 +22,7 @@ RNBootSplash.hide({ fade: true }) const StorybookUI = getStorybookUI({ enableWebsockets: true, onDeviceUI: true, - initialSelection: { kind: "Conversation Screen", name: "Default" }, + initialSelection: { kind: "ChatBot Screen", name: "Default" }, shouldPersistSelection: false, }) diff --git a/app/navigation/root-navigator.tsx b/app/navigation/root-navigator.tsx index 3cca209143..3ea775ea70 100644 --- a/app/navigation/root-navigator.tsx +++ b/app/navigation/root-navigator.tsx @@ -5,7 +5,7 @@ import LearnIcon from "@app/assets/icons/learn.svg" import MapIcon from "@app/assets/icons/map.svg" import { useIsAuthed } from "@app/graphql/is-authed-context" import { useI18nContext } from "@app/i18n/i18n-react" -import { ConversationScreen } from "@app/screens/conversation/conversation" +import { ChatBotScreen } from "@app/screens/chatbot-screen/chatbot" import { ConversionConfirmationScreen, ConversionDetailsScreen, @@ -412,7 +412,7 @@ export const RootStack = () => { /> {Story()}], -} as Meta +} as Meta export const Empty = () => ( - + ) @@ -77,7 +77,7 @@ export const Empty = () => ( export const Default = () => ( - + ) diff --git a/app/screens/conversation/conversation.tsx b/app/screens/chatbot-screen/chatbot.tsx similarity index 94% rename from app/screens/conversation/conversation.tsx rename to app/screens/chatbot-screen/chatbot.tsx index 70148a16e1..685ac26488 100644 --- a/app/screens/conversation/conversation.tsx +++ b/app/screens/chatbot-screen/chatbot.tsx @@ -1,6 +1,7 @@ import { useState, useRef } from "react" import { ActivityIndicator, + Alert, FlatList, Keyboard, TouchableHighlight, @@ -55,7 +56,7 @@ gql` } ` -export const ConversationScreen = () => { +export const ChatBotScreen = () => { const styles = useStyles() const { theme } = useTheme() @@ -102,13 +103,10 @@ export const ConversationScreen = () => { await supportChatMessageAdd({ variables: { input: { message: input } }, update: (cache, { data }) => { - // If mutation didn't return any data, return early if (!data || !data.supportChatMessageAdd.supportMessage) return - // Add the new message to the chat array const newMessages = data.supportChatMessageAdd.supportMessage - // Write the updated chats back to the cache cache.writeQuery({ query: SupportChatDocument, data: { @@ -120,10 +118,18 @@ export const ConversationScreen = () => { }, }) } catch (err) { + // TODO: translation + Alert.alert("Error", "An error occurred while sending the message") console.log("error: ", err) } finally { setPendingInput("") setTimeout(() => { + // TODO: improve code clarity + // supportChatMaybeInput should be the "cache" version prior to the table update + // and length will increase by 1 after the update + // so I think supportChatMaybeInput.length - 1 + // is actually mapping to supportChatMaybeInput.length - 2 + // when consideing the new message const indexBeforeLast = supportChatMaybeInput.length - 1 if (indexBeforeLast >= 0) { flatListRef.current?.scrollToIndex({ index: indexBeforeLast, animated: true }) @@ -136,12 +142,13 @@ export const ConversationScreen = () => { setInput(v) } + // TODO: make it work async function clearChat() { if (loading) return - // setOpenaiResponse([]) setInput("") } + // FIXME: this is not working async function showClipboardActionsheet(text: string) { console.log("showClipboardActionsheet", text) diff --git a/app/screens/settings-screen/settings-screen.tsx b/app/screens/settings-screen/settings-screen.tsx index 40ca0d1e14..8ccda7d17d 100644 --- a/app/screens/settings-screen/settings-screen.tsx +++ b/app/screens/settings-screen/settings-screen.tsx @@ -88,7 +88,6 @@ export const SettingsScreen: React.FC = () => { skip: !isAtLeastLevelZero, }) - // get beta flag const betaQuery = useBetaQuery() const beta = betaQuery.data?.beta ?? false