Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Toasts #16

Merged
merged 2 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/icons/check-circle-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/exclamation-triangle-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions assets/icons/shield-exclamation-icon.svg

This file was deleted.

16 changes: 8 additions & 8 deletions assets/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@
/* --------------------------------------- */
--field-bg-primary: var(--background-primary-light);

/* label */
--field-label-font-family: var(--app-font-family-main);
--field-label-font-size: #{toRem(14)};
--field-label-font-weight: 400;
--field-label-line-height: #{toRem(22)};
--field-label-letter-spacing: 0;
--field-label: var(--text-primary-main);
--field-label-margin-bottom: #{toRem(4)};
/* label */
--field-label-font-family: var(--app-font-family-main);
--field-label-font-size: #{toRem(14)};
--field-label-font-weight: 400;
--field-label-line-height: #{toRem(22)};
--field-label-letter-spacing: 0;
--field-label: var(--text-primary-main);
--field-label-margin-bottom: #{toRem(4)};

/* text */
--field-text-font-family: var(--app-font-family-main);
Expand Down
100 changes: 100 additions & 0 deletions components/AppNotification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<template>
<div class="app-notification">
<app-icon class="app-notification__icon" :name="iconName" />
<div class="app-notification__details">
<p class="app-notification__title">
{{ title }}
</p>
<p class="app-notification__message">
{{ message }}
</p>
</div>
<app-button
class="app-notification__close-btn"
color="secondary"
modification="text"
:icon-left="ICON_NAMES.x"
@click="emit('close-toast')"
/>
</div>
</template>

<script lang="ts" setup>
import { AppButton, AppIcon } from '#components'
import { ICON_NAMES } from '@/enums'

const emit = defineEmits<{
(event: 'close-toast'): void
}>()

defineProps<{
title: string
message: string
iconName: ICON_NAMES
}>()
</script>

<style lang="scss">
@import 'vue-toastification/src/scss/index.scss';

.Vue-Toastification__toast {
padding: toRem(24) toRem(70) toRem(24) toRem(24);
background-color: var(--background-primary-main);
border-radius: var(--border-radius-main);
width: 100%;
max-width: toRem(420);
}

.Vue-Toastification__progress-bar {
background: var(--text-primary-main);
}

.app-notification {
display: grid;
grid-template-columns: max-content 1fr;
grid-gap: toRem(16);
}

.app-notification .app-notification__icon {
max-width: toRem(24);
max-height: toRem(24);

.Vue-Toastification__toast--success & {
color: var(--success-main);
}

.Vue-Toastification__toast--error & {
color: var(--error-main);
}

.Vue-Toastification__toast--warning & {
color: var(--warning-main);
}

.Vue-Toastification__toast--info & {
color: var(--info-main);
}
}

.app-notification__details {
display: grid;
grid-gap: toRem(4);
width: 100%;
}

.app-notification__title {
@include p-16-medium;
}

.app-notification__message {
color: var(--text-primary-main);

@include p-14-regular;
}

.app-notification__close-btn {
position: absolute;
top: toRem(24);
right: toRem(24);
}
</style>
142 changes: 0 additions & 142 deletions components/DefaultToast.vue

This file was deleted.

23 changes: 10 additions & 13 deletions composables/use-notifications.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { AppNotification } from '#components'
import { ICON_NAMES } from '@/enums'
import { CommonNotificationTypes, NotificationObjectPayload } from '@/types'
import isObject from 'lodash/isObject'
import { TYPE, useToast } from 'vue-toastification'

import { DefaultToast } from '#components'
import { i18n } from '~/plugins/localization'
import { CommonNotificationTypes, NotificationObjectPayload } from '@/types'

const MINUTE = 60 * 1000

export const useNotifications = () => {
const toast = useToast()
Expand All @@ -21,18 +18,18 @@ export const useNotifications = () => {
[TYPE.DEFAULT]: t('notification.default-title-default'),
}
const defaultMessages = {
[TYPE.DEFAULT]: t('notification.default-message-default'),
[TYPE.INFO]: t('notification.default-message-info'),
[TYPE.SUCCESS]: t('notification.default-message-success'),
[TYPE.ERROR]: t('notification.default-message-error'),
[TYPE.WARNING]: t('notification.default-message-warning'),
[TYPE.INFO]: t('notification.default-message-info'),
[TYPE.DEFAULT]: t('notification.default-message-default'),
}
const defaultIconNames = {
[TYPE.DEFAULT]: ICON_NAMES.exclamationCircle,
[TYPE.INFO]: ICON_NAMES.exclamationCircle,
[TYPE.SUCCESS]: ICON_NAMES.checkCircle,
[TYPE.ERROR]: ICON_NAMES.exclamationCircle,
[TYPE.WARNING]: ICON_NAMES.shieldExclamation,
[TYPE.WARNING]: ICON_NAMES.exclamationTriangle,
[TYPE.INFO]: ICON_NAMES.exclamationCircle,
[TYPE.DEFAULT]: ICON_NAMES.exclamationCircle,
}

const showToast = (
Expand Down Expand Up @@ -64,7 +61,7 @@ export const useNotifications = () => {

return toast(
{
component: DefaultToast,
component: AppNotification,
props: {
...(title && { title }),
message,
Expand All @@ -80,9 +77,9 @@ export const useNotifications = () => {
error: TYPE.ERROR,
warning: TYPE.WARNING,
}[messageType],
toastClassName: 'default-toast',
timeout: MINUTE / 2,
timeout: 30000,
closeOnClick: false,
closeButton: false,
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion enums/icon-names.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export enum ICON_NAMES {
download = 'download',
duplicate = 'duplicate',
exclamationCircle = 'exclamation-circle',
exclamationTriangle = 'exclamation-triangle',
hashtag = 'hashtag',
locationMarker = 'location-marker',
plus = 'plus',
refresh = 'refresh',
shieldExclamation = 'shield-exclamation',
xCircle = 'x-circle',
x = 'x',
}
2 changes: 1 addition & 1 deletion forms/AbiDecodeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
'abi-decode-form__icon',
'abi-decode-form__icon--warning',
]"
:name="$icons.exclamationCircle"
:name="$icons.exclamationTriangle"
/>
<p
:class="['abi-decode-form__msg', 'abi-decode-form__msg--warning']"
Expand Down
19 changes: 2 additions & 17 deletions helpers/error-handler.helper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import log from 'loglevel'
import { bus, BUS_EVENTS } from '@/helpers'
import { i18n } from '~/plugins/localization'
import { getErrorMessage } from './errors.helpers'

export class ErrorHandler {
static process(error: Error | unknown, errorMessage = ''): void {
const msgTranslation = errorMessage || ErrorHandler._getErrorMessage(error)
const msgTranslation = errorMessage || getErrorMessage(error)
bus.emit(BUS_EVENTS.error, msgTranslation)

ErrorHandler.processWithoutFeedback(error)
Expand All @@ -13,19 +13,4 @@ export class ErrorHandler {
static processWithoutFeedback(error: Error | unknown): void {
log.error(error)
}

static _getErrorMessage(error: Error | unknown): string {
let errorMessage = ''

const { t } = i18n.global

if (error instanceof Error)
switch (error.constructor) {
default: {
errorMessage = t('errors.default')
}
}

return errorMessage
}
}
Loading