## 概要 [Task2802: 画面作成(利用規約同意画面)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2802) - 何をどう変更したか、追加したライブラリなど - 利用規約同意画面の実装を行いました - このPull Requestでの対象/対象外 - api.tsおよびstyles - 影響範囲(他の機能にも影響があるか) - ありません ## レビューポイント - 特にレビューしてほしい箇所 - URLの妥当性(動作確認のため別タスクで追加していますが、内容は本タスクで見てほしいです) 違和感ないか確認お願いします。 <Route path="/accept-to-use" element={<AcceptToUsePage />} /> - 各処理のエラーハンドリングについて ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 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/Task2802?csf=1&web=1&e=otF5YX ## 動作確認状況 - ローカルで確認済 ## 補足 - 相談、参考資料などがあれば
159 lines
4.5 KiB
TypeScript
159 lines
4.5 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 { getIdTokenFromLocalStorage } from "common/token";
|
|
import { TIERS } from "components/auth/constants";
|
|
import {
|
|
UsersApi,
|
|
GetAccountInfoMinimalAccessResponse,
|
|
AccountsApi,
|
|
TermsApi,
|
|
GetTermsInfoResponse,
|
|
} from "../../api/api";
|
|
import { Configuration } from "../../api/configuration";
|
|
|
|
export const getAccountInfoMinimalAccessAsync = createAsyncThunk<
|
|
GetAccountInfoMinimalAccessResponse,
|
|
{
|
|
localStorageKeyforIdToken: string;
|
|
},
|
|
{
|
|
// rejectした時の返却値の型
|
|
rejectValue: {
|
|
error: ErrorObject;
|
|
};
|
|
}
|
|
>("accept/getAccountInfoMinimalAccessAsync", async (args, thunkApi) => {
|
|
const { localStorageKeyforIdToken } = args;
|
|
// 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 {
|
|
// IDトークンの取得
|
|
const idToken = getIdTokenFromLocalStorage(localStorageKeyforIdToken);
|
|
|
|
// IDトークンが取得できない場合エラーとする
|
|
if (!idToken) {
|
|
throw new Error("Unable to retrieve the ID token.");
|
|
}
|
|
const res = await accountApi.getAccountInfoMinimalAccess(
|
|
{ idToken },
|
|
{
|
|
headers: { authorization: `Bearer ${accessToken}` },
|
|
}
|
|
);
|
|
return res.data;
|
|
} catch (e) {
|
|
const error = createErrorObject(e);
|
|
thunkApi.dispatch(
|
|
openSnackbar({
|
|
level: "error",
|
|
message: getTranslationID("common.message.internalServerError"),
|
|
})
|
|
);
|
|
return thunkApi.rejectWithValue({ error });
|
|
}
|
|
});
|
|
|
|
export const getTermsInfoAsync = createAsyncThunk<
|
|
GetTermsInfoResponse,
|
|
void,
|
|
{
|
|
// rejectした時の返却値の型
|
|
rejectValue: {
|
|
error: ErrorObject;
|
|
};
|
|
}
|
|
>("accept/getTermsInfoAsync", async (_args, thunkApi) => {
|
|
// apiのConfigurationを取得する
|
|
const { getState } = thunkApi;
|
|
const state = getState() as RootState;
|
|
const { configuration, accessToken } = state.auth;
|
|
const config = new Configuration(configuration);
|
|
const termsApi = new TermsApi(config);
|
|
|
|
try {
|
|
const termsInfo = await termsApi.getTermsInfo({
|
|
headers: { authorization: `Bearer ${accessToken}` },
|
|
});
|
|
|
|
return termsInfo.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 updateAcceptedVersionAsync = createAsyncThunk<
|
|
{
|
|
/* Empty Object */
|
|
},
|
|
{
|
|
tier: number;
|
|
localStorageKeyforIdToken: string;
|
|
updateAccceptVersions: {
|
|
acceptedVerDPA: string;
|
|
acceptedVerEULA: string;
|
|
};
|
|
},
|
|
{
|
|
// rejectした時の返却値の型
|
|
rejectValue: {
|
|
error: ErrorObject;
|
|
};
|
|
}
|
|
>("accept/UpdateAcceptedVersionAsync", async (args, thunkApi) => {
|
|
const { tier, localStorageKeyforIdToken, updateAccceptVersions } = args;
|
|
// apiのConfigurationを取得する
|
|
const { getState } = thunkApi;
|
|
const state = getState() as RootState;
|
|
const { configuration, accessToken } = state.auth;
|
|
const config = new Configuration(configuration);
|
|
const userApi = new UsersApi(config);
|
|
|
|
try {
|
|
// IDトークンの取得
|
|
const idToken = getIdTokenFromLocalStorage(localStorageKeyforIdToken);
|
|
|
|
// IDトークンが取得できない場合エラーとする
|
|
if (!idToken) {
|
|
throw new Error("Unable to retrieve the ID token.");
|
|
}
|
|
await userApi.updateAcceptedVersion(
|
|
{
|
|
idToken,
|
|
acceptedEULAVersion: updateAccceptVersions.acceptedVerEULA,
|
|
acceptedDPAVersion: !(TIERS.TIER5 === tier.toString())
|
|
? updateAccceptVersions.acceptedVerDPA
|
|
: undefined,
|
|
},
|
|
{
|
|
headers: { authorization: `Bearer ${accessToken}` },
|
|
}
|
|
);
|
|
return {};
|
|
} catch (e) {
|
|
const error = createErrorObject(e);
|
|
thunkApi.dispatch(
|
|
openSnackbar({
|
|
level: "error",
|
|
message: getTranslationID("common.message.internalServerError"),
|
|
})
|
|
);
|
|
return thunkApi.rejectWithValue({ error });
|
|
}
|
|
});
|