-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1463 from Vizzuality/MRXN23-303-inventory-panel-c…
…ost-surface [FE] (feat): Inventory panel: Cost surface [MRXN23-303]
- Loading branch information
Showing
31 changed files
with
1,269 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { useQuery, QueryObserverOptions, useMutation } from 'react-query'; | ||
|
||
import { useSession } from 'next-auth/react'; | ||
|
||
import { CostSurface } from 'types/api/cost-surface'; | ||
import { Project } from 'types/api/project'; | ||
|
||
import { API } from 'services/api'; | ||
import UPLOADS from 'services/uploads'; | ||
|
||
export function useProjectCostSurfaces<T = CostSurface[]>( | ||
pid: Project['id'], | ||
params: { search?: string; sort?: string } = {}, | ||
queryOptions: QueryObserverOptions<CostSurface[], Error, T> = {} | ||
) { | ||
const { data: session } = useSession(); | ||
|
||
const mockData: CostSurface[] = [ | ||
{ | ||
id: 'b7454579-c48e-4e2f-8438-833280cb65d8', | ||
name: 'Brazil 15 k Cost Surface', | ||
isCustom: true, | ||
scenarioUsageCount: 3, | ||
}, | ||
{ | ||
id: 'rfjghhrtersdtbkjshfw', | ||
name: 'Cost Surface Rwanda B', | ||
isCustom: true, | ||
scenarioUsageCount: 0, | ||
}, | ||
{ | ||
id: '23275455HGVVCMSJHDFk', | ||
name: 'Cost Surface Rwanda C', | ||
isCustom: true, | ||
scenarioUsageCount: 0, | ||
}, | ||
]; | ||
|
||
return useQuery({ | ||
queryKey: ['cost-surfaces', pid], | ||
queryFn: async () => | ||
API.request<CostSurface[]>({ | ||
method: 'GET', | ||
// !TODO: change this to the correct endpoint | ||
url: `/projects/${pid}/protected-areas`, | ||
headers: { | ||
Authorization: `Bearer ${session.accessToken}`, | ||
}, | ||
params, | ||
}).then(({ data }) => mockData), | ||
enabled: Boolean(pid), | ||
...queryOptions, | ||
}); | ||
} | ||
|
||
export function useEditProjectCostSurface() { | ||
const { data: session } = useSession(); | ||
|
||
const editCostSurface = ({ | ||
costSurfaceId, | ||
projectId, | ||
body = {}, | ||
}: { | ||
costSurfaceId: CostSurface['id']; | ||
projectId: Project['id']; | ||
body: Record<string, unknown>; | ||
}) => { | ||
// TODO: change this to the correct endpoint | ||
return API.patch<CostSurface>( | ||
`projects/${projectId}/cost-surfaces/${costSurfaceId}`, | ||
{ | ||
...body, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${session.accessToken}`, | ||
}, | ||
} | ||
); | ||
}; | ||
|
||
return useMutation(editCostSurface); | ||
} | ||
|
||
export function useUploadProjectCostSurface() { | ||
const { data: session } = useSession(); | ||
|
||
const uploadProjectCostSurface = ({ id, data }: { id: CostSurface['id']; data: FormData }) => { | ||
return UPLOADS.request({ | ||
method: 'POST', | ||
// TODO: change this to the correct endpoint | ||
url: `/projects/${id}/cost-surface/shapefile`, | ||
data, | ||
headers: { | ||
Authorization: `Bearer ${session.accessToken}`, | ||
'Content-Type': 'multipart/form-data', | ||
}, | ||
}); | ||
}; | ||
|
||
return useMutation(uploadProjectCostSurface); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { AxiosRequestConfig } from 'axios'; | ||
|
||
export interface UseWDPACategoriesProps { | ||
adminAreaId?: string; | ||
customAreaId?: string; | ||
scenarioId: string[] | string; | ||
} | ||
|
||
export interface UseSaveScenarioProtectedAreasProps { | ||
requestConfig?: AxiosRequestConfig; | ||
} | ||
|
||
export interface SaveScenarioProtectedAreasProps { | ||
data: unknown; | ||
id: string[] | string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const UploadCostSurfaceInfoButtonContent = (): JSX.Element => { | ||
return ( | ||
<div className="space-y-2.5 text-xs"> | ||
<h4 className="font-heading">List of supported file formats:</h4> | ||
<p>Zipped: .shp (zipped shapefiles must include .shp, .shx, .dbf, and .prj files)</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default UploadCostSurfaceInfoButtonContent; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
app/layout/project/sidebar/project/inventory-panel/cost-surface/index.tsx
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
app/layout/project/sidebar/project/inventory-panel/cost-surface/info/index.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.