Update Subscription.tsx

This commit is contained in:
Egor
2026-02-04 01:08:05 +03:00
committed by GitHub
parent 9804e3a874
commit 026cb47694

View File

@@ -1645,100 +1645,100 @@ export default function Subscription() {
<div className="max-h-64 space-y-2 overflow-y-auto"> <div className="max-h-64 space-y-2 overflow-y-auto">
{countriesData.countries {countriesData.countries
.filter((country) => country.is_available || country.is_connected) .filter((country) => country.is_available || country.is_connected)
.map((country) => { .map((country) => {
const isCurrentlyConnected = country.is_connected; const isCurrentlyConnected = country.is_connected;
const isSelected = selectedServersToUpdate.includes(country.uuid); const isSelected = selectedServersToUpdate.includes(country.uuid);
const willBeAdded = !isCurrentlyConnected && isSelected; const willBeAdded = !isCurrentlyConnected && isSelected;
const willBeRemoved = isCurrentlyConnected && !isSelected; const willBeRemoved = isCurrentlyConnected && !isSelected;
return ( return (
<button <button
key={country.uuid} key={country.uuid}
onClick={() => { onClick={() => {
if (isSelected) { if (isSelected) {
setSelectedServersToUpdate((prev) => setSelectedServersToUpdate((prev) =>
prev.filter((u) => u !== country.uuid), prev.filter((u) => u !== country.uuid),
); );
} else { } else {
setSelectedServersToUpdate((prev) => [...prev, country.uuid]); setSelectedServersToUpdate((prev) => [...prev, country.uuid]);
} }
}} }}
disabled={!country.is_available && !isCurrentlyConnected} disabled={!country.is_available && !isCurrentlyConnected}
className={`flex w-full items-center justify-between rounded-xl border p-3 text-left transition-all ${ className={`flex w-full items-center justify-between rounded-xl border p-3 text-left transition-all ${
isSelected isSelected
? willBeAdded ? willBeAdded
? 'border-success-500 bg-success-500/10' ? 'border-success-500 bg-success-500/10'
: 'border-accent-500 bg-accent-500/10' : 'border-accent-500 bg-accent-500/10'
: willBeRemoved
? 'border-error-500/50 bg-error-500/5'
: 'border-dark-700/50 bg-dark-800/30 hover:border-dark-600'
} ${!country.is_available && !isCurrentlyConnected ? 'cursor-not-allowed opacity-50' : ''}`}
>
<div className="flex items-center gap-3">
<span className="text-lg">
{willBeAdded
? ''
: willBeRemoved : willBeRemoved
? '' ? 'border-error-500/50 bg-error-500/5'
: isSelected : 'border-dark-700/50 bg-dark-800/30 hover:border-dark-600'
? '' } ${!country.is_available && !isCurrentlyConnected ? 'cursor-not-allowed opacity-50' : ''}`}
: '⚪'} >
</span> <div className="flex items-center gap-3">
<div> <span className="text-lg">
<div className="flex items-center gap-2 font-medium text-dark-100"> {willBeAdded
{country.name} ? ''
{country.has_discount && !isCurrentlyConnected && ( : willBeRemoved
<span className="rounded bg-success-500/20 px-1.5 py-0.5 text-xs text-success-400"> ? ''
-{country.discount_percent}% : isSelected
</span> ? '✅'
: '⚪'}
</span>
<div>
<div className="flex items-center gap-2 font-medium text-dark-100">
{country.name}
{country.has_discount && !isCurrentlyConnected && (
<span className="rounded bg-success-500/20 px-1.5 py-0.5 text-xs text-success-400">
-{country.discount_percent}%
</span>
)}
</div>
{willBeAdded && (
<div className="text-xs text-success-400">
+{formatPrice(country.price_kopeks)}{' '}
{t('subscription.serverManagement.forDays', {
days: countriesData.days_left,
})}
{country.has_discount && (
<span className="ml-1 text-dark-500 line-through">
{formatPrice(
Math.round(
(country.base_price_kopeks *
countriesData.days_left) /
30,
),
)}
</span>
)}
</div>
)}
{!willBeAdded && !isCurrentlyConnected && (
<div className="text-xs text-dark-500">
{formatPrice(country.price_per_month_kopeks)}
{t('subscription.serverManagement.perMonth')}
{country.has_discount && (
<span className="ml-1 text-dark-600 line-through">
{formatPrice(country.base_price_kopeks)}
</span>
)}
</div>
)}
{!country.is_available && !isCurrentlyConnected && (
<div className="text-xs text-dark-500">
{t('subscription.serverManagement.unavailable')}
</div>
)} )}
</div> </div>
{willBeAdded && (
<div className="text-xs text-success-400">
+{formatPrice(country.price_kopeks)}{' '}
{t('subscription.serverManagement.forDays', {
days: countriesData.days_left,
})}
{country.has_discount && (
<span className="ml-1 text-dark-500 line-through">
{formatPrice(
Math.round(
(country.base_price_kopeks *
countriesData.days_left) /
30,
),
)}
</span>
)}
</div>
)}
{!willBeAdded && !isCurrentlyConnected && (
<div className="text-xs text-dark-500">
{formatPrice(country.price_per_month_kopeks)}
{t('subscription.serverManagement.perMonth')}
{country.has_discount && (
<span className="ml-1 text-dark-600 line-through">
{formatPrice(country.base_price_kopeks)}
</span>
)}
</div>
)}
{!country.is_available && !isCurrentlyConnected && (
<div className="text-xs text-dark-500">
{t('subscription.serverManagement.unavailable')}
</div>
)}
</div> </div>
</div> {country.country_code && (
{country.country_code && ( <span className="text-xl">
<span className="text-xl"> {getFlagEmoji(country.country_code)}
{getFlagEmoji(country.country_code)} </span>
</span> )}
)} </button>
</button> );
); })}
})}
</div> </div>
{(() => { {(() => {