## 概要 [Task2651: 画面実装(テンプレートファイル一覧画面)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2651) - テンプレートファイル一覧画面を実装 ## レビューポイント - 取得方法やstoreの構成は問題ないか ## UIの変更 - https://ndstokyo.sharepoint.com/:f:/r/sites/Piranha/Shared%20Documents/General/OMDS/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88/Task2651?csf=1&web=1&e=MAaOJd ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば
106 lines
3.0 KiB
TypeScript
106 lines
3.0 KiB
TypeScript
import { createAsyncThunk } from "@reduxjs/toolkit";
|
|
import type { RootState } from "app/store";
|
|
import { ErrorObject, createErrorObject } from "common/errors";
|
|
import { getTranslationID } from "translation";
|
|
import { openSnackbar } from "features/ui/uiSlice";
|
|
import { AccountsApi, UpdateAccountInfoRequest, UsersApi } from "../../api/api";
|
|
import { Configuration } from "../../api/configuration";
|
|
import { ViewAccountRelationsInfo } from "./types";
|
|
|
|
export const getAccountRelationsAsync = createAsyncThunk<
|
|
// 正常時の戻り値の型
|
|
ViewAccountRelationsInfo,
|
|
void,
|
|
{
|
|
// rejectした時の返却値の型
|
|
rejectValue: {
|
|
error: ErrorObject;
|
|
};
|
|
}
|
|
>("accounts/getAccountRelationsAsync", async (_args, thunkApi) => {
|
|
// apiのConfigurationを取得する
|
|
const { getState } = thunkApi;
|
|
const state = getState() as RootState;
|
|
const { configuration, accessToken } = state.auth;
|
|
const config = new Configuration(configuration);
|
|
const accountsApi = new AccountsApi(config);
|
|
const usersApi = new UsersApi(config);
|
|
|
|
try {
|
|
const accountInfo = await accountsApi.getMyAccount({
|
|
headers: { authorization: `Bearer ${accessToken}` },
|
|
});
|
|
const dealers = await accountsApi.getDealers();
|
|
const users = await usersApi.getUsers({
|
|
headers: { authorization: `Bearer ${accessToken}` },
|
|
});
|
|
return {
|
|
accountInfo: accountInfo.data,
|
|
dealers: dealers.data,
|
|
users: users.data,
|
|
};
|
|
} catch (e) {
|
|
// e ⇒ errorObjectに変換"
|
|
const error = createErrorObject(e);
|
|
thunkApi.dispatch(
|
|
openSnackbar({
|
|
level: "error",
|
|
message: getTranslationID("common.message.internalServerError"),
|
|
})
|
|
);
|
|
return thunkApi.rejectWithValue({ error });
|
|
}
|
|
});
|
|
|
|
export const updateAccountInfoAsync = createAsyncThunk<
|
|
{
|
|
/* Empty Object */
|
|
},
|
|
UpdateAccountInfoRequest,
|
|
{
|
|
// rejectした時の返却値の型
|
|
rejectValue: {
|
|
error: ErrorObject;
|
|
};
|
|
}
|
|
>("accounts/updateAccountInfoAsync", async (args, thunkApi) => {
|
|
// apiのConfigurationを取得する
|
|
const { getState } = thunkApi;
|
|
const state = getState() as RootState;
|
|
const { configuration, accessToken } = state.auth;
|
|
const config = new Configuration(configuration);
|
|
const accountApi = new AccountsApi(config);
|
|
|
|
try {
|
|
await accountApi.updateAccountInfo(args, {
|
|
headers: { authorization: `Bearer ${accessToken}` },
|
|
});
|
|
thunkApi.dispatch(
|
|
openSnackbar({
|
|
level: "info",
|
|
message: getTranslationID("common.message.success"),
|
|
})
|
|
);
|
|
return {};
|
|
} catch (e) {
|
|
const error = createErrorObject(e);
|
|
|
|
let errorMessage = getTranslationID("common.message.internalServerError");
|
|
|
|
if (error.code === "E010502") {
|
|
errorMessage = getTranslationID(
|
|
"accountPage.message.updateAccountFailedError"
|
|
);
|
|
}
|
|
|
|
thunkApi.dispatch(
|
|
openSnackbar({
|
|
level: "error",
|
|
message: errorMessage,
|
|
})
|
|
);
|
|
|
|
return thunkApi.rejectWithValue({ error });
|
|
}
|
|
});
|