end of tickets

This commit is contained in:
Thomas Demirdjian
2025-11-17 15:54:54 +01:00
parent c7cbd85088
commit 016f7c27ac
8 changed files with 159 additions and 71 deletions
+3
View File
@@ -507,3 +507,6 @@ export const CHOOSE_DECOR = [
"Jardin",
"Neige",
];
export const defaultAvatar =
"https://firebasestorage.googleapis.com/v0/b/musicland-d33f9.firebasestorage.app/o/default%2FdefaultAvatar.png?alt=media&token=99b6231a-e594-421e-b6cd-0e3aab148be0";
+100 -40
View File
@@ -30,6 +30,49 @@ const stripePromise = loadStripe(
isStripeTesting ? STRIPE_PUBLISHABLE_KEY_TEST : STRIPE_PUBLISHABLE_KEY_LIVE,
);
const isSafariBrowser = () => {
if (
typeof navigator !== "object" ||
typeof navigator.userAgent !== "string"
) {
return false;
}
return (
/safari/i.test(navigator.userAgent) &&
!/(chrome|crios|android|fxios|edgios|opr|ucbrowser)/i.test(
navigator.userAgent,
)
);
};
const openSafariCheckoutWindow = () => {
if (!isWeb || typeof window === "undefined") {
return null;
}
if (!isSafariBrowser()) {
return null;
}
try {
const placeholder = window.open("", "_blank", "noopener,noreferrer");
if (!placeholder) {
return null;
}
try {
placeholder.document.write(
"<p style='font-family: sans-serif; color: #111; padding: 16px;'>Chargement du paiement Stripe...</p>",
);
placeholder.document.title = "Stripe Checkout";
} catch {
// Ignore failures when the window gets reused or is cross-domain.
}
placeholder.focus?.();
return placeholder;
} catch (error) {
console.warn("[StripeProvider] Safari window pre-open failed", error);
return null;
}
};
export const StripeContext = React.createContext(null);
export const useStripe = () => {
@@ -68,56 +111,70 @@ const StripeProvider = ({ children }) => {
setClientSecret(null);
}, []);
const redirectToCheckout = React.useCallback(async (checkoutUrl) => {
if (!checkoutUrl) {
throw new Error("Session Stripe introuvable.");
}
const redirectToCheckout = React.useCallback(
async (checkoutUrl, { safariWindow } = {}) => {
if (!checkoutUrl) {
throw new Error("Session Stripe introuvable.");
}
if (isWeb) {
if (typeof window !== "undefined") {
const openedTab = window.open(
checkoutUrl,
"_blank",
"noopener,noreferrer",
);
// Fallback to same-tab navigation if the popup is blocked.
if (!openedTab) {
window.location.assign(checkoutUrl);
if (isWeb) {
if (safariWindow && !safariWindow.closed) {
try {
safariWindow.location.replace(checkoutUrl);
} catch (navigationError) {
safariWindow.location.href = checkoutUrl;
}
safariWindow.focus?.();
return;
}
if (typeof window !== "undefined") {
const openedTab = window.open(
checkoutUrl,
"_blank",
"noopener,noreferrer",
);
if (openedTab) {
return;
}
}
await Linking.openURL(checkoutUrl);
return;
}
throw new Error("Navigation Stripe impossible dans cet environnement.");
}
const isMobileApp =
Platform.OS === "ios" || Platform.OS === "android";
const isMobileApp =
Platform.OS === "ios" || Platform.OS === "android";
if (isMobileApp) {
try {
await WebBrowser.openBrowserAsync(checkoutUrl, {
enableDefaultShareMenu: false,
dismissButtonStyle: "close",
presentationStyle:
WebBrowser?.WebBrowserPresentationStyle?.PAGE_SHEET,
});
return;
} catch (webBrowserError) {
console.warn(
"[StripeProvider] WebBrowser checkout fallback",
webBrowserError,
);
if (isMobileApp) {
try {
await WebBrowser.openBrowserAsync(checkoutUrl, {
enableDefaultShareMenu: false,
dismissButtonStyle: "close",
presentationStyle:
WebBrowser?.WebBrowserPresentationStyle?.PAGE_SHEET,
});
return;
} catch (webBrowserError) {
console.warn(
"[StripeProvider] WebBrowser checkout fallback",
webBrowserError,
);
}
}
}
const canOpen = await Linking.canOpenURL(checkoutUrl);
if (!canOpen) {
throw new Error("Impossible d'ouvrir l'URL de paiement.");
}
await Linking.openURL(checkoutUrl);
}, []);
const canOpen = await Linking.canOpenURL(checkoutUrl);
if (!canOpen) {
throw new Error("Impossible d'ouvrir l'URL de paiement.");
}
await Linking.openURL(checkoutUrl);
},
[],
);
const runCheckoutSession = React.useCallback(
async ({ callableName, payload, logTag }) => {
const safariWindow = openSafariCheckoutWindow();
try {
const callable = getFunctionsClient(FUNCTIONS_REGION).httpsCallable(
callableName,
@@ -127,8 +184,11 @@ const StripeProvider = ({ children }) => {
if (!checkoutUrl) {
throw new Error("Session Stripe introuvable.");
}
await redirectToCheckout(checkoutUrl);
await redirectToCheckout(checkoutUrl, { safariWindow });
} catch (error) {
if (safariWindow && !safariWindow.closed) {
safariWindow.close();
}
console.error(`[StripeProvider] ${logTag}`, error);
throw new Error(
error?.message ||
@@ -49,9 +49,6 @@ const ResearchHeader = ({
<BlurView
intensity={Platform.OS !== "ios" ? 10 : 20}
style={styles.blurView}
// experimentalBlurMethod={
// Platform.OS !== "ios" ? "dimezisBlurView" : "none"
// }
>
<Text style={styles.menu}>{item}</Text>
</BlurView>
@@ -10,6 +10,7 @@ import { FONT_FAMILY } from "../../../styles/Fonts";
import { getArtistDisplayName } from "../../../utils/artistName";
import CreateLyricsHeader from "../../Writing/components/CreateLyricsHeader";
import MusicCard from "./MusicCard";
import { defaultAvatar } from "../../../data/data";
const EmptyText = ({ text }) => (
<View style={{ flex: 1, alignItems: "center", paddingVertical: 16 }}>
@@ -80,13 +81,13 @@ const SearchResultsList = ({
...cover.options.flatMap((option) => [
option?.finalUrl,
option?.generatedUrl,
])
]),
);
}
return coverCandidates.find(isValid) || null;
},
[]
[],
);
const handleMusicPress = (project) => {
@@ -164,7 +165,7 @@ const SearchResultsList = ({
setShowMenu(
(previous) =>
!previous ||
positionTop?.top !== (menuPosition?.top ?? null)
positionTop?.top !== (menuPosition?.top ?? null),
);
}}
/>
@@ -210,7 +211,7 @@ const SearchResultsList = ({
setShowMenu(
(previous) =>
!previous ||
positionTop?.top !== (menuPosition?.top ?? null)
positionTop?.top !== (menuPosition?.top ?? null),
);
}}
/>
@@ -249,12 +250,7 @@ const SearchResultsList = ({
onPress={() => handleProfilePress(user.id)}
>
<ProfilePicture
uri={
user?.pictureUrl ||
user?.profilePictureURL ||
user?.photoURL ||
null
}
uri={user?.profilePictureURL || defaultAvatar}
size={60}
imageProps={{ priority: "high" }}
/>
+1 -1
View File
@@ -197,7 +197,7 @@ const SongReady = () => {
try {
await pauseAllPlayers();
} catch {}
navigate(Routes.ComposeSong, { isRegeneration: true });
navigate(Routes.Lyrics);
};
const handleRegeneratePress = () => {
+8 -8
View File
@@ -73,7 +73,7 @@ const CreatingLyrics = ({ active, config, selections }) => {
});
const sanitizedStructure = sanitizeStructureList(
config?.structure,
CUSTOM_SANITIZE_OPTIONS
CUSTOM_SANITIZE_OPTIONS,
);
const callable = firebase
.functions()
@@ -136,7 +136,7 @@ const CreatingLyrics = ({ active, config, selections }) => {
const rawMessage = typeof e?.message === "string" ? e.message : "";
const cleanedMessage = rawMessage.replace(
/^functions error: \w+-\w+:\s*/i,
""
"",
);
setError({
message:
@@ -166,7 +166,7 @@ const CreatingLyrics = ({ active, config, selections }) => {
console.log("💾 [CreatingLyrics] Sauvegarde automatique des paroles");
const sanitizedStructure = sanitizeStructureList(
result?.structure || config?.structure,
CUSTOM_SANITIZE_OPTIONS
CUSTOM_SANITIZE_OPTIONS,
);
const baseConfig =
config && typeof config === "object" && !Array.isArray(config)
@@ -192,12 +192,12 @@ const CreatingLyrics = ({ active, config, selections }) => {
if ("customStructure" in persistedSelections) {
persistedSelections.customStructure = sanitizeStructureList(
persistedSelections.customStructure,
CUSTOM_SANITIZE_OPTIONS
CUSTOM_SANITIZE_OPTIONS,
);
}
if ("parsedStructure" in persistedSelections) {
persistedSelections.parsedStructure = sanitizeStructureList(
persistedSelections.parsedStructure
persistedSelections.parsedStructure,
);
}
}
@@ -250,7 +250,7 @@ const CreatingLyrics = ({ active, config, selections }) => {
onPress: redirect,
},
],
{ cancelable: false }
{ cancelable: false },
);
if (Platform.OS === "web") {
@@ -322,7 +322,7 @@ const CreatingLyrics = ({ active, config, selections }) => {
setSaved(true);
await setIsLoading(true);
console.log(
"📄 [CreatingLyrics] Consultation manuelle du texte"
"📄 [CreatingLyrics] Consultation manuelle du texte",
);
await updateProjectData({
title: result?.title || "",
@@ -337,7 +337,7 @@ const CreatingLyrics = ({ active, config, selections }) => {
} catch (e) {
console.error(
"⚠️ [CreatingLyrics] Erreur lors de l'ouverture manuelle",
e
e,
);
} finally {
await setIsLoading(false);
+16 -4
View File
@@ -37,6 +37,12 @@ const Lyrics = ({ navigation }) => {
const [containerLayout, setContainerLayout] = useState(null);
const { setIsLoading } = useMinuit();
const { selectedProjectId, selectedProject } = useUser();
const hasExistingMusicDraft = useMemo(() => {
if (!Array.isArray(selectedProject?.musicUrls)) return false;
return selectedProject.musicUrls.some(
(url) => typeof url === "string" && url.trim()
);
}, [selectedProject?.musicUrls]);
const [isFocus, setIsFocus] = useState(null);
const [itemsContainerLayout, setItemsContainerLayout] = useState([]);
const [sensitiveContentModal, setSensitiveContentModal] = useState({
@@ -306,6 +312,14 @@ const Lyrics = ({ navigation }) => {
}
const beatmakerStage = getStageAction("beatmaker", projectForStage);
await setIsLoading(false);
if (hasExistingMusicDraft) {
navigate(Routes.ComposeSong, { isRegeneration: true });
return;
}
const handleNavigateToStudio = () => {
const targetRoute = beatmakerStage?.route || Routes.Compose;
navigate(targetRoute, beatmakerStage?.params);
};
alert(
"Céline",
"Bravo ! Vous venez de terminer de créer les paroles de votre musique ! Maintenant vous pouvez passer à la prochaine étape : le Studio pour donner vie à votre chanson !",
@@ -323,10 +337,7 @@ const Lyrics = ({ navigation }) => {
},
{
text: "Continuer vers le Studio",
onPress: () => {
const targetRoute = beatmakerStage?.route || Routes.Compose;
navigate(targetRoute, beatmakerStage?.params);
},
onPress: handleNavigateToStudio,
},
]
);
@@ -350,6 +361,7 @@ const Lyrics = ({ navigation }) => {
projectHasLyrics,
projectLyrics,
selectedProject,
hasExistingMusicDraft,
]);
const typeOccurrences = {};