Fix save behavior

This commit is contained in:
Félix Malfait
2023-07-08 17:21:11 +02:00
parent 5ad36eb7f3
commit f85abf5d46
3 changed files with 16 additions and 11 deletions
+6 -4
View File
@@ -3033,7 +3033,8 @@ export type CreateCommentMutation = { __typename?: 'Mutation', createOneComment:
export type CreateCommentThreadWithCommentMutationVariables = Exact<{
commentThreadId: Scalars['String'];
commentText: Scalars['String'];
body?: InputMaybe<Scalars['String']>;
title?: InputMaybe<Scalars['String']>;
authorId: Scalars['String'];
createdAt: Scalars['DateTime'];
commentThreadTargetArray: Array<CommentThreadTargetCreateManyCommentThreadInput> | CommentThreadTargetCreateManyCommentThreadInput;
@@ -3576,9 +3577,9 @@ export type CreateCommentMutationHookResult = ReturnType<typeof useCreateComment
export type CreateCommentMutationResult = Apollo.MutationResult<CreateCommentMutation>;
export type CreateCommentMutationOptions = Apollo.BaseMutationOptions<CreateCommentMutation, CreateCommentMutationVariables>;
export const CreateCommentThreadWithCommentDocument = gql`
mutation CreateCommentThreadWithComment($commentThreadId: String!, $commentText: String!, $authorId: String!, $createdAt: DateTime!, $commentThreadTargetArray: [CommentThreadTargetCreateManyCommentThreadInput!]!) {
mutation CreateCommentThreadWithComment($commentThreadId: String!, $body: String, $title: String, $authorId: String!, $createdAt: DateTime!, $commentThreadTargetArray: [CommentThreadTargetCreateManyCommentThreadInput!]!) {
createOneCommentThread(
data: {id: $commentThreadId, createdAt: $createdAt, updatedAt: $createdAt, author: {connect: {id: $authorId}}, body: $commentText, commentThreadTargets: {createMany: {data: $commentThreadTargetArray, skipDuplicates: true}}}
data: {id: $commentThreadId, createdAt: $createdAt, updatedAt: $createdAt, author: {connect: {id: $authorId}}, body: $body, title: $title, commentThreadTargets: {createMany: {data: $commentThreadTargetArray, skipDuplicates: true}}}
) {
id
createdAt
@@ -3620,7 +3621,8 @@ export type CreateCommentThreadWithCommentMutationFn = Apollo.MutationFunction<C
* const [createCommentThreadWithCommentMutation, { data, loading, error }] = useCreateCommentThreadWithCommentMutation({
* variables: {
* commentThreadId: // value for 'commentThreadId'
* commentText: // value for 'commentText'
* body: // value for 'body'
* title: // value for 'title'
* authorId: // value for 'authorId'
* createdAt: // value for 'createdAt'
* commentThreadTargetArray: // value for 'commentThreadTargetArray'
@@ -18,6 +18,7 @@ import { isDefined } from '@/utils/type-guards/isDefined';
import { isNonEmptyString } from '@/utils/type-guards/isNonEmptyString';
import { useCreateCommentThreadWithCommentMutation } from '~/generated/graphql';
import { useOpenCommentThreadRightDrawer } from '../hooks/useOpenCommentThreadRightDrawer';
import { GET_COMMENT_THREAD } from '../services';
import { commentableEntityArrayState } from '../states/commentableEntityArrayState';
@@ -28,8 +29,6 @@ export function RightDrawerCreateCommentThread() {
const [commentableEntityArray] = useRecoilState(commentableEntityArrayState);
const openRightDrawer = useOpenRightDrawer();
const [createCommentThreadWithComment] =
useCreateCommentThreadWithCommentMutation();
@@ -37,6 +36,8 @@ export function RightDrawerCreateCommentThread() {
const identifier = JSON.stringify(commentableEntityArray);
const openCommentThreadRightDrawer = useOpenCommentThreadRightDrawer();
function handleNewCommentThread(title: string, body: string) {
if (!(isNonEmptyString(title) || isNonEmptyString(body))) {
return;
@@ -52,7 +53,8 @@ export function RightDrawerCreateCommentThread() {
createCommentThreadWithComment({
variables: {
authorId: currentUser.id,
commentText: body,
body: body,
title: title,
commentThreadId: v4(),
createdAt: new Date().toISOString(),
commentThreadTargetArray: commentableEntityArray.map(
@@ -70,8 +72,7 @@ export function RightDrawerCreateCommentThread() {
getOperationName(GET_COMMENT_THREAD) ?? '',
],
onCompleted(data) {
// TODO : redirect to drawer comment thread with data.createOneCommentThread.id
openRightDrawer('comments');
openCommentThreadRightDrawer(data.createOneCommentThread.id);
localStorage.setItem('editorTitle' + identifier, '');
localStorage.setItem('editorBody' + identifier, '');
},
@@ -35,7 +35,8 @@ export const CREATE_COMMENT = gql`
export const CREATE_COMMENT_THREAD_WITH_COMMENT = gql`
mutation CreateCommentThreadWithComment(
$commentThreadId: String!
$commentText: String!
$body: String
$title: String
$authorId: String!
$createdAt: DateTime!
$commentThreadTargetArray: [CommentThreadTargetCreateManyCommentThreadInput!]!
@@ -46,7 +47,8 @@ export const CREATE_COMMENT_THREAD_WITH_COMMENT = gql`
createdAt: $createdAt
updatedAt: $createdAt
author: { connect: { id: $authorId } }
body: $commentText
body: $body
title: $title
commentThreadTargets: {
createMany: { data: $commentThreadTargetArray, skipDuplicates: true }
}