Use REST API for confirm endpoint
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -4,12 +4,9 @@ import { Helmet } from "react-helmet-async";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { Link } from "react-router";
|
||||
import { useMutation } from "react-relay";
|
||||
import { graphql } from "relay-runtime";
|
||||
import { PayloadError } from "relay-runtime";
|
||||
import { ConfirmInvitationPageMutation } from "./__generated__/ConfirmInvitationPageMutation.graphql";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { buildEndpoint } from "@/utils";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -19,14 +16,6 @@ import {
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
|
||||
const ConfirmInvitationMutation = graphql`
|
||||
mutation ConfirmInvitationPageMutation($input: ConfirmInvitationInput!) {
|
||||
confirmInvitation(input: $input) {
|
||||
success
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default function ConfirmInvitationPage() {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isConfirmed, setIsConfirmed] = useState(false);
|
||||
@@ -37,9 +26,6 @@ export default function ConfirmInvitationPage() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const { toast } = useToast();
|
||||
const [commitMutation] = useMutation<ConfirmInvitationPageMutation>(
|
||||
ConfirmInvitationMutation
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
// Extract token from URL and prefill the form
|
||||
@@ -81,34 +67,30 @@ export default function ConfirmInvitationPage() {
|
||||
}
|
||||
|
||||
try {
|
||||
commitMutation({
|
||||
variables: {
|
||||
input: {
|
||||
const response = await fetch(
|
||||
buildEndpoint("/api/console/v1/auth/invitation"),
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
token: token.trim(),
|
||||
password: password,
|
||||
},
|
||||
},
|
||||
onCompleted: (response, errors: PayloadError[] | null) => {
|
||||
if (errors) {
|
||||
throw new Error(
|
||||
errors[0]?.message || "Failed to confirm invitation"
|
||||
);
|
||||
}
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
setIsConfirmed(true);
|
||||
toast({
|
||||
title: "Success",
|
||||
description: "Your invitation has been confirmed successfully",
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
setIsLoading(false);
|
||||
},
|
||||
onError: (err) => {
|
||||
setError(
|
||||
err.message || "Failed to confirm invitation. Please try again."
|
||||
);
|
||||
setIsLoading(false);
|
||||
},
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || "Failed to confirm invitation");
|
||||
}
|
||||
|
||||
setIsConfirmed(true);
|
||||
toast({
|
||||
title: "Success",
|
||||
description: "Your invitation has been confirmed successfully",
|
||||
});
|
||||
} catch (error) {
|
||||
setError(
|
||||
@@ -116,6 +98,7 @@ export default function ConfirmInvitationPage() {
|
||||
? error.message
|
||||
: "Failed to confirm invitation. Please try again."
|
||||
);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/**
|
||||
* @generated SignedSource<<8326ebf0af891dd062245db55f40abba>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type ConfirmInvitationInput = {
|
||||
password: string;
|
||||
token: string;
|
||||
};
|
||||
export type ConfirmInvitationPageMutation$variables = {
|
||||
input: ConfirmInvitationInput;
|
||||
};
|
||||
export type ConfirmInvitationPageMutation$data = {
|
||||
readonly confirmInvitation: {
|
||||
readonly success: boolean;
|
||||
};
|
||||
};
|
||||
export type ConfirmInvitationPageMutation = {
|
||||
response: ConfirmInvitationPageMutation$data;
|
||||
variables: ConfirmInvitationPageMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
"concreteType": "ConfirmInvitationPayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "confirmInvitation",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "success",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
];
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "ConfirmInvitationPageMutation",
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Operation",
|
||||
"name": "ConfirmInvitationPageMutation",
|
||||
"selections": (v1/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "b274132385a2cb59047b47de69712aa8",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "ConfirmInvitationPageMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation ConfirmInvitationPageMutation(\n $input: ConfirmInvitationInput!\n) {\n confirmInvitation(input: $input) {\n success\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "f1f013a448277ebffb14e954b2c1797c";
|
||||
|
||||
export default node;
|
||||
Reference in New Issue
Block a user