-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
6 changed files
with
179 additions
and
103 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...ky/starsky/clientapp/src/components/organisms/modal-geo/internal/update-button-active.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { IGeoLocationModel } from "../../../../interfaces/IGeoLocationModel"; | ||
import localization from "../../../../localization/localization.json"; | ||
import { Language } from "../../../../shared/language"; | ||
import { ILatLong } from "../modal-geo"; | ||
import { UpdateGeoLocation } from "./update-geo-location"; | ||
|
||
interface IUpdateButtonActiveProps { | ||
parentDirectory: string; | ||
handleExit: (result: IGeoLocationModel | null) => void; | ||
selectedSubPath: string; | ||
latitude?: number; | ||
longitude?: number; | ||
location: ILatLong; | ||
language: Language; | ||
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>; | ||
setError: React.Dispatch<React.SetStateAction<boolean>>; | ||
propsCollections: boolean | undefined; | ||
} | ||
|
||
export const UpdateButtonActive: React.FunctionComponent<IUpdateButtonActiveProps> = ({ | ||
handleExit, | ||
parentDirectory, | ||
latitude, | ||
longitude, | ||
language, | ||
...props | ||
}) => { | ||
return ( | ||
<button | ||
onClick={async () => { | ||
const model = await UpdateGeoLocation( | ||
parentDirectory, | ||
props.selectedSubPath, | ||
props.location, | ||
props.setError, | ||
props.setIsLoading, | ||
props.propsCollections | ||
); | ||
if (model) { | ||
handleExit(model); | ||
} | ||
}} | ||
data-test="update-geo-location" | ||
className="btn btn--default" | ||
> | ||
{!latitude && !longitude | ||
? language.key(localization.MessageAddLocation) | ||
: language.key(localization.MessageUpdateLocation)} | ||
</button> | ||
); | ||
}; |
23 changes: 23 additions & 0 deletions
23
.../starsky/clientapp/src/components/organisms/modal-geo/internal/update-button-disabled.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import localization from "../../../../localization/localization.json"; | ||
import { Language } from "../../../../shared/language"; | ||
|
||
interface IUpdateButtonActiveProps { | ||
latitude?: number; | ||
longitude?: number; | ||
language: Language; | ||
} | ||
|
||
export const UpdateButtonDisabled: React.FunctionComponent<IUpdateButtonActiveProps> = ({ | ||
latitude, | ||
longitude, | ||
language | ||
}) => { | ||
return ( | ||
<button className="btn btn--default" disabled={true}> | ||
{/* disabled */} | ||
{!latitude && !longitude | ||
? language.key(localization.MessageAddLocation) | ||
: language.key(localization.MessageUpdateLocation)} | ||
</button> | ||
); | ||
}; |
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
105 changes: 45 additions & 60 deletions
105
starsky/starsky/clientapp/src/components/organisms/modal-geo/internal/update-button.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,68 +1,53 @@ | ||
import React from "react"; | ||
import useGlobalSettings from "../../../../hooks/use-global-settings"; | ||
import { IGeoLocationModel } from "../../../../interfaces/IGeoLocationModel"; | ||
import localization from "../../../../localization/localization.json"; | ||
import { Language } from "../../../../shared/language"; | ||
import { ILatLong } from "../modal-geo"; | ||
import { UpdateGeoLocation } from "./update-geo-location"; | ||
import { UpdateButtonActive } from "./update-button-active"; | ||
import { UpdateButtonDisabled } from "./update-button-disabled"; | ||
|
||
export class UpdateButton { | ||
interface UpdateButtonProps { | ||
parentDirectory: string; | ||
selectedSubPath: string; | ||
location: ILatLong; | ||
setError: any; | ||
setIsLoading: any; | ||
propsCollections: boolean | undefined; | ||
|
||
constructor( | ||
parentDirectory: string, | ||
selectedSubPath: string, | ||
location: ILatLong, | ||
setError: React.Dispatch<React.SetStateAction<boolean>>, | ||
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>, | ||
propsCollections?: boolean | undefined | ||
) { | ||
this.parentDirectory = parentDirectory; | ||
this.selectedSubPath = selectedSubPath; | ||
this.location = location; | ||
this.setError = setError; | ||
this.setIsLoading = setIsLoading; | ||
this.propsCollections = propsCollections; | ||
} | ||
updateButton( | ||
isLocationUpdated: boolean, | ||
handleExit: (result: IGeoLocationModel | null) => void, | ||
latitude: number | undefined, | ||
longitude: number | undefined, | ||
language: Language | ||
): React.JSX.Element { | ||
return isLocationUpdated ? ( | ||
<button | ||
onClick={async () => { | ||
const model = await UpdateGeoLocation( | ||
this.parentDirectory, | ||
this.selectedSubPath, | ||
this.location, | ||
this.setError, | ||
this.setIsLoading, | ||
this.propsCollections | ||
); | ||
if (model) { | ||
handleExit(model); | ||
} | ||
}} | ||
data-test="update-geo-location" | ||
className="btn btn--default" | ||
> | ||
{!latitude && !longitude | ||
? language.key(localization.MessageAddLocation) | ||
: language.key(localization.MessageUpdateLocation)} | ||
</button> | ||
) : ( | ||
<button className="btn btn--default" disabled={true}> | ||
{/* disabled */} | ||
{!latitude && !longitude | ||
? language.key(localization.MessageAddLocation) | ||
: language.key(localization.MessageUpdateLocation)} | ||
</button> | ||
); | ||
} | ||
setError: React.Dispatch<React.SetStateAction<boolean>>; | ||
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>; | ||
propsCollections?: boolean; | ||
isLocationUpdated: boolean; | ||
handleExit: (result: IGeoLocationModel | null) => void; | ||
} | ||
|
||
export const UpdateButton: React.FC<UpdateButtonProps> = ({ | ||
parentDirectory, | ||
selectedSubPath, | ||
location, | ||
setError, | ||
setIsLoading, | ||
propsCollections, | ||
isLocationUpdated, | ||
handleExit | ||
}) => { | ||
const settings = useGlobalSettings(); | ||
const language = new Language(settings.language); | ||
|
||
return isLocationUpdated ? ( | ||
<UpdateButtonActive | ||
parentDirectory={parentDirectory} | ||
selectedSubPath={selectedSubPath} | ||
location={location} | ||
handleExit={handleExit} | ||
latitude={location.latitude} | ||
longitude={location.longitude} | ||
language={language} | ||
setIsLoading={setIsLoading} | ||
setError={setError} | ||
propsCollections={propsCollections} | ||
/> | ||
) : ( | ||
<UpdateButtonDisabled | ||
language={language} | ||
latitude={location.latitude} | ||
longitude={location.longitude} | ||
/> | ||
); | ||
}; |
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