diff --git a/src/client/index.ts b/src/client/index.ts index b774b75..7df2728 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -854,7 +854,31 @@ export class Api< type: ContentType.Json, format: 'json', ...params - }) + }), + + /** + * @description a user me. + * + * @tags User + * @name v1UserUpdate + * @summary update user information + * @request PUT:/api/v1/users/me + * @secure + */ + v1UserUpdate: ( + id: string, + updateUser: SchemaUpdateUser, + params: RequestParams = {} + ) => + this.request({ + path: `/api/v1/users/${id}`, + method: 'PUT', + body: updateUser, + secure: true, + type: ContentType.Json, + format: 'json', + ...params + }), } misc = { /** diff --git a/src/pages/EditProfile/index.tsx b/src/pages/EditProfile/index.tsx index 3e80974..3220cdf 100644 --- a/src/pages/EditProfile/index.tsx +++ b/src/pages/EditProfile/index.tsx @@ -1,25 +1,63 @@ import { useRequest } from 'ahooks' -import type { SchemaUserDetail } from 'client' +import type { SchemaUpdateUser, SchemaUserDetail } from 'client' import PageContainer from 'components/PageContainer' import type React from 'react' import { useState } from 'react' import { Form, Button, Col, Row, Accordion } from 'react-bootstrap' import Backend from 'utils/service' -const UserProfileForm: React.FC = () => { - // TODO: submit update user - const { run: submit } = useRequest(async () => null) - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault() - submit() - } - const [user, setUser] = useState() - const { loading } = useRequest(async () => Backend.user.v1UsersMeList(), { - onSuccess: res => { - setUser(res.data) +const UserProfileForm: React.FC<{ + key: string + updateUser: SchemaUpdateUser + refresh: () => void +}>= ({ key, updateUser, refresh }) => { + const [show, setShow] = useState(false) + const handleClose = () => setShow(false) + const handleShow = () => setShow(true) + const [address, setAddress] = useState(updateUser.address) + const [address2,setAddress2] = useState(updateUser.address2) + const [card_address,setCard_address] = useState(updateUser.card_address) + const [card_address2,setCard_address2] = useState(updateUser.card_address2) + const [card_city, setCard_city] = useState(updateUser.card_city) + const [card_expiration, setCard_expiration] = useState(updateUser.card_expiration) + const [card_number, setCard_number] = useState(updateUser.card_number) + const [card_state, setCard_state] = useState(updateUser.card_state) + const [card_type, setCard_type] = useState(updateUser.card_type) + const [card_zip, setCard_zip] = useState(updateUser.card_zip) + const [city, setCity] = useState(updateUser.city) + const [name, setName] = useState(updateUser.name) + const [need_promotion, setNeed_promotion] = useState(updateUser.need_promotion) + const { run: submit } = useRequest( + async () => { + Backend.user.v1UserUpdate(updateUser.username, { + address, + address2, + card_address, + card_address2, + card_city, + card_expiration, + card_number, + card_state, + card_type, + card_zip, + city, + name, + need_promotion, + password: '', + phone: '', + state: '', + username: '', + zip: '' + }) + }, + { + manual: true, + onSuccess: () => { + refresh() + handleClose() + } } - }) - + ) return ( <>
diff --git a/src/pages/MovieManage/index.tsx b/src/pages/MovieManage/index.tsx index 844ea27..ae14833 100644 --- a/src/pages/MovieManage/index.tsx +++ b/src/pages/MovieManage/index.tsx @@ -399,7 +399,7 @@ const Index: React.FC = () => { create() }} > - Create + Create!!