diff --git a/front/src/__tests__/FormUrl.test.tsx b/front/src/__tests__/FormUrl.test.tsx index f879680..2aee4f0 100644 --- a/front/src/__tests__/FormUrl.test.tsx +++ b/front/src/__tests__/FormUrl.test.tsx @@ -14,6 +14,7 @@ const mocks = [ name: "Google", path: "https://www.google.com/", }, + private: false, }, }, result: { diff --git a/front/src/components/FormUserUrl.tsx b/front/src/components/FormUserUrl.tsx index 99e8c1d..47b4bcc 100644 --- a/front/src/components/FormUserUrl.tsx +++ b/front/src/components/FormUserUrl.tsx @@ -13,7 +13,7 @@ import { Input } from "@/components/ui/input"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { newUrlSchema } from "@/constants/validator"; -import { useAddUserUrlMutation } from "@/generated/graphql-types"; +import { useAddUrlMutation } from "@/generated/graphql-types"; import { GET_ALL_URLS, GET_RECENT_PRIVATE_URLS } from "@/graphql/queries"; import { useToast } from "@/components/ui/use-toast"; import { @@ -27,6 +27,7 @@ import { import { useState } from "react"; import { Checkbox } from "./ui/checkbox"; import { FormLoginProps } from "@/types/form"; +import { useSearchParams } from "react-router-dom"; export default function FormUserUrl({ setOpenDialog }: FormLoginProps) { const [isPrivate, setIsPrivate] = useState(false); @@ -40,7 +41,8 @@ export default function FormUserUrl({ setOpenDialog }: FormLoginProps) { }, }); - const [createNewUserUrl, { loading }] = useAddUserUrlMutation(); + const [searchParams] = useSearchParams(); + const [createNewUrl, { loading }] = useAddUrlMutation(); const { toast } = useToast(); const onSubmit = (values: z.infer) => { @@ -49,8 +51,8 @@ export default function FormUserUrl({ setOpenDialog }: FormLoginProps) { path: values.path, }; - createNewUserUrl({ - variables: { urlData: urlInput, isPrivate }, + createNewUrl({ + variables: { urlData: urlInput, isPrivate: isPrivate }, onCompleted() { toast({ variant: "default", @@ -68,6 +70,12 @@ export default function FormUserUrl({ setOpenDialog }: FormLoginProps) { refetchQueries: [ { query: GET_ALL_URLS, + variables: { + searchText: searchParams?.get("searchUrl") || "", + sortField: searchParams?.get("sortField") || "", + currentPage: + Number(searchParams?.get("currentPage")) || 1, + }, }, { query: GET_RECENT_PRIVATE_URLS, diff --git a/front/src/components/landing/FormUrl.tsx b/front/src/components/landing/FormUrl.tsx index 2cca0df..b8e91e9 100644 --- a/front/src/components/landing/FormUrl.tsx +++ b/front/src/components/landing/FormUrl.tsx @@ -39,7 +39,7 @@ export default function FormUrl() { }; createNewUrl({ - variables: { urlData: urlInput }, + variables: { urlData: urlInput, isPrivate: false }, onCompleted() { toast({ variant: "default", diff --git a/front/src/generated/graphql-types.ts b/front/src/generated/graphql-types.ts index fbf6baa..dbaefaf 100644 --- a/front/src/generated/graphql-types.ts +++ b/front/src/generated/graphql-types.ts @@ -30,7 +30,6 @@ export type History = { export type Mutation = { __typename?: 'Mutation'; addUrl: Url; - addUserUrl: Url; checkUrl: Url; createUser: Scalars['String']['output']; login: Scalars['String']['output']; @@ -38,12 +37,7 @@ export type Mutation = { export type MutationAddUrlArgs = { - urlData: UrlInput; -}; - - -export type MutationAddUserUrlArgs = { - isPrivate: Scalars['Boolean']['input']; + isPrivate?: Scalars['Boolean']['input']; urlData: UrlInput; }; @@ -111,7 +105,8 @@ export type Url = { lastCheckDate: Scalars['DateTimeISO']['output']; name: Scalars['String']['output']; path: Scalars['String']['output']; - userUrl?: Maybe; + private: Scalars['Boolean']['output']; + user?: Maybe; }; export type UrlInput = { @@ -119,16 +114,17 @@ export type UrlInput = { path: Scalars['String']['input']; }; -export type UserUrl = { - __typename?: 'UserUrl'; - createdAt: Scalars['DateTimeISO']['output']; +export type User = { + __typename?: 'User'; + email: Scalars['String']['output']; id: Scalars['String']['output']; - urlId: Scalars['String']['output']; - userId: Scalars['String']['output']; + urls?: Maybe>; + username: Scalars['String']['output']; }; export type AddUrlMutationVariables = Exact<{ urlData: UrlInput; + isPrivate: Scalars['Boolean']['input']; }>; @@ -151,14 +147,6 @@ export type LoginMutationVariables = Exact<{ export type LoginMutation = { __typename?: 'Mutation', login: string }; -export type AddUserUrlMutationVariables = Exact<{ - urlData: UrlInput; - isPrivate: Scalars['Boolean']['input']; -}>; - - -export type AddUserUrlMutation = { __typename?: 'Mutation', addUserUrl: { __typename?: 'Url', name: string, path: string } }; - export type CheckUrlMutationVariables = Exact<{ id: Scalars['String']['input']; }>; @@ -190,12 +178,6 @@ export type RecentPrivateUrlsQuery = { __typename?: 'Query', recentPrivateUrls: export type LogoutQueryVariables = Exact<{ [key: string]: never; }>; -export type LogoutQuery = { __typename?: 'Query', logout: string }; - - -export type LogoutQueryVariables = Exact<{ [key: string]: never; }>; - - export type LogoutQuery = { __typename?: 'Query', logout: string }; export type MeQueryVariables = Exact<{ [key: string]: never; }>; @@ -205,8 +187,8 @@ export type MeQuery = { __typename?: 'Query', me: string }; export const AddUrlDocument = gql` - mutation AddUrl($urlData: UrlInput!) { - addUrl(urlData: $urlData) { + mutation AddUrl($urlData: UrlInput!, $isPrivate: Boolean!) { + addUrl(urlData: $urlData, isPrivate: $isPrivate) { name path } @@ -228,6 +210,7 @@ export type AddUrlMutationFn = Apollo.MutationFunction; export type LoginMutationResult = Apollo.MutationResult; export type LoginMutationOptions = Apollo.BaseMutationOptions; -export const AddUserUrlDocument = gql` - mutation AddUserUrl($urlData: UrlInput!, $isPrivate: Boolean!) { - addUserUrl(urlData: $urlData, isPrivate: $isPrivate) { - name - path - } -} - `; -export type AddUserUrlMutationFn = Apollo.MutationFunction; - -/** - * __useAddUserUrlMutation__ - * - * To run a mutation, you first call `useAddUserUrlMutation` within a React component and pass it any options that fit your needs. - * When your component renders, `useAddUserUrlMutation` returns a tuple that includes: - * - A mutate function that you can call at any time to execute the mutation - * - An object with fields that represent the current status of the mutation's execution - * - * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; - * - * @example - * const [addUserUrlMutation, { data, loading, error }] = useAddUserUrlMutation({ - * variables: { - * urlData: // value for 'urlData' - * isPrivate: // value for 'isPrivate' - * }, - * }); - */ -export function useAddUserUrlMutation(baseOptions?: Apollo.MutationHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useMutation(AddUserUrlDocument, options); - } -export type AddUserUrlMutationHookResult = ReturnType; -export type AddUserUrlMutationResult = Apollo.MutationResult; -export type AddUserUrlMutationOptions = Apollo.BaseMutationOptions; export const CheckUrlDocument = gql` mutation CheckUrl($id: String!) { checkUrl(id: $id) { diff --git a/front/src/graphql/mutation.ts b/front/src/graphql/mutation.ts index 8d3b0b4..40e2d41 100644 --- a/front/src/graphql/mutation.ts +++ b/front/src/graphql/mutation.ts @@ -1,8 +1,8 @@ import { gql } from "@apollo/client"; export const CREATE_NEW_URL = gql` - mutation AddUrl($urlData: UrlInput!) { - addUrl(urlData: $urlData) { + mutation AddUrl($urlData: UrlInput!, $isPrivate: Boolean!) { + addUrl(urlData: $urlData, isPrivate: $isPrivate) { name path } @@ -21,15 +21,6 @@ export const LOGIN = gql` } `; -export const CREATE_NEW_PRIVATE_URL = gql` - mutation AddUserUrl($urlData: UrlInput!, $isPrivate: Boolean!) { - addUserUrl(urlData: $urlData, isPrivate: $isPrivate) { - name - path - } - } -`; - export const CHECK_URL = gql` mutation CheckUrl($id: String!) { checkUrl(id: $id) {