Skip to content

Commit

Permalink
fix: show error with html formatting for toasts
Browse files Browse the repository at this point in the history
fix #1914
  • Loading branch information
BreadGenie committed Nov 5, 2024
1 parent 0a71e20 commit 0752655
Show file tree
Hide file tree
Showing 27 changed files with 109 additions and 195 deletions.
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"vue-echarts": "^6.6.1",
"vue-qrcode": "^2.2.2",
"vue-router": "^4.0.5",
"vue-sonner": "^0.4.4"
"vue-sonner": "^1.2.5"
},
"devDependencies": {
"@iconify/json": "^2.2.123",
Expand Down
7 changes: 2 additions & 5 deletions dashboard/src2/components/MarketplaceAppListing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
import { TextEditor } from 'frappe-ui';
import FileUploader from '@/components/FileUploader.vue';
import { toast } from 'vue-sonner';
import { getToastErrorMessage } from '../utils/toast';
export default {
name: 'MarketplaceAppOverview',
Expand Down Expand Up @@ -266,11 +267,7 @@ export default {
this.marketplaceApp = { ...this.marketplaceApp, ...response.message };
},
onError(e) {
toast.error(
e.messages?.length
? e.messages.join('\n')
: e.message || 'Failed to fetch listing data'
);
toast.error(getToastErrorMessage(e, 'Failed to fetch listing data'));
}
};
},
Expand Down
5 changes: 2 additions & 3 deletions dashboard/src2/components/SiteActionCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { getCachedDocumentResource } from 'frappe-ui';
import { defineAsyncComponent, h } from 'vue';
import { toast } from 'vue-sonner';
import { confirmDialog, renderDialog } from '../utils/components';
import { getToastErrorMessage } from '../utils/toast';
import router from '../router';
import { isLastSite } from '../data/team';
Expand Down Expand Up @@ -257,9 +258,7 @@ function onScheduleBackup() {
});
return 'Backup scheduled successfully';
},
error: e => {
return e.messages?.length ? e.messages.join('\n') : e.message;
}
error: e => getToastErrorMessage(e)
}
);
}
Expand Down
5 changes: 2 additions & 3 deletions dashboard/src2/components/SiteOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ import { h, defineAsyncComponent } from 'vue';
import { toast } from 'vue-sonner';
import InfoIcon from '~icons/lucide/info';
import DismissableBanner from './DismissableBanner.vue';
import { getToastErrorMessage } from '../utils/toast';
import { renderDialog } from '../utils/components';
import SiteDailyUsage from './SiteDailyUsage.vue';
import AlertBanner from './AlertBanner.vue';
Expand Down Expand Up @@ -265,9 +266,7 @@ export default {
{
loading: 'Removing tag...',
success: `Tag ${tag.tag_name} removed`,
error: e => {
return e.messages.length ? e.messages.join('\n') : e.message;
}
error: e => getToastErrorMessage(e)
}
);
},
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src2/components/group/AddAppDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ import {
} from 'frappe-ui';
import { toast } from 'vue-sonner';
import { h } from 'vue';
import { getToastErrorMessage } from '../../utils/toast';
import NewAppDialog from '../NewAppDialog.vue';
export default {
Expand Down Expand Up @@ -183,7 +184,7 @@ export default {
this.$emit('appAdd');
},
onError(e) {
toast.error(e.messages.length ? e.messages.join('\n') : e.message);
toast.error(getToastErrorMessage(e));
}
},
installableApps() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

<script>
import { toast } from 'vue-sonner';
import { getToastErrorMessage } from '../../utils/toast';
import { DashboardError } from '../../utils/error';
export default {
Expand Down Expand Up @@ -85,10 +86,7 @@ export default {
this.$emit('branch-changed');
return 'Branch changed successfully';
},
error: e => {
console.log(e);
return e.messages.length ? e.messages.join('\n') : e.message;
}
error: e => getToastErrorMessage(e)
});
},
branchList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import { toast } from 'vue-sonner';
import GitHubAppSelector from '../GitHubAppSelector.vue';
import LinkControl from '../LinkControl.vue';
import { getToastErrorMessage } from '../../utils/toast';
export default {
components: {
Expand Down Expand Up @@ -123,9 +124,7 @@ export default {
});
return 'New app added';
},
error: e => {
return e.messages.length ? e.messages.join('\n') : e.message;
}
error: e => getToastErrorMessage(e)
});
},
validateApp(data) {
Expand Down
6 changes: 2 additions & 4 deletions dashboard/src2/components/marketplace/PlansDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<script>
import { toast } from 'vue-sonner';
import { DashboardError } from '../../utils/error';
import { getToastErrorMessage } from '../../utils/toast';
export default {
name: 'PlanDialog',
Expand Down Expand Up @@ -193,10 +194,7 @@ export default {
return 'Plan created successfully';
}
},
error: e => {
console.log(e);
return e.messages.length ? e.messages.join('\n') : e.message;
}
error: e => getToastErrorMessage(e)
}
);
},
Expand Down
8 changes: 5 additions & 3 deletions dashboard/src2/components/server/ServerOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import { toast } from 'vue-sonner';
import { h, defineAsyncComponent } from 'vue';
import { getCachedDocumentResource } from 'frappe-ui';
import { confirmDialog, renderDialog } from '../../utils/components';
import { getToastErrorMessage } from '../../utils/toast';
import ServerPlansDialog from './ServerPlansDialog.vue';
import ServerLoadAverage from './ServerLoadAverage.vue';
import { getDocResource } from '../../utils/resource';
Expand Down Expand Up @@ -274,9 +275,10 @@ export default {
loading: 'Increasing disk size...',
success: 'Disk size is scheduled to increase',
error: e =>
e.messages.length
? e.messages.join('\n')
: e.message || 'Failed to increase disk size'
getToastErrorMessage(
e,
'Failed to increase disk size'
)
}
);
}
Expand Down
13 changes: 9 additions & 4 deletions dashboard/src2/components/settings/EditWebhookDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
</FormControl>
<p class="mt-1.5 text-sm text-gray-700">
<secret>Note:</secret> Secret is optional. Check
<a href="https://frappecloud.com/docs/webhook-introduction" class="underline" target="_blank"
<a
href="https://frappecloud.com/docs/webhook-introduction"
class="underline"
target="_blank"
>the documentation</a
>
to learn more
Expand Down Expand Up @@ -77,6 +80,7 @@

<script>
import { toast } from 'vue-sonner';
import { getToastErrorMessage } from '../../utils/toast';
export default {
emits: ['success'],
Expand Down Expand Up @@ -140,9 +144,10 @@ export default {
},
onError: e => {
toast.error(
e.messages.length
? e.messages.join('\n')
: e.message || 'Failed to update webhook'
getToastErrorMessage(
e,
'Failed to update webhook. Please try again'
)
);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<script>
import { toast } from 'vue-sonner';
import { DashboardError } from '../../utils/error';
import { getToastErrorMessage } from '../../utils/toast';
export default {
data() {
Expand Down Expand Up @@ -123,7 +124,7 @@ export default {
this.show = false;
return 'Invite Sent!';
},
error: e => (e.messages?.length ? e.messages.join('\n') : e.message)
error: e => getToastErrorMessage(e)
}
);
}
Expand Down
5 changes: 3 additions & 2 deletions dashboard/src2/components/settings/RoleConfigureDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import { Switch, Tabs } from 'frappe-ui';
import { toast } from 'vue-sonner';
import UserWithAvatarCell from '../UserWithAvatarCell.vue';
import { getToastErrorMessage } from '../../utils/toast';
export default {
props: {
Expand Down Expand Up @@ -280,14 +281,14 @@ export default {
this.member = {};
return `${user} added to ${this.role.title}`;
},
error: e => (e.messages.length ? e.messages.join('\n') : e.message)
error: e => getToastErrorMessage(e)
});
},
removeUser(user) {
return toast.promise(this.$resources.role.removeUser.submit({ user }), {
loading: `Removing ${user} from ${this.role.title}`,
success: () => `${user} removed from ${this.role.title}`,
error: e => (e.messages.length ? e.messages.join('\n') : e.message)
error: e => getToastErrorMessage(e)
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src2/components/settings/RoleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ObjectList from '../ObjectList.vue';
import RoleConfigureDialog from './RoleConfigureDialog.vue';
import router from '../../router';
import UserAvatarGroup from '../AvatarGroup.vue';
import { getToastErrorMessage } from '../../utils/toast';
const listOptions = ref({
doctype: 'Press Role',
Expand Down Expand Up @@ -74,8 +75,7 @@ const listOptions = ref({
hide();
return `Role ${row.title} deleted`;
},
error: e =>
e.messages.length ? e.messages.join('\n') : e.message
error: e => getToastErrorMessage(e)
});
}
});
Expand Down
5 changes: 1 addition & 4 deletions dashboard/src2/components/settings/RolePermissions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ const rolePermissions = ref({
permissions.reload();
return 'Permission added successfully';
},
error: e =>
e.messages.length
? e.messages.join('\n')
: 'An error occurred'
error: e => getToastErrorMessage(e)
}
);
}
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src2/components/settings/TeamSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getTeam } from '../../data/team';
import { confirmDialog, renderDialog } from '../../utils/components';
import ObjectList from '../ObjectList.vue';
import UserWithAvatarCell from '../UserWithAvatarCell.vue';
import { getToastErrorMessage } from '../../utils/toast';
const team = getTeam();
team.getTeamMembers.submit();
Expand Down Expand Up @@ -56,8 +57,7 @@ const teamMembersListOptions = ref({
hide();
return 'Member Removed';
},
error: e =>
e.messages.length ? e.messages.join('\n') : e.message
error: e => getToastErrorMessage(e)
}
);
}
Expand Down
11 changes: 3 additions & 8 deletions dashboard/src2/components/site/InstallAppDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { toast } from 'vue-sonner';
import { renderDialog } from '../../utils/components';
import router from '../../router';
import ObjectList from '../ObjectList.vue';
import { getToastErrorMessage } from '../../utils/toast';
export default {
props: {
Expand Down Expand Up @@ -75,11 +76,7 @@ export default {
this.show = false;
return 'App will be installed shortly';
},
error: e => {
return e.messages?.length
? e.messages.join('\n')
: e.message;
}
error: e => getToastErrorMessage(e)
}
);
}
Expand All @@ -104,9 +101,7 @@ export default {
this.show = false;
return 'App will be installed shortly';
},
error: e => {
return e.messages?.length ? e.messages.join('\n') : e.message;
}
error: e => getToastErrorMessage(e)
}
);
}
Expand Down
5 changes: 2 additions & 3 deletions dashboard/src2/components/site/SiteAppPlanSelectDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</template>

<script>
import { getToastErrorMessage } from '../../utils/toast';
import SiteAppPlanSelectorDialog from './SiteAppPlanSelectorDialog.vue';
import { toast } from 'vue-sonner';
Expand Down Expand Up @@ -43,9 +44,7 @@ export default {
this.$emit('plan-changed', plan);
return 'Plan changed successfully';
},
error: e => {
return e.messages.length ? e.messages.join('\n') : e.message;
}
error: e => getToastErrorMessage(e)
}
);
else this.$emit('plan-selected', plan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import { getCachedDocumentResource } from 'frappe-ui';
import AlertBanner from '../../AlertBanner.vue';
import { toast } from 'vue-sonner';
import { getToastErrorMessage } from '../../../utils/toast';
export default {
props: [
Expand Down Expand Up @@ -131,9 +132,7 @@ export default {
});
return 'The job to add a database index has been sucessfully created.';
},
error: e => {
return e.messages.length ? e.messages.join('\n') : e.message;
}
error: e => getToastErrorMessage(e)
});
},
shouldShowAnalyzeQueryButton() {
Expand Down
9 changes: 3 additions & 6 deletions dashboard/src2/objects/common/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
} from './types';
import { getUpsellBanner } from '.';
import { isMobile } from '../../utils/device';
import { getToastErrorMessage } from '../../utils/toast';

export function getAppsTab(forSite: boolean) {
return {
Expand Down Expand Up @@ -214,7 +215,7 @@ const siteAppListOptions: Partial<TabList> = {
}),
{
loading: 'Scheduling app uninstall...',
success: jobId => {
success: (jobId: string) => {
hide();
router.push({
name: 'Site Job',
Expand All @@ -225,11 +226,7 @@ const siteAppListOptions: Partial<TabList> = {
});
return 'App uninstall scheduled';
},
error: e => {
return e.messages?.length
? e.messages.join('\n')
: e.message;
}
error: (e: Error) => getToastErrorMessage(e)
}
);
}
Expand Down
Loading

0 comments on commit 0752655

Please sign in to comment.