-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4e4429
commit e51b015
Showing
4 changed files
with
41 additions
and
56 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
49 changes: 32 additions & 17 deletions
49
frontend/webapp/containers/overview/destination/destination.tsx
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 |
---|---|---|
@@ -1,61 +1,76 @@ | ||
"use client"; | ||
import React, { useState } from "react"; | ||
import { KeyvalLoader } from "@/design.system"; | ||
import { OVERVIEW, QUERIES } from "@/utils/constants"; | ||
import { NOTIFICATION, OVERVIEW, QUERIES } from "@/utils/constants"; | ||
import { useQuery } from "react-query"; | ||
import { getDestinations } from "@/services"; | ||
import { OverviewHeader, DestinationsManagedList } from "@/components/overview"; | ||
import { DestinationContainerWrapper } from "./destination.styled"; | ||
import { NewDestinationFlow } from "./new.destination.flow"; | ||
import { UpdateDestinationFlow } from "./update.destination.flow"; | ||
import { useNotification } from "@/hooks"; | ||
|
||
export function DestinationContainer() { | ||
const [selectedDestination, setSelectedDestination] = useState<any>(null); | ||
const [displayNewDestination, setDisplayNewDestination] = | ||
useState<boolean>(false); | ||
|
||
const { show, Notification } = useNotification(); | ||
const { | ||
isLoading: destinationLoading, | ||
data: destinationList, | ||
refetch, | ||
} = useQuery([QUERIES.API_DESTINATIONS], getDestinations); | ||
|
||
function handleAddNewDestinationClick() { | ||
setDisplayNewDestination(true); | ||
function onSuccess(message = OVERVIEW.DESTINATION_UPDATE_SUCCESS) { | ||
refetch(); | ||
setSelectedDestination(null); | ||
setDisplayNewDestination(false); | ||
show({ | ||
type: NOTIFICATION.SUCCESS, | ||
message, | ||
}); | ||
} | ||
|
||
if (destinationLoading) { | ||
return <KeyvalLoader />; | ||
function onError({ response }) { | ||
const message = response?.data?.message; | ||
show({ | ||
type: NOTIFICATION.ERROR, | ||
message, | ||
}); | ||
} | ||
|
||
if (displayNewDestination) { | ||
return ( | ||
<NewDestinationFlow | ||
onBackClick={() => { | ||
refetch(); | ||
setDisplayNewDestination(false); | ||
}} | ||
/> | ||
); | ||
if (destinationLoading) { | ||
return <KeyvalLoader />; | ||
} | ||
|
||
return ( | ||
<DestinationContainerWrapper> | ||
{selectedDestination ? ( | ||
{displayNewDestination ? ( | ||
<NewDestinationFlow | ||
onSuccess={onSuccess} | ||
onError={onError} | ||
onBackClick={() => { | ||
setDisplayNewDestination(false); | ||
}} | ||
/> | ||
) : selectedDestination ? ( | ||
<UpdateDestinationFlow | ||
selectedDestination={selectedDestination} | ||
setSelectedDestination={setSelectedDestination} | ||
onSuccess={onSuccess} | ||
onError={onError} | ||
/> | ||
) : ( | ||
<> | ||
<OverviewHeader title={OVERVIEW.MENU.DESTINATIONS} /> | ||
<DestinationsManagedList | ||
data={destinationList} | ||
onItemClick={setSelectedDestination} | ||
onMenuButtonClick={handleAddNewDestinationClick} | ||
onMenuButtonClick={() => setDisplayNewDestination(true)} | ||
/> | ||
</> | ||
)} | ||
<Notification /> | ||
</DestinationContainerWrapper> | ||
); | ||
} |
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