Skip to content

Commit

Permalink
Merge branch 'develop' into fix/omni-removed-room-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jun 22, 2023
2 parents 88de4f8 + 9a65911 commit 91caf83
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 50 deletions.
49 changes: 0 additions & 49 deletions packages/livechat/src/components/Alert/index.js

This file was deleted.

68 changes: 68 additions & 0 deletions packages/livechat/src/components/Alert/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { useCallback, useEffect } from 'preact/hooks';
import type { JSXInternal } from 'preact/src/jsx';
import { useTranslation } from 'react-i18next';

import CloseIcon from '../../icons/close.svg';
import { createClassName } from '../helpers';
import styles from './styles.scss';

type AlertProps = {
id?: string;
onDismiss?: (id?: string) => void;
success?: boolean;
warning?: boolean;
error?: boolean;
color?: string;
hideCloseButton?: boolean;
className?: string;
style?: JSXInternal.CSSProperties;
children?: JSXInternal.Element[];
timeout?: number;
};

const Alert = ({
id,
onDismiss,
success,
warning,
error,
color,
hideCloseButton = false,
className,
style = {},
children,
timeout = 3000,
}: AlertProps) => {
const { t } = useTranslation();
const handleDismiss = useCallback(() => {
onDismiss?.(id);
}, [id, onDismiss]);

useEffect(() => {
let dismissTimeout: ReturnType<typeof setTimeout> | undefined;
if (Number.isFinite(timeout) && timeout > 0) {
dismissTimeout = setTimeout(handleDismiss, timeout);
}
return () => clearTimeout(dismissTimeout);
}, [handleDismiss, timeout]);

return (
<div
role='alert'
className={createClassName(styles, 'alert', { success, warning, error }, [className])}
style={{
...style,
...(color && { backgroundColor: color }),
}}
>
<div className={createClassName(styles, 'alert__content')}>{children}</div>
{!hideCloseButton && (
<button onClick={handleDismiss} className={createClassName(styles, 'alert__close')} aria-label={t('dismiss_this_alert')}>
<CloseIcon width={20} height={20} />
</button>
)}
</div>
);
};

export default Alert;
4 changes: 4 additions & 0 deletions packages/livechat/src/definitions/svg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.svg' {
const content: Preact.FunctionComponent<Preact.SVGAttributes<SVGElement>>;
export default content;
}
2 changes: 2 additions & 0 deletions packages/livechat/src/i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ export default i18next
fallbackLng: 'en',
react: {
useSuspense: false,
bindI18n: 'loaded languageChanged',
bindI18nStore: 'added',
}
});
2 changes: 1 addition & 1 deletion packages/livechat/src/lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const Connection = {

async connect() {
try {
await import('../i18next');
this.clearListeners();
await loadConfig();
await import('../i18next');
// await Livechat.connection.connect();
this.addListeners();
this.clearAlerts();
Expand Down

0 comments on commit 91caf83

Please sign in to comment.