Skip to content

Commit 2cf2dea

Browse files
author
Guillermo Machado
committed
feat: add webview to open terms and conditions
1 parent c323aba commit 2cf2dea

File tree

10 files changed

+118
-38
lines changed

10 files changed

+118
-38
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ API_URL=
22
VAR_NUMBER=
33
VAR_BOOL=
44
SECRET_KEY=
5+
WEBSITE_URL=
6+
TERMS_AND_CONDITIONS_URL=

env.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const LOCAL_BUILD_SCRIPT_PATTERNS = [
3030
'expo export',
3131
];
3232
const isLocalBuild = LOCAL_BUILD_SCRIPT_PATTERNS.some((pattern) =>
33-
process.env.npm_lifecycle_script?.includes(pattern)
33+
process.env.npm_lifecycle_script?.includes(pattern),
3434
);
3535

3636
const EXPO_RUN_COMMANDS = ['expo start', 'expo run'];
@@ -44,13 +44,13 @@ const ENVIRONMENT_DEPENDANT_SCRIPTS = [
4444
];
4545

4646
const scriptIsEnvironmentDependant = ENVIRONMENT_DEPENDANT_SCRIPTS.some(
47-
(script) => process.env.npm_lifecycle_script?.includes(script)
47+
(script) => process.env.npm_lifecycle_script?.includes(script),
4848
);
4949

5050
// Check if the environment file has to be validated for the current running script and build method
5151
const isBuilding = isEASBuild || isLocalBuild;
5252
const isRunning = EXPO_RUN_COMMANDS.some((script) =>
53-
process.env.npm_lifecycle_script?.includes(script)
53+
process.env.npm_lifecycle_script?.includes(script),
5454
);
5555
const shouldValidateEnv =
5656
(isBuilding && scriptIsEnvironmentDependant) || isRunning;
@@ -138,6 +138,8 @@ const clientEnvSchema = z.object({
138138
API_URL: z.string(),
139139
VAR_NUMBER: z.number(),
140140
VAR_BOOL: z.boolean(),
141+
TERMS_AND_CONDITIONS_URL: z.string(),
142+
WEBSITE_URL: z.string(),
141143
});
142144

143145
const buildTimeEnvSchema = z.object({
@@ -162,6 +164,8 @@ const _clientEnv = {
162164
API_URL: parseString(process.env.API_URL),
163165
VAR_NUMBER: parseNumber(process.env.VAR_NUMBER),
164166
VAR_BOOL: parseBoolean(process.env.VAR_BOOL),
167+
WEBSITE_URL: parseString(process.env.WEBSITE_URL),
168+
TERMS_AND_CONDITIONS_URL: parseString(process.env.TERMS_AND_CONDITIONS_URL),
165169
};
166170

167171
/**
@@ -212,19 +216,19 @@ if (shouldValidateEnv) {
212216

213217
if (isLocalBuild) {
214218
messages.push(
215-
`\n💡 Tip: If you recently updated the \x1b[1m\x1b[4m\x1b[31m${envFile}\x1b[0m file and the error still persists, try restarting the server with the -cc flag to clear the cache.`
219+
`\n💡 Tip: If you recently updated the \x1b[1m\x1b[4m\x1b[31m${envFile}\x1b[0m file and the error still persists, try restarting the server with the -cc flag to clear the cache.`,
216220
);
217221
}
218222

219223
if (isEASBuild) {
220224
messages.push(
221-
`\n☁️ For \x1b[1m\x1b[32mEAS Build\x1b[0m deployments, ensure the secret\x1b[1m\x1b[4m\x1b[31m${environmentFiles[APP_ENV]} \x1b[0m is defined in Project Secrets and has the proper environment file attached.`
225+
`\n☁️ For \x1b[1m\x1b[32mEAS Build\x1b[0m deployments, ensure the secret\x1b[1m\x1b[4m\x1b[31m${environmentFiles[APP_ENV]} \x1b[0m is defined in Project Secrets and has the proper environment file attached.`,
222226
);
223227
}
224228

225229
console.error(...messages);
226230
throw new Error(
227-
'Invalid environment variables, Check terminal for more details '
231+
'Invalid environment variables, Check terminal for more details ',
228232
);
229233
}
230234

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"react-native-screens": "~3.31.1",
104104
"react-native-svg": "~15.2.0",
105105
"react-native-web": "~0.19.12",
106+
"react-native-webview": "13.8.6",
106107
"react-query-kit": "^3.3.0",
107108
"tailwind-variants": "^0.2.1",
108109
"zod": "^3.23.8",

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/(app)/settings.tsx

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { Env } from '@env';
2+
import { router } from 'expo-router';
23
import { useColorScheme } from 'nativewind';
4+
import React from 'react';
35

46
import { Item } from '@/components/settings/item';
57
import { ItemsContainer } from '@/components/settings/items-container';
68
import { LanguageItem } from '@/components/settings/language-item';
79
import { ThemeItem } from '@/components/settings/theme-item';
810
import { translate, useAuth } from '@/core';
911
import { colors, FocusAwareStatusBar, ScrollView, Text, View } from '@/ui';
10-
import { Github, Rate, Share, Support, Website } from '@/ui/icons';
12+
import { Website } from '@/ui/icons';
1113

1214
export default function Settings() {
1315
const signOut = useAuth.use.signOut();
@@ -29,44 +31,32 @@ export default function Settings() {
2931
<ThemeItem />
3032
</ItemsContainer>
3133

32-
<ItemsContainer title="settings.about">
33-
<Item text="settings.app_name" value={Env.NAME} />
34-
<Item text="settings.version" value={Env.VERSION} />
35-
</ItemsContainer>
36-
37-
<ItemsContainer title="settings.support_us">
38-
<Item
39-
text="settings.share"
40-
icon={<Share color={iconColor} />}
41-
onPress={() => {}}
42-
/>
43-
<Item
44-
text="settings.rate"
45-
icon={<Rate color={iconColor} />}
46-
onPress={() => {}}
47-
/>
48-
<Item
49-
text="settings.support"
50-
icon={<Support color={iconColor} />}
51-
onPress={() => {}}
52-
/>
53-
</ItemsContainer>
54-
5534
<ItemsContainer title="settings.links">
56-
<Item text="settings.privacy" onPress={() => {}} />
57-
<Item text="settings.terms" onPress={() => {}} />
5835
<Item
59-
text="settings.github"
60-
icon={<Github color={iconColor} />}
61-
onPress={() => {}}
36+
text="settings.terms"
37+
onPress={() => {
38+
const url = encodeURIComponent(Env.TERMS_AND_CONDITIONS_URL);
39+
const title = encodeURIComponent('Terms & Conditions');
40+
41+
router.push(`/www?url=${url}&title=${title}`);
42+
}}
6243
/>
6344
<Item
6445
text="settings.website"
6546
icon={<Website color={iconColor} />}
66-
onPress={() => {}}
47+
onPress={() => {
48+
const url = encodeURIComponent(Env.WEBSITE_URL);
49+
const title = encodeURIComponent('Website');
50+
51+
router.push(`/www?url=${url}&title=${title}`);
52+
}}
6753
/>
6854
</ItemsContainer>
6955

56+
<ItemsContainer title="settings.about">
57+
<Item text="settings.version" value={Env.VERSION} />
58+
</ItemsContainer>
59+
7060
<View className="my-8">
7161
<ItemsContainer>
7262
<Item text="settings.logout" onPress={signOut} />

src/app/(app)/style.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import React from 'react';
2+
13
import { Buttons } from '@/components/buttons';
24
import { Colors } from '@/components/colors';
35
import { Inputs } from '@/components/inputs';

src/app/_layout.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ export default function RootLayout() {
3535
<Stack.Screen name="onboarding" options={{ headerShown: false }} />
3636
<Stack.Screen name="forgot-password" />
3737
<Stack.Screen name="sign-in" options={{ headerShown: false }} />
38+
<Stack.Screen
39+
name="www"
40+
options={{
41+
presentation: 'modal',
42+
title: '', // Title will be overridden by the screen itself
43+
}}
44+
/>
3845
</Stack>
3946
</Providers>
4047
);

src/app/onboarding.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function Onboarding() {
3535
</View>
3636
<SafeAreaView className="mt-6">
3737
<Button
38-
label="Let's Get Started "
38+
label="Let's Get Started"
3939
onPress={() => {
4040
setIsFirstTime(false);
4141
router.replace('/sign-in');

src/app/www.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { useLocalSearchParams, useNavigation, useRouter } from 'expo-router';
2+
import React, { useEffect } from 'react';
3+
import { StyleSheet, View } from 'react-native';
4+
import { WebView } from 'react-native-webview';
5+
6+
import { Text } from '@/ui';
7+
8+
export default function WWW() {
9+
const router = useRouter();
10+
const { url, title } = useLocalSearchParams();
11+
const navigation = useNavigation();
12+
13+
useEffect(() => {
14+
if (title) {
15+
navigation.setOptions({
16+
title,
17+
});
18+
}
19+
}, [navigation, title]);
20+
21+
if (!url || typeof url !== 'string') {
22+
return (
23+
<View style={styles.errorContainer}>
24+
<Text style={styles.errorText}>Invalid URL</Text>
25+
</View>
26+
);
27+
}
28+
29+
return (
30+
<View style={styles.container}>
31+
<WebView
32+
source={{ uri: url }}
33+
style={styles.webview}
34+
onError={() => router.back()}
35+
/>
36+
</View>
37+
);
38+
}
39+
40+
const styles = StyleSheet.create({
41+
container: {
42+
flex: 1,
43+
backgroundColor: 'white',
44+
},
45+
webview: {
46+
flex: 1,
47+
},
48+
errorContainer: {
49+
flex: 1,
50+
justifyContent: 'center',
51+
alignItems: 'center',
52+
backgroundColor: 'white',
53+
},
54+
errorText: {
55+
color: 'red',
56+
fontSize: 16,
57+
},
58+
});

src/components/settings/language-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useMemo } from 'react';
1+
import React, { useCallback, useMemo } from 'react';
22

33
import { translate, useSelectedLanguage } from '@/core';
44
import type { Language } from '@/core/i18n/resources';

0 commit comments

Comments
 (0)