Use af in the default state and configure the phone number input styling

This commit is contained in:
sabaimran 2024-08-01 17:04:57 +05:30
parent 723b37955a
commit 1b2cad2a2c
3 changed files with 49 additions and 2 deletions

View file

@ -424,6 +424,31 @@ export default function SettingsView() {
} }
}; };
const disconnectNumber = async () => {
try {
const response = await fetch(`/api/phone`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) throw new Error('Failed to disconnect phone number');
setPhoneNumber(undefined);
setNumberValidationState(PhoneNumberValidationState.Setup);
toast({
title: "📱 Phone",
description: "Phone number disconnected",
});
} catch (error) {
console.error('Error disconnecting phone number:', error);
toast({
title: "📱 Phone",
description: "Failed to disconnect phone number. Try again or contact us at team@khoj.dev",
});
}
}
const setSubscription = async (state: string) => { const setSubscription = async (state: string) => {
try { try {
const url = `/api/subscription?email=${userConfig?.username}&operation=${state}`; const url = `/api/subscription?email=${userConfig?.username}&operation=${state}`;
@ -951,8 +976,9 @@ export default function SettingsView() {
disabled={numberValidationState === PhoneNumberValidationState.VerifyOTP} disabled={numberValidationState === PhoneNumberValidationState.VerifyOTP}
initOptions={{ initOptions={{
separateDialCode: true, separateDialCode: true,
initialCountry: "us", initialCountry: "af",
utilsScript: "https://assets.khoj.dev/intl-tel-input%4023.8.0_build_js_utils.js", utilsScript: "https://assets.khoj.dev/intl-tel-input%4023.8.0_build_js_utils.js",
containerClass: `${styles.phoneInput}`
}} }}
/> />
{numberValidationState === PhoneNumberValidationState.VerifyOTP && ( {numberValidationState === PhoneNumberValidationState.VerifyOTP && (
@ -1000,6 +1026,16 @@ export default function SettingsView() {
} }
</Button> </Button>
)} )}
{
numberValidationState === PhoneNumberValidationState.Verified && (
<Button
variant="outline"
onClick={() => disconnectNumber()}
>
<CloudSlash className="h-5 w-5 mr-2" />Disconnect
</Button>
)
}
</CardFooter> </CardFooter>
</Card> </Card>
</div> </div>

View file

@ -9,3 +9,14 @@ div.contentBody {
display: grid; display: grid;
margin: auto; margin: auto;
} }
div.phoneInput {
padding: 0rem;
}
div.phoneInput input {
width: 100%;
padding: 0.5rem;
border: 1px solid hsla(var(--border));
border-radius: 0.25rem;
}

View file

@ -1298,7 +1298,7 @@ def get_user_config(user: KhojUser, request: Request, is_detailed: bool = False)
"user_photo": user_picture, "user_photo": user_picture,
"is_active": is_active, "is_active": is_active,
"given_name": given_name, "given_name": given_name,
"phone_number": str(user.phone_number), "phone_number": str(user.phone_number) if user.phone_number else "",
"is_phone_number_verified": user.verified_phone_number, "is_phone_number_verified": user.verified_phone_number,
# user content settings # user content settings
"enabled_content_source": enabled_content_sources, "enabled_content_source": enabled_content_sources,