feat: useGetCredentialsQuery

This commit is contained in:
zerosoul
2022-05-07 22:26:02 +08:00
parent 309c65ab64
commit 0f89bf4ff5
4 changed files with 27 additions and 15 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
// const BASE_URL = `${location.origin}/api`;
const BASE_URL = `https://dev.rustchat.com/api`;
export const CACHE_VERSION = `0.2.10`;
export const CACHE_VERSION = `0.2.12`;
// const BASE_URL = `https://rustchat.net/api`;
export const ContentTypes = {
text: "text/plain",
+6
View File
@@ -95,6 +95,11 @@ export const authApi = createApi({
url: `/token/metamask/nonce?public_address=${address}`,
}),
}),
getCredentials: builder.query({
query: () => ({
url: `/token/credentials`,
}),
}),
logout: builder.query({
query: () => ({ url: `token/logout` }),
}),
@@ -102,6 +107,7 @@ export const authApi = createApi({
});
export const {
useGetCredentialsQuery,
useUpdateDeviceTokenMutation,
useGetOpenidMutation,
useRenewMutation,
+1 -1
View File
@@ -200,7 +200,7 @@ export const normalizeArchiveData = (
) => {
// uid存在,则favorite,否则archive
const prefix = uid
? `${BASE_URL}/favorite/attachment/${uid}/${file_id}/`
? `${BASE_URL}/favorite/attachment/${uid}/${filePath}/`
: `${BASE_URL}/resource/archive/attachment?file_path=${filePath}&attachment_id=`;
return {
transformedContent:
+19 -13
View File
@@ -2,7 +2,10 @@
import { useEffect, useState } from "react";
import styled from "styled-components";
import Input from "../../common/component/styled/Input";
import { useUpdatePasswordMutation } from "../../app/services/auth";
import {
useUpdatePasswordMutation,
useGetCredentialsQuery,
} from "../../app/services/auth";
import StyledModal from "../../common/component/styled/Modal";
import Button from "../../common/component/styled/Button";
const StyledEdit = styled(StyledModal)`
@@ -23,6 +26,7 @@ const StyledEdit = styled(StyledModal)`
import Modal from "../../common/component/Modal";
import toast from "react-hot-toast";
export default function ProfileBasicEditModal({ closeModal }) {
const { data } = useGetCredentialsQuery();
const [input, setInput] = useState({
current: "",
newPassword: "",
@@ -60,7 +64,7 @@ export default function ProfileBasicEditModal({ closeModal }) {
}, [isSuccess]);
const { current, newPassword, confirmPassword } = input;
const disableBtn =
!current ||
(data?.password && !current) ||
!newPassword ||
!confirmPassword ||
newPassword !== confirmPassword ||
@@ -81,17 +85,19 @@ export default function ProfileBasicEditModal({ closeModal }) {
</>
}
>
<div className="input">
<label htmlFor={"current"}>Current Password</label>
<Input
type="password"
id="current"
name="current"
value={current}
data-type="current"
onChange={handleChange}
></Input>
</div>
{data?.password && (
<div className="input">
<label htmlFor={"current"}>Current Password</label>
<Input
type="password"
id="current"
name="current"
value={current}
data-type="current"
onChange={handleChange}
></Input>
</div>
)}
<div className="input">
<label htmlFor={"newPassword"}>New Password</label>
<Input