From d3f4c5a70d8227fd4430954eeffec062d4a61a55 Mon Sep 17 00:00:00 2001 From: tsyirvo Date: Wed, 17 Apr 2024 15:57:48 +0200 Subject: [PATCH] feat: add util to request store review --- .env.development | 1 + .env.production | 1 + .env.staging | 1 + app.config.ts | 3 +++ env.js | 2 ++ package.json | 1 + .../storeRating/hooks/useAppStoreReview.ts | 21 +++++++++++++++++++ yarn.lock | 10 +++++++++ 8 files changed, 40 insertions(+) create mode 100644 src/features/storeRating/hooks/useAppStoreReview.ts diff --git a/.env.development b/.env.development index c523950a..9de08aa6 100644 --- a/.env.development +++ b/.env.development @@ -3,6 +3,7 @@ APP_NAME="Dev" EXPO_APPLE_TEAM_ID="" API_URL="" +ITUNES_ITEM_ID="" SENTRY_DSN="" SENTRY_ORG="" diff --git a/.env.production b/.env.production index b385a91e..51022fd1 100644 --- a/.env.production +++ b/.env.production @@ -3,6 +3,7 @@ APP_NAME="RN Starter" EXPO_APPLE_TEAM_ID="" API_URL="" +ITUNES_ITEM_ID="" SENTRY_DSN="" SENTRY_ORG="" diff --git a/.env.staging b/.env.staging index 34c3fa6d..28da0188 100644 --- a/.env.staging +++ b/.env.staging @@ -3,6 +3,7 @@ APP_NAME="Staging" EXPO_APPLE_TEAM_ID="" API_URL="" +ITUNES_ITEM_ID="" SENTRY_DSN="" SENTRY_ORG="" diff --git a/app.config.ts b/app.config.ts index d1d80f0e..05e15d56 100644 --- a/app.config.ts +++ b/app.config.ts @@ -94,6 +94,8 @@ export default ({ config }: ConfigContext): ExpoConfig => ({ ios: { supportsTablet: false, bundleIdentifier: Env.BUNDLE_ID, + // TODO(prod): Add correct app store URL + appStoreUrl: `https://apps.apple.com/app/XXX/${Env.ITUNES_ITEM_ID}`, config: { usesNonExemptEncryption: false, }, @@ -104,6 +106,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({ backgroundColor: '#000', }, package: Env.PACKAGE, + playStoreUrl: `https://play.google.com/store/apps/details?id=${Env.PACKAGE}`, }, plugins, extra: { diff --git a/env.js b/env.js index 8d916acc..1b36c73e 100644 --- a/env.js +++ b/env.js @@ -38,6 +38,7 @@ const client = z.object({ // ADD CLIENT ENV VARS HERE API_URL: z.string(), + ITUNES_ITEM_ID: z.string(), FLAGSMITH_KEY: z.string(), AMPLITUDE_API_KEY: z.string(), SENTRY_DSN: z.string(), @@ -66,6 +67,7 @@ const _clientEnv = { // ADD ENV VARS HERE TOO APP_NAME: process.env.APP_NAME, API_URL: process.env.API_URL, + ITUNES_ITEM_ID: process.env.ITUNES_ITEM_ID, FLAGSMITH_KEY: process.env.FLAGSMITH_KEY, AMPLITUDE_API_KEY: process.env.AMPLITUDE_API_KEY, SENTRY_DSN: process.env.SENTRY_DSN, diff --git a/package.json b/package.json index baabc86c..1b41d484 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "expo-secure-store": "~12.8.1", "expo-splash-screen": "~0.26.4", "expo-status-bar": "~1.11.1", + "expo-store-review": "~6.8.3", "expo-updates": "~0.24.12", "graphql": "16.8.1", "graphql-request": "6.1.0", diff --git a/src/features/storeRating/hooks/useAppStoreReview.ts b/src/features/storeRating/hooks/useAppStoreReview.ts new file mode 100644 index 00000000..9e623965 --- /dev/null +++ b/src/features/storeRating/hooks/useAppStoreReview.ts @@ -0,0 +1,21 @@ +import * as StoreReview from 'expo-store-review'; + +export const useAppStoreReview = () => { + const isStoreReviewAvailable = async () => { + const [isActionAvailable, isRequestAvailable] = await Promise.all([ + StoreReview.hasAction(), + StoreReview.isAvailableAsync(), + ]); + + return isActionAvailable && isRequestAvailable; + }; + + const requestStoreReview = async () => { + await StoreReview.requestReview(); + }; + + return { + isStoreReviewAvailable, + requestStoreReview, + }; +}; diff --git a/yarn.lock b/yarn.lock index 4e7c150d..d5a32b21 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11523,6 +11523,15 @@ __metadata: languageName: node linkType: hard +"expo-store-review@npm:~6.8.3": + version: 6.8.3 + resolution: "expo-store-review@npm:6.8.3" + peerDependencies: + expo: "*" + checksum: 8a8967173aed19ac6640df51d74f909016715e83988ea030c93a276ea37fa80b13673e1fc028965511469fb657e9a9820b96a5deebce2213fd57fb5fb92aa179 + languageName: node + linkType: hard + "expo-structured-headers@npm:~3.7.0": version: 3.7.2 resolution: "expo-structured-headers@npm:3.7.2" @@ -19355,6 +19364,7 @@ __metadata: expo-secure-store: ~12.8.1 expo-splash-screen: ~0.26.4 expo-status-bar: ~1.11.1 + expo-store-review: ~6.8.3 expo-updates: ~0.24.12 fs-extra: 11.2.0 graphql: 16.8.1