Skip to content

Commit

Permalink
Merge pull request #403 from panoratech/feat/fix-issues
Browse files Browse the repository at this point in the history
🚑 Fixes on unified objects
  • Loading branch information
naelob authored May 2, 2024
2 parents 7031826 + b50f22d commit 4c9ac6c
Show file tree
Hide file tree
Showing 123 changed files with 3,450 additions and 1,561 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ POSTGRES_USER=my_user
POSTGRES_DB=panora_db
POSTGRES_HOST=postgres


# Each Provider is of form PROVIDER_TICKETING_SOFTWAREMODE_ATTRIBUTE
# ================================================
# Integration Providers
Expand Down
2 changes: 1 addition & 1 deletion apps/client-ts/src/app/(Dashboard)/api-keys/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function Page() {
const {idProject} = useProjectStore();
const {profile} = useProfileStore();

const { data: apiKeys, isLoading, error } = useApiKeys(idProject);
const { data: apiKeys, isLoading, error } = useApiKeys();
const { mutate } = useApiKeyMutation();

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions apps/client-ts/src/app/(Dashboard)/b2c/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { useQueryClient } from '@tanstack/react-query';

const Profile = () => {

const {profile,setProfile} = useProfileStore();
const { idProject, setIdProject } = useProjectStore();
const { profile, setProfile } = useProfileStore();
const { setIdProject } = useProjectStore();
const queryClient = useQueryClient();


Expand Down
6 changes: 3 additions & 3 deletions apps/client-ts/src/app/(Dashboard)/configuration/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ import { Heading } from "@/components/ui/heading";
export default function Page() {
const {idProject} = useProjectStore();

const { data: linkedUsers, isLoading, error } = useLinkedUsers(idProject);
const { data: webhooks, isLoading: isWebhooksLoading, error: isWebhooksError } = useWebhooks(idProject);
const {data: ConnectionStrategies, isLoading: isConnectionStrategiesLoading,error: isConnectionStategiesError} = useConnectionStrategies(idProject)
const { data: linkedUsers, isLoading, error } = useLinkedUsers();
const { data: webhooks, isLoading: isWebhooksLoading, error: isWebhooksError } = useWebhooks();
const {data: ConnectionStrategies, isLoading: isConnectionStrategiesLoading,error: isConnectionStategiesError} = useConnectionStrategies()

const { data: mappings, isLoading: isFieldMappingsLoading, error: isFieldMappingsError } = useFieldMappings();
const [open, setOpen] = useState(false);
Expand Down
2 changes: 0 additions & 2 deletions apps/client-ts/src/app/(Dashboard)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { useEffect, useState } from "react";
import Cookies from 'js-cookie';
import useFetchUserMutation from "@/hooks/mutations/useFetchUserMutation";



const inter = Inter({ subsets: ["latin"] });

export default function Layout({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ const AddAuthCredentialsForm = (prop : propType) => {
</CardHeader>
<CardContent className="grid gap-5">
<div className="grid gap-4">
{/* <div className="grip gap-4"> */}
<FormField
control={form.control}
// disabled={prop.performUpdate}
Expand Down Expand Up @@ -432,21 +431,16 @@ const AddAuthCredentialsForm = (prop : propType) => {
</div>

</CommandItem>
))}
</CommandGroup>
))}
</CommandGroup>
</ScrollArea>
</Command>
</PopoverContent>
</Popover>
<FormMessage />


{/* <FormDescription>
This is the language that will be used in the dashboard.
</FormDescription> */}
</FormItem>
</FormItem>
)}
/>
/>

{/* </div> */}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function FModal({ onClose }: {onClose: () => void}) {
const { data: mappings } = useFieldMappings();
const { mutate: mutateDefineField } = useDefineFieldMutation();
const { mutate: mutateMapField } = useMapFieldMutation();
const { data: linkedUsers } = useLinkedUsers(idProject);
const { data: linkedUsers } = useLinkedUsers();
const { data: sourceCustomFields, error, isLoading } = useProviderProperties(linkedUserId,sourceProvider);

const posthog = usePostHog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Cookies from 'js-cookie';
export default function ConnectionTable() {

const {idProject} = useProjectStore();
const { data: connections, isLoading, error } = useConnections(idProject);
const { data: connections, isLoading, error } = useConnections();
const [isGenerated, setIsGenerated] = useState(false);

const posthog = usePostHog()
Expand Down
2 changes: 1 addition & 1 deletion apps/client-ts/src/components/Events/EventsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function EventsTable() {
} = useEvents({
page: pagination.page,
pageSize: pagination.pageSize,
}, idProject);
});

//TODO
const transformedEvents = events?.map((event: Event) => ({
Expand Down
12 changes: 3 additions & 9 deletions apps/client-ts/src/components/RootLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@ import useProfileStore from '@/state/profileStore';
import useProjectStore from '@/state/projectStore';
import { ThemeToggle } from '@/components/Nav/theme-toggle';
import useProjects from '@/hooks/useProjects';
import useRefreshAccessTokenMutation from '@/hooks/mutations/useRefreshAccessTokenMutation';

export const RootLayout = ({children}:{children:React.ReactNode}) => {
const router = useRouter()
const base = process.env.NEXT_PUBLIC_WEBAPP_DOMAIN;


const {profile} = useProfileStore()
const {data : projectsData} = useProjects();
const { idProject, setIdProject } = useProjectStore();


// const { setIdProject } = useProjectStore();

const {mutate : refreshAccessToken} = useRefreshAccessTokenMutation()

useEffect(() => {
if(projectsData)
Expand All @@ -34,10 +29,9 @@ export const RootLayout = ({children}:{children:React.ReactNode}) => {
{
console.log("Project Id setting : ",projectsData[0]?.id_project)
setIdProject(projectsData[0]?.id_project);

}
}
},[projectsData])
},[idProject, projectsData, refreshAccessToken, setIdProject])

const handlePageChange = (page: string) => {
if (page) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export function DataTableRowActions<TData>({
<DropdownMenuItem>Edit</DropdownMenuItem>
<DropdownMenuItem>Make a copy</DropdownMenuItem>
<DropdownMenuItem>Favorite</DropdownMenuItem>
<DropdownMenuItem>{row.id}</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuSub>
<DropdownMenuSubTrigger>Labels</DropdownMenuSubTrigger>
Expand Down
12 changes: 3 additions & 9 deletions apps/client-ts/src/components/shared/team-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import config from "@/lib/config"
import { Skeleton } from "@/components/ui/skeleton";
import useProfileStore from "@/state/profileStore"
import { projects as Project } from 'api';
import useRefreshAccessTokenMutation from "@/hooks/mutations/useRefreshAccessTokenMutation"


const projectFormSchema = z.object({
Expand Down Expand Up @@ -85,15 +86,7 @@ export default function TeamSwitcher({ className ,projects}: TeamSwitcherProps)
const { profile } = useProfileStore();

const { idProject, setIdProject } = useProjectStore();

// const projects = profile?.projects;

// useEffect(() => {
// if(idProject==="" && projects)
// {
// setIdProject(projects[0]?.id_project)
// }
// },[projects])
const {mutate : refreshAccessToken} = useRefreshAccessTokenMutation()

const handleOpenChange = (open: boolean) => {
setShowNewDialog(prevState => ({ ...prevState, open }));
Expand Down Expand Up @@ -149,6 +142,7 @@ export default function TeamSwitcher({ className ,projects}: TeamSwitcherProps)
key={project.id_project}
onSelect={() => {
setIdProject(project.id_project)
refreshAccessToken(project.id_project)
setOpen(false)
}}
className="text-sm"
Expand Down
15 changes: 2 additions & 13 deletions apps/client-ts/src/hooks/mutations/useLoginMutation.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import config from '@/lib/config';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';
import { toast } from "sonner"
import useProfileStore from '@/state/profileStore';
import { projects as Project } from 'api';
import Cookies from 'js-cookie';

type IUserDto = {
Expand All @@ -18,15 +17,11 @@ interface ILoginInputDto {
password_hash:string
}



interface ILoginOutputDto {
user: IUserDto,
access_token: string

}


const useLoginMutation = () => {

const {setProfile} = useProfileStore()
Expand All @@ -41,15 +36,10 @@ const useLoginMutation = () => {
},
});



if (!response.ok) {
throw new Error("Login Failed!!")
}




return response.json();
};
return useMutation({
Expand All @@ -73,10 +63,9 @@ const useLoginMutation = () => {
})
},
onSuccess: (data : ILoginOutputDto) => {

setProfile(data.user);
Cookies.set('access_token',data.access_token,{expires:1});
console.log("Bearer Token in client Side : ",data.access_token);
//console.log("Bearer Token in client Side : ",data.access_token);

toast.success("User has been generated !", {
description: "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import config from '@/lib/config';
import { useMutation } from '@tanstack/react-query';
import { toast } from "sonner"
import Cookies from 'js-cookie';

interface IRefreshOutputDto {
access_token: string
}

const useRefreshAccessTokenMutation = () => {
const refreshAccessToken = async (projectId: string) => {
const response = await fetch(`${config.API_URL}/auth/refresh-token`, {
method: 'POST',
body: JSON.stringify({
projectId: projectId
}),
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${Cookies.get('access_token')}`,
},
});

if (!response.ok) {
throw new Error("Login Failed!!")
}

return response.json();
};
return useMutation({
mutationFn: refreshAccessToken,
onMutate: () => {
},
onError: (error) => {
toast.error("Refreshing token generation failed !", {
description: error as any,
action: {
label: "Close",
onClick: () => console.log("Close"),
},
})
},
onSuccess: (data : IRefreshOutputDto) => {
Cookies.remove('access_token');
Cookies.set('access_token', data.access_token, {expires:1});
/*toast.success("Refresh has been generated !", {
description: "",
action: {
label: "Close",
onClick: () => console.log("Close"),
},
})*/
},
onSettled: () => {
},
});
};

export default useRefreshAccessTokenMutation;
4 changes: 2 additions & 2 deletions apps/client-ts/src/hooks/useApiKeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { useQuery } from '@tanstack/react-query';
import { api_keys as ApiKey } from 'api';
import Cookies from 'js-cookie';

const useApiKeys = (project_id: string) => {
const useApiKeys = () => {
return useQuery({
queryKey: ['api-keys'],
queryFn: async (): Promise<ApiKey[]> => {
const response = await fetch(`${config.API_URL}/auth/api-keys?project_id=${project_id}`,
const response = await fetch(`${config.API_URL}/auth/api-keys`,
{
method: 'GET',
headers: {
Expand Down
4 changes: 2 additions & 2 deletions apps/client-ts/src/hooks/useConnectionStrategies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { useQuery } from '@tanstack/react-query';
import { connection_strategies as ConnectionStrategies } from 'api';
import Cookies from 'js-cookie';

const useConnectionStrategies = (projectId : string) => {
const useConnectionStrategies = () => {
return useQuery({
queryKey: ['connection-strategies'],
queryFn: async (): Promise<ConnectionStrategies[]> => {
const response = await fetch(`${config.API_URL}/connections-strategies/getConnectionStrategiesForProject?projectId=${projectId}`,
const response = await fetch(`${config.API_URL}/connections-strategies/getConnectionStrategiesForProject`,
{
method: 'GET',
headers: {
Expand Down
4 changes: 2 additions & 2 deletions apps/client-ts/src/hooks/useConnections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { connections as Connection } from 'api';
import Cookies from 'js-cookie';


const useConnections = (project_id: string) => {
const useConnections = () => {
return useQuery({
queryKey: ['connections'],
queryFn: async (): Promise<Connection[]> => {
const response = await fetch(`${config.API_URL}/connections?project_id=${project_id}`,{
const response = await fetch(`${config.API_URL}/connections`,{
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
8 changes: 4 additions & 4 deletions apps/client-ts/src/hooks/useEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { useQuery } from '@tanstack/react-query';
import { events as Event } from 'api';
import Cookies from 'js-cookie';

const fetchEvents = async (params: PaginationParams, project_id: string): Promise<Event[]> => {
const fetchEvents = async (params: PaginationParams): Promise<Event[]> => {
const searchParams = new URLSearchParams({
page: params.page.toString(),
pageSize: params.pageSize.toString(),
});

const response = await fetch(`${config.API_URL}/events?project_id=${project_id}&${searchParams.toString()}`,
const response = await fetch(`${config.API_URL}/events?${searchParams.toString()}`,
{
method: 'GET',
headers: {
Expand All @@ -25,10 +25,10 @@ const fetchEvents = async (params: PaginationParams, project_id: string): Promis
return response.json();
};

const useEvents = (params: PaginationParams, project_id: string) => {
const useEvents = (params: PaginationParams) => {
return useQuery({
queryKey: ['events', { page: params.page, pageSize: params.pageSize }],
queryFn: () => fetchEvents(params, project_id),
queryFn: () => fetchEvents(params),
});
};

Expand Down
4 changes: 2 additions & 2 deletions apps/client-ts/src/hooks/useLinkedUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { useQuery } from '@tanstack/react-query';
import { linked_users as LinkedUser } from 'api';
import Cookies from 'js-cookie';

const useLinkedUsers = (project_id: string) => {
const useLinkedUsers = () => {
return useQuery({
queryKey: ['linked-users'],
queryFn: async (): Promise<LinkedUser[]> => {
const response = await fetch(`${config.API_URL}/linked-users?project_id=${project_id}`,
const response = await fetch(`${config.API_URL}/linked-users`,
{
method: 'GET',
headers: {
Expand Down
4 changes: 2 additions & 2 deletions apps/client-ts/src/hooks/useWebhooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useQuery } from '@tanstack/react-query';
import { webhook_endpoints as Webhook } from 'api';
import Cookies from 'js-cookie';

const useWebhooks = (project_id: string) => {
const useWebhooks = () => {
return useQuery({
queryKey: ['webhooks'],
queryFn: async (): Promise<Webhook[]> => {
console.log("Webhook mutation called")
const response = await fetch(`${config.API_URL}/webhook?project_id=${project_id}`,
const response = await fetch(`${config.API_URL}/webhook`,
{
method: 'GET',
headers: {
Expand Down
Loading

0 comments on commit 4c9ac6c

Please sign in to comment.