feat: 添加對話
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import * as React from 'react'
|
||||
import { Button, Dialog, TextField } from "mdui"
|
||||
import useEventListener from "../useEventListener.ts"
|
||||
import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
|
||||
import { checkApiSuccessOrSncakbar, snackbar } from "../snackbar.ts"
|
||||
import Client from "../../api/Client.ts"
|
||||
|
||||
import * as CryptoJS from 'crypto-js'
|
||||
import data from "../../Data.ts"
|
||||
import EventBus from "../../EventBus.ts"
|
||||
|
||||
interface Refs {
|
||||
addContactDialogRef: React.MutableRefObject<Dialog | null>
|
||||
@@ -14,35 +15,27 @@ interface Refs {
|
||||
export default function AddContactDialog({
|
||||
addContactDialogRef,
|
||||
}: Refs) {
|
||||
const loginButtonRef = React.useRef<Button>(null)
|
||||
const registerButtonRef = React.useRef<Button>(null)
|
||||
useEventListener(registerButtonRef, 'click', () => registerDialogRef.current!.open = true)
|
||||
useEventListener(loginButtonRef, 'click', async () => {
|
||||
const account = loginInputAccountRef.current!.value
|
||||
const password = loginInputPasswordRef.current!.value
|
||||
|
||||
const re = await Client.invoke("User.login", {
|
||||
account: account,
|
||||
password: CryptoJS.SHA256(password).toString(CryptoJS.enc.Hex),
|
||||
})
|
||||
|
||||
if (checkApiSuccessOrSncakbar(re, "登錄失敗")) return
|
||||
|
||||
data.access_token = re.data!.access_token as string
|
||||
data.apply()
|
||||
location.reload()
|
||||
})
|
||||
const inputUserAccountRef = React.useRef<TextField>(null)
|
||||
return (
|
||||
<mdui-dialog headline="添加對話" ref={addContactDialogRef}>
|
||||
|
||||
<mdui-text-field label="用戶 ID / 用戶名" ref={loginInputAccountRef as any}></mdui-text-field>
|
||||
<div style={{
|
||||
height: "10px",
|
||||
}}></div>
|
||||
<mdui-text-field label="密碼" type="password" toggle-password ref={loginInputPasswordRef as any}></mdui-text-field>
|
||||
|
||||
現階段只支持添加用戶, 對話敬請期待...
|
||||
<mdui-text-field style={{ marginTop: "10px", }} label="對方的 用戶 ID / 用戶名" ref={inputUserAccountRef as any}></mdui-text-field>
|
||||
<mdui-button slot="action" variant="text" onClick={() => addContactDialogRef.current!.open = false}>取消</mdui-button>
|
||||
<mdui-button slot="action" variant="text">添加</mdui-button>
|
||||
<mdui-button slot="action" variant="text" onClick={async () => {
|
||||
const re = await Client.invoke("User.addContact", {
|
||||
account: inputUserAccountRef.current!.value,
|
||||
token: data.access_token,
|
||||
})
|
||||
|
||||
if (checkApiSuccessOrSncakbar(re, "添加失敗")) return
|
||||
snackbar({
|
||||
message: "添加成功!",
|
||||
placement: "top",
|
||||
})
|
||||
EventBus.emit('ContactsList.updateContacts')
|
||||
|
||||
addContactDialogRef.current!.open = false
|
||||
}}>添加</mdui-button>
|
||||
</mdui-dialog>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user