-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated 0.0.7; changed option page and language
- Loading branch information
Showing
11 changed files
with
273 additions
and
196 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,39 +1,39 @@ | ||
import React from "react"; | ||
import { StyleSheet, Text, TouchableOpacity } from "react-native"; | ||
import { theme } from "../../theme"; | ||
import AlertCircle from "../../assets/svg/alert-circle.svg"; | ||
|
||
export function OptedOutNotification() { | ||
return ( | ||
<TouchableOpacity testID="OptedOutNotification" style={styles.container}> | ||
<AlertCircle style={styles.icon} /> | ||
<Text style={styles.label}>You have opted out of demand response</Text> | ||
<Text style={styles.cta}></Text> | ||
</TouchableOpacity> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flexDirection: "row", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
minHeight: 45, | ||
paddingVertical: theme.padding / 2, | ||
backgroundColor: theme.colors.periwinkle, | ||
borderRadius: 22, | ||
}, | ||
icon: { | ||
marginHorizontal: theme.padding, | ||
marginRight: "auto", | ||
}, | ||
label: { | ||
color: theme.primary, | ||
fontFamily: theme.fonts.title, | ||
paddingHorizontal: theme.padding, | ||
}, | ||
cta: { | ||
marginLeft: "auto", | ||
marginRight: theme.padding * 2, | ||
}, | ||
}); | ||
import React from "react"; | ||
import { StyleSheet, Text, TouchableOpacity } from "react-native"; | ||
import { theme, typography } from "../../theme"; | ||
import AlertCircle from "../../assets/svg/alert-circle.svg"; | ||
|
||
export function OptedOutNotification() { | ||
return ( | ||
<TouchableOpacity testID="OptedOutNotification" style={styles.container}> | ||
<AlertCircle style={styles.icon} /> | ||
<Text style={styles.label}>Standard operation has resumed</Text> | ||
<Text style={styles.cta}></Text> | ||
</TouchableOpacity> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flexDirection: "row", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
minHeight: 45, | ||
paddingVertical: theme.padding / 2, | ||
backgroundColor: theme.colors.periwinkle, | ||
borderRadius: 22, | ||
}, | ||
icon: { | ||
marginHorizontal: theme.padding, | ||
marginRight: "auto", | ||
}, | ||
label: { | ||
color: theme.primary, | ||
fontFamily: theme.fonts.title, | ||
paddingHorizontal: theme.padding, | ||
}, | ||
cta: { | ||
marginLeft: "auto", | ||
marginRight: theme.padding * 2, | ||
}, | ||
}); |
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 |
---|---|---|
@@ -1,94 +1,94 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { StyleSheet, Text, View, SafeAreaView } from "react-native"; | ||
import { useHomeConfigData } from "../hooks/useHomeConfigData"; | ||
import { theme, typography } from "../theme"; | ||
import { useNavigation, useRoute } from "@react-navigation/native"; | ||
import { Button } from "../components/Button"; | ||
import { DemandResponseScreenRouteProps } from "../types"; | ||
import { useDeviceUpdateDerStatus } from "../hooks/api"; | ||
import { ErrorLabel } from "../components/ErrorLabel"; | ||
import { DataBoundary } from "../components/DataBoundary"; | ||
|
||
export function DemandResponseMessageScreen() { | ||
const { data, error, loading, getData } = useHomeConfigData(); | ||
const [optedOut, setOptedOut] = useState<boolean>(false); | ||
const navigation = useNavigation(); | ||
|
||
const route = useRoute<DemandResponseScreenRouteProps>(); | ||
const { deviceId, showOptOutButton } = route.params; | ||
const { update, error: updateError, loading: updateLoading } = useDeviceUpdateDerStatus(deviceId); | ||
|
||
const message = data?.lpc_config.current_event_message.message; | ||
const refresh = getData; | ||
|
||
useEffect(() => { | ||
getData(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!optedOut) { | ||
return; | ||
} | ||
|
||
const optOut = async () => { | ||
const response = await update({ status: "opted_out" }); | ||
|
||
if (response.success) { | ||
navigation.goBack(); | ||
} else { | ||
setOptedOut(false); | ||
} | ||
}; | ||
|
||
optOut(); | ||
}, [optedOut]); | ||
|
||
return ( | ||
<DataBoundary | ||
loading={loading} | ||
error={error} | ||
data={data} | ||
onPressRetry={refresh} | ||
errorMessage="We encountered an error while retrieving Demand Response data." | ||
> | ||
<SafeAreaView style={styles.container}> | ||
{data && ( | ||
<View style={styles.content}> | ||
<View style={styles.textBlock}> | ||
<Text style={typography.headline2}>{message}</Text> | ||
</View> | ||
{updateError && <ErrorLabel message="Error Opting Out" />} | ||
<View style={{ marginVertical: theme.padding }}> | ||
{showOptOutButton && ( | ||
<Button | ||
label="Opt Out of Power Event" | ||
accessibilityLabel="Opt Out of Power Event" | ||
onPress={() => setOptedOut(true)} | ||
style={{ backgroundColor: theme.colors.red }} | ||
activity={updateLoading} | ||
/> | ||
)} | ||
</View> | ||
<Button onPress={navigation.goBack} label="Close" /> | ||
</View> | ||
)} | ||
</SafeAreaView> | ||
</DataBoundary> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: theme.background, | ||
alignItems: "center", | ||
}, | ||
content: { | ||
height: "100%", | ||
padding: theme.padding, | ||
}, | ||
textBlock: { | ||
flex: 1, | ||
paddingTop: theme.padding, | ||
}, | ||
}); | ||
import React, { useEffect, useState } from "react"; | ||
import { StyleSheet, Text, View, SafeAreaView } from "react-native"; | ||
import { useHomeConfigData } from "../hooks/useHomeConfigData"; | ||
import { theme, typography } from "../theme"; | ||
import { useNavigation, useRoute } from "@react-navigation/native"; | ||
import { Button } from "../components/Button"; | ||
import { DemandResponseScreenRouteProps } from "../types"; | ||
import { useDeviceUpdateDerStatus } from "../hooks/api"; | ||
import { ErrorLabel } from "../components/ErrorLabel"; | ||
import { DataBoundary } from "../components/DataBoundary"; | ||
|
||
export function DemandResponseMessageScreen() { | ||
const { data, error, loading, getData } = useHomeConfigData(); | ||
const [optedOut, setOptedOut] = useState<boolean>(false); | ||
const navigation = useNavigation(); | ||
|
||
const route = useRoute<DemandResponseScreenRouteProps>(); | ||
const { deviceId, showOptOutButton } = route.params; | ||
const { update, error: updateError, loading: updateLoading } = useDeviceUpdateDerStatus(deviceId); | ||
|
||
const message = data?.lpc_config.current_event_message.message; | ||
const refresh = getData; | ||
|
||
useEffect(() => { | ||
getData(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!optedOut) { | ||
return; | ||
} | ||
|
||
const optOut = async () => { | ||
const response = await update({ status: "opted_out" }); | ||
|
||
if (response.success) { | ||
navigation.goBack(); | ||
} else { | ||
setOptedOut(false); | ||
} | ||
}; | ||
|
||
optOut(); | ||
}, [optedOut]); | ||
|
||
return ( | ||
<DataBoundary | ||
loading={loading} | ||
error={error} | ||
data={data} | ||
onPressRetry={refresh} | ||
errorMessage="We encountered an error while retrieving Demand Response data." | ||
> | ||
<SafeAreaView style={styles.container}> | ||
{data && ( | ||
<View style={styles.content}> | ||
<View style={styles.textBlock}> | ||
<Text style={typography.headline2}>{message}</Text> | ||
</View> | ||
{updateError && <ErrorLabel message="Error Opting Out" />} | ||
<View style={{ marginVertical: theme.padding }}> | ||
{showOptOutButton && ( | ||
<Button | ||
label="Resume Normal Settings" | ||
accessibilityLabel="Resume Normal Settings" | ||
onPress={() => setOptedOut(true)} | ||
style={{ backgroundColor: theme.colors.red }} | ||
activity={updateLoading} | ||
/> | ||
)} | ||
</View> | ||
<Button onPress={navigation.goBack} label="Close" /> | ||
</View> | ||
)} | ||
</SafeAreaView> | ||
</DataBoundary> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: theme.background, | ||
alignItems: "center", | ||
}, | ||
content: { | ||
height: "100%", | ||
padding: theme.padding, | ||
}, | ||
textBlock: { | ||
flex: 1, | ||
paddingTop: theme.padding, | ||
}, | ||
}); |
Oops, something went wrong.