Skip to content

Commit

Permalink
WILD_017b: Refacto - Maj schema BDD
Browse files Browse the repository at this point in the history
  • Loading branch information
JTissot-Dev committed Aug 23, 2024
1 parent 50235ff commit e356f80
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 80 deletions.
1 change: 1 addition & 0 deletions front/src/__tests__/FormUrl.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const mocks = [
name: "Google",
path: "https://www.google.com/",
},
private: false,
},
},
result: {
Expand Down
16 changes: 12 additions & 4 deletions front/src/components/FormUserUrl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<boolean>(false);
Expand All @@ -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<typeof newUrlSchema>) => {
Expand All @@ -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",
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/landing/FormUrl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function FormUrl() {
};

createNewUrl({
variables: { urlData: urlInput },
variables: { urlData: urlInput, isPrivate: false },
onCompleted() {
toast({
variant: "default",
Expand Down
76 changes: 12 additions & 64 deletions front/src/generated/graphql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,14 @@ export type History = {
export type Mutation = {
__typename?: 'Mutation';
addUrl: Url;
addUserUrl: Url;
checkUrl: Url;
createUser: Scalars['String']['output'];
login: Scalars['String']['output'];
};


export type MutationAddUrlArgs = {
urlData: UrlInput;
};


export type MutationAddUserUrlArgs = {
isPrivate: Scalars['Boolean']['input'];
isPrivate?: Scalars['Boolean']['input'];
urlData: UrlInput;
};

Expand Down Expand Up @@ -111,24 +105,26 @@ export type Url = {
lastCheckDate: Scalars['DateTimeISO']['output'];
name: Scalars['String']['output'];
path: Scalars['String']['output'];
userUrl?: Maybe<UserUrl>;
private: Scalars['Boolean']['output'];
user?: Maybe<User>;
};

export type UrlInput = {
name: Scalars['String']['input'];
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<Array<Url>>;
username: Scalars['String']['output'];
};

export type AddUrlMutationVariables = Exact<{
urlData: UrlInput;
isPrivate: Scalars['Boolean']['input'];
}>;


Expand All @@ -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'];
}>;
Expand Down Expand Up @@ -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; }>;
Expand All @@ -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
}
Expand All @@ -228,6 +210,7 @@ export type AddUrlMutationFn = Apollo.MutationFunction<AddUrlMutation, AddUrlMut
* const [addUrlMutation, { data, loading, error }] = useAddUrlMutation({
* variables: {
* urlData: // value for 'urlData'
* isPrivate: // value for 'isPrivate'
* },
* });
*/
Expand Down Expand Up @@ -303,41 +286,6 @@ export function useLoginMutation(baseOptions?: Apollo.MutationHookOptions<LoginM
export type LoginMutationHookResult = ReturnType<typeof useLoginMutation>;
export type LoginMutationResult = Apollo.MutationResult<LoginMutation>;
export type LoginMutationOptions = Apollo.BaseMutationOptions<LoginMutation, LoginMutationVariables>;
export const AddUserUrlDocument = gql`
mutation AddUserUrl($urlData: UrlInput!, $isPrivate: Boolean!) {
addUserUrl(urlData: $urlData, isPrivate: $isPrivate) {
name
path
}
}
`;
export type AddUserUrlMutationFn = Apollo.MutationFunction<AddUserUrlMutation, AddUserUrlMutationVariables>;

/**
* __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<AddUserUrlMutation, AddUserUrlMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<AddUserUrlMutation, AddUserUrlMutationVariables>(AddUserUrlDocument, options);
}
export type AddUserUrlMutationHookResult = ReturnType<typeof useAddUserUrlMutation>;
export type AddUserUrlMutationResult = Apollo.MutationResult<AddUserUrlMutation>;
export type AddUserUrlMutationOptions = Apollo.BaseMutationOptions<AddUserUrlMutation, AddUserUrlMutationVariables>;
export const CheckUrlDocument = gql`
mutation CheckUrl($id: String!) {
checkUrl(id: $id) {
Expand Down
13 changes: 2 additions & 11 deletions front/src/graphql/mutation.ts
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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) {
Expand Down

0 comments on commit e356f80

Please sign in to comment.