feat: initial update email support
This commit is contained in:
parent
9fed7a2643
commit
ddf9a0ddea
|
@ -1,11 +1,53 @@
|
||||||
import type { DataProvider } from "@refinedev/core";
|
import type {DataProvider, UpdateParams, UpdateResponse, HttpError} from "@refinedev/core";
|
||||||
import {SdkProvider} from "~/data/sdk-provider.js";
|
import {SdkProvider} from "~/data/sdk-provider.js";
|
||||||
|
|
||||||
export const accountProvider: SdkProvider = {
|
type AccountParams = {
|
||||||
getList: () => { throw Error("Not Implemented") },
|
email?: string;
|
||||||
getOne: () => { throw Error("Not Implemented") },
|
password?: string;
|
||||||
update: () => { throw Error("Not Implemented") },
|
}
|
||||||
create: () => { throw Error("Not Implemented") },
|
|
||||||
deleteOne: () => { throw Error("Not Implemented") },
|
type AccountData = AccountParams;
|
||||||
getApiUrl: () => "",
|
|
||||||
|
export const accountProvider: SdkProvider = {
|
||||||
|
getList: () => {
|
||||||
|
throw Error("Not Implemented")
|
||||||
|
},
|
||||||
|
getOne: () => {
|
||||||
|
throw Error("Not Implemented")
|
||||||
|
},
|
||||||
|
// @ts-ignore
|
||||||
|
async update<TVariables extends AccountParams = AccountParams>(
|
||||||
|
params: UpdateParams<AccountParams>,
|
||||||
|
): Promise<UpdateResponse<AccountData>> {
|
||||||
|
if (params.variables.email && params.variables.password) {
|
||||||
|
const ret = accountProvider.sdk?.account().updateEmail(params.variables.email, params.variables.password);
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
if (ret instanceof Error) {
|
||||||
|
return Promise.reject(ret)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data:
|
||||||
|
{
|
||||||
|
email: params.variables.email,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return an empty response if params.variables is undefined
|
||||||
|
return {
|
||||||
|
data: {} as AccountParams,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
create: () => {
|
||||||
|
throw Error("Not Implemented")
|
||||||
|
},
|
||||||
|
deleteOne: () => {
|
||||||
|
throw Error("Not Implemented")
|
||||||
|
},
|
||||||
|
getApiUrl: () => "",
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,8 +222,8 @@ const ChangeEmailForm = ({
|
||||||
const data = Object.fromEntries(new FormData(e.currentTarget).entries());
|
const data = Object.fromEntries(new FormData(e.currentTarget).entries());
|
||||||
console.log(identity);
|
console.log(identity);
|
||||||
updateEmail({
|
updateEmail({
|
||||||
resource: "users",
|
resource: "account",
|
||||||
id: identity?.id || "",
|
id: "",
|
||||||
values: {
|
values: {
|
||||||
email: data.email.toString(),
|
email: data.email.toString(),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue