Skip to content

Commit

Permalink
update linting and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryHengZJ committed Sep 9, 2024
1 parent 2b4e38c commit 9348508
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 36 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ You can also customize chatbot with different configuration
company: 'Flowise',
companyLink: 'https://flowiseai.com',
},
disclaimer: {
title: 'Disclaimer',
message: 'By using this chatbot, you agree to the <a target="_blank" href="https://flowiseai.com/terms">Terms & Condition</a>',
}
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion dist/components/Bot.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/features/popup/components/DisclaimerPopup.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/utils/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions src/components/Bot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,18 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
setUploadedFiles([]);
scrollToBottom();
};

const handleDisclaimerAccept = () => {
setDisclaimerPopupOpen(false); // Close the disclaimer popup
setCookie("chatbotDisclaimer", "true", 365); // Disclaimer accepted
setCookie('chatbotDisclaimer', 'true', 365); // Disclaimer accepted
};

const promptClick = (prompt: string) => {
handleSubmit(prompt);
};

// Handle form submission
const handleSubmit = async (value: string, action?: IAction | undefined | null) => {
const handleSubmit = async (value: string, action?: IAction | undefined | null) => {
if (value.trim() === '') {
const containsFile = previews().filter((item) => !item.mime.startsWith('image') && item.type !== 'audio').length > 0;
if (!previews().length || (previews().length && containsFile)) {
Expand Down Expand Up @@ -653,15 +653,14 @@ export const Bot = (botProps: BotProps & { class?: string }) => {

// eslint-disable-next-line solid/reactivity
createEffect(async () => {

if (props.disclaimer) {
if (getCookie("chatbotDisclaimer") == "true") {
setDisclaimerPopupOpen(false)
if (getCookie('chatbotDisclaimer') == 'true') {
setDisclaimerPopupOpen(false);
} else {
setDisclaimerPopupOpen(true)
setDisclaimerPopupOpen(true);
}
} else {
setDisclaimerPopupOpen(false)
setDisclaimerPopupOpen(false);
}

const chatMessage = getLocalStorageChatflow(props.chatflowid);
Expand Down Expand Up @@ -1350,12 +1349,11 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
<DisclaimerPopup
isOpen={disclaimerPopupOpen()}
onAccept={handleDisclaimerAccept}
title={props.disclaimer?.title}
title={props.disclaimer?.title}
message={props.disclaimer?.message}
buttonText={props.disclaimer?.buttonText}
/>
)}

</>
);
};
19 changes: 5 additions & 14 deletions src/features/popup/components/DisclaimerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ export type DisclaimerPopupProps = {
};

export const DisclaimerPopup = (props: DisclaimerPopupProps) => {
const [popupProps] = splitProps(props, [
'onAccept',
'isOpen',
'title',
'message',
'buttonText',
]);
const [popupProps] = splitProps(props, ['onAccept', 'isOpen', 'title', 'message', 'buttonText']);

const handleAccept = () => {
props.onAccept?.();
Expand All @@ -25,16 +19,13 @@ export const DisclaimerPopup = (props: DisclaimerPopupProps) => {
<Show when={popupProps.isOpen}>
<div class="fixed inset-0 rounded-lg flex items-center justify-center bg-black bg-opacity-40 backdrop-blur-sm z-50">
<div class="bg-white p-10 rounded-lg shadow-lg max-w-md w-full text-center mx-4 font-sans">
<h2 class="text-2xl font-semibold mb-4 flex justify-center items-center">
{popupProps.title ?? 'Disclaimer'}
</h2>
<h2 class="text-2xl font-semibold mb-4 flex justify-center items-center">{popupProps.title ?? 'Disclaimer'}</h2>

<p
class="text-gray-700 text-base mb-6"
innerHTML={popupProps.message ??
'By using this chatbot, you acknowledge and accept these terms.'}
></p>

innerHTML={popupProps.message ?? 'By using this chatbot, you acknowledge and accept these terms.'}
/>

<div class="flex justify-center">
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded focus:outline-none focus:shadow-outline"
Expand Down
16 changes: 8 additions & 8 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ export const getBubbleButtonSize = (size: 'small' | 'medium' | 'large' | number

export const setCookie = (cname: string, cvalue: string, exdays: number) => {
const d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
const expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
const expires = 'expires=' + d.toUTCString();
document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';
};

export const getCookie = (cname: string): string =>{
const name = cname + "=";
export const getCookie = (cname: string): string => {
const name = cname + '=';
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
Expand All @@ -148,5 +148,5 @@ export const getCookie = (cname: string): string =>{
return c.substring(name.length, c.length);
}
}
return "";
}
return '';
};

0 comments on commit 9348508

Please sign in to comment.