Skip to content

Commit

Permalink
fix: use yarn 4, notify on password change (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia authored Nov 10, 2023
1 parent d357263 commit 7fdde36
Show file tree
Hide file tree
Showing 7 changed files with 4,437 additions and 4,928 deletions.
541 changes: 0 additions & 541 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

This file was deleted.

874 changes: 0 additions & 874 deletions .yarn/releases/yarn-3.6.3.cjs

This file was deleted.

893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.1.cjs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
nodeLinker: node-modules
compressionLevel: mixed

enableGlobalCache: false

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.6.3.cjs
yarnPath: .yarn/releases/yarn-4.0.1.cjs
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@emotion/cache": "11.11.0",
"@emotion/react": "11.11.1",
"@emotion/styled": "11.11.0",
"@graasp/query-client": "2.0.0",
"@graasp/query-client": "2.0.1",
"@graasp/sdk": "2.0.0",
"@graasp/translations": "1.19.4",
"@graasp/ui": "4.0.0",
Expand All @@ -30,6 +30,7 @@
"@uppy/status-bar": "^3.2.4",
"@uppy/tus": "3.3.0",
"@uppy/xhr-upload": "3.4.0",
"axios": "0.27.2",
"connected-react-router": "6.9.3",
"filesize": "^10.0.12",
"http-status-codes": "2.3.0",
Expand Down Expand Up @@ -124,5 +125,5 @@
"vite-plugin-checker": "0.6.2",
"vite-plugin-istanbul": "5.0.0"
},
"packageManager": "yarn@3.6.3"
"packageManager": "yarn@4.0.1"
}
31 changes: 30 additions & 1 deletion src/config/notifier.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { toast } from 'react-toastify';

import { Notifier, routines } from '@graasp/query-client';
import { FAILURE_MESSAGES } from '@graasp/translations';

import { AxiosError } from 'axios';

import i18n from './i18n';
import {
CHANGE_PLAN_ERROR_MESSAGE,
CHANGE_PLAN_SUCCESS_MESSAGE,
} from './messages';

const { changePlanRoutine } = routines;
const { changePlanRoutine, updatePasswordRoutine } = routines;

type ErrorPayload = Parameters<Notifier>[0]['payload'] & {
failure?: unknown[];
Expand All @@ -20,6 +23,23 @@ type SuccessPayload = {

type Payload = ErrorPayload & SuccessPayload;

const getErrorMessageFromPayload = (
payload?: Parameters<Notifier>[0]['payload'],
) => {
if (payload?.error && payload.error instanceof AxiosError) {
if (payload.error.isAxiosError) {
return (
payload.error.response?.data.message ??
FAILURE_MESSAGES.UNEXPECTED_ERROR
);
}
}
return payload?.error?.message ?? FAILURE_MESSAGES.UNEXPECTED_ERROR;
};

const getSuccessMessageFromPayload = (payload?: SuccessPayload) =>
i18n.t(payload?.message ?? 'The operation successfully proceeded');

export default ({
type,
payload,
Expand All @@ -30,10 +50,19 @@ export default ({
let message = null;
switch (type) {
// error messages
case updatePasswordRoutine.FAILURE: {
message = getErrorMessageFromPayload(payload);
break;
}
case changePlanRoutine.FAILURE: {
message = CHANGE_PLAN_ERROR_MESSAGE;
break;
}
// success messages
case updatePasswordRoutine.SUCCESS: {
message = getSuccessMessageFromPayload(payload);
break;
}

// progress messages
case changePlanRoutine.SUCCESS: {
Expand Down
Loading

0 comments on commit 7fdde36

Please sign in to comment.