Skip to content

Commit

Permalink
added kalia flow
Browse files Browse the repository at this point in the history
  • Loading branch information
prtkjakhar committed Mar 5, 2024
1 parent 4dde2e3 commit a8d0086
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 46 deletions.
Binary file added apps/amakrushi/src/assets/images/kalia_status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 41 additions & 3 deletions apps/amakrushi/src/components/HomePage/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,55 @@
width: 57%;
margin: auto;
position: relative;
top: 10%;
top: 3%;
text-align: center;
font-family: 'Mulish-Bold';
font-size: 3.5vh;
font-weight: 700;
}

.imgButtons{
position: relative;
top: 7%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}

.imgBtn {
background-color: white;
box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
padding: 10px;
border-radius: 12px;
display: flex;
flex-direction: column;
justify-content: center;
cursor: pointer;
width: 110px;
height: 110px;
}

.imgBtn:active{
transform: scale(0.9);
}

.imgBtn img{
min-width: 80% !important;
}

.imgBtn p{
color: var(--font);
font-family: 'Mulish-bold';
text-align: center;
line-height: 1;
margin-bottom: 5px;
}

.voiceRecorder {
position: relative;
margin: auto;
top: 25%;
top: 10%;
text-align: center;
height: 18vh;
width: 18vh;
Expand Down Expand Up @@ -116,7 +154,7 @@
position: absolute;
left: 50%;
right: 50%;
bottom: 1vh;
bottom: 0;
transform: translateX(-50%);
color: var(--font);
width: 70%;
Expand Down
134 changes: 93 additions & 41 deletions apps/amakrushi/src/components/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import RenderVoiceRecorder from '../recorder/RenderVoiceRecorder';
import { useFlags } from 'flagsmith/react';
import DownTimePage from '../down-time-page';
import { recordUserLocation } from '../../utils/location';
import kaliaStatusImg from '../../assets/images/kalia_status.png';
import plantProtectionImg from '../../assets/images/plant_protection.png';
import weatherAdvisoryImg from '../../assets/images/weather_advisory.png';

const HomePage: NextPage = () => {
const context = useContext(AppContext);
Expand Down Expand Up @@ -65,7 +68,7 @@ const HomePage: NextPage = () => {
};

useEffect(() => {
if (inputMsg.length > 0 && !(localStorage.getItem('locale') === 'en')) {
if (inputMsg.length > 0 && !(localStorage.getItem('locale') === 'en') && !context?.kaliaClicked) {
if (suggestionClicked) {
setSuggestionClicked(false);
return;
Expand Down Expand Up @@ -200,7 +203,6 @@ const HomePage: NextPage = () => {
}
recordUserLocation();


// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand All @@ -214,7 +216,9 @@ const HomePage: NextPage = () => {
console.log('clearing mssgs');
context?.setMessages([]);
router.push('/chat');
context?.sendMessage(msg);
if(context?.kaliaClicked){
context?.sendMessage("Aadhar number - "+msg);
}else context?.sendMessage(msg);
} else {
toast.error(t('error.disconnected'));
return;
Expand All @@ -225,8 +229,12 @@ const HomePage: NextPage = () => {

const handleInputChange = (e: any) => {
const inputValue = e.target.value;
setInputMsg(inputValue);
// Store the cursor position
if(context?.kaliaClicked){
if(!/^[0-9]*$/.test(inputValue) || inputValue.length > 12){
toast.error('Please enter valid aadhaar number');
// setInputMsg(inputValue.slice(0, 12));
}else setInputMsg(inputValue);
}else setInputMsg(inputValue);
const cursorPosition = e.target.selectionStart;
setCursorPosition(cursorPosition);
// setShowExampleMessages(inputValue.length === 0);
Expand Down Expand Up @@ -352,10 +360,52 @@ const HomePage: NextPage = () => {
<>
<div className={styles.main} onClick={handleDocumentClick}>
<div className={styles.title}>{t('label.ask_me')}</div>
<div className={styles.imgButtons}>
<div
style={{
display: 'flex',
justifyContent: 'space-evenly',
width: '100%',
maxWidth: '500px',
}}>
<div className={styles.imgBtn} onClick={() => {context?.setKaliaClicked((props: boolean) => !props);}}>
<p>KALIA status</p>
<Image
src={kaliaStatusImg}
width={80}
height={57}
alt="kaliastatus"
/>
</div>
<div className={styles.imgBtn} onClick={() => {
toast('Coming Soon!')
}}>
<p>Plant Protection</p>
<Image
src={plantProtectionImg}
width={60}
height={60}
alt="plantprotection"
/>
</div>
</div>
<div className={styles.imgBtn} style={{ marginTop: '20px' }} onClick={() => {
sendMessage('weather advisory');
}}>
<p>Weather Advisory</p>
<Image
src={weatherAdvisoryImg}
width={50}
height={70}
alt="weatheradvisory"
/>
</div>
</div>
<div className={styles.voiceRecorder} ref={voiceRecorderRef}>
<RenderVoiceRecorder setInputMsg={setInputMsg} tapToSpeak={true} />
</div>
<div

{/* <div
className={
styles.exampleMessages +
(showExampleMessages
Expand All @@ -380,46 +430,48 @@ const HomePage: NextPage = () => {
style={{ marginRight: '2px' }}
/>
{choice.text}
{/* <div className={styles.rightIcon}>
<div className={styles.rightIcon}>
<RightIcon width="35px" color="var(--secondarygreen)" />
</div> */}
</div>
</button>
);
})}
</div>

<form onSubmit={(event) => event?.preventDefault()}>
<div
ref={chatBoxButton}
className={`${`${styles.inputBox} ${styles.inputBoxOpen}`}`}>
<div className={styles.suggestions}>
{suggestions.map((elem, index) => {
return (
<div
key={index}
onClick={() => suggestionClickHandler(elem)}
className={`${styles.suggestion} ${activeSuggestion === index ? styles.active : ''
}`}
onMouseEnter={(e) => suggestionHandler(e, index)}>
{elem}
</div>
);
})}
</div>
<textarea
ref={inputRef}
rows={1}
value={inputMsg}
onChange={handleInputChange}
placeholder={placeholder}
/>
<button
type="submit"
className={styles.sendButton}>
<Image src={SendIcon} width={50} height={50} alt="sendIcon" onClick={() => sendMessage(inputMsg)} />
</button>
</div> */}
<div
ref={chatBoxButton}
className={`${`${styles.inputBox} ${styles.inputBoxOpen}`}`}>
<div className={styles.suggestions}>
{suggestions.map((elem, index) => {
return (
<div
key={index}
onClick={() => suggestionClickHandler(elem)}
className={`${styles.suggestion} ${
activeSuggestion === index ? styles.active : ''
}`}
onMouseEnter={(e) => suggestionHandler(e, index)}>
{elem}
</div>
);
})}
</div>
</form>
<textarea
ref={inputRef}
rows={1}
value={inputMsg}
onChange={handleInputChange}
placeholder={!context?.kaliaClicked ? placeholder: 'Enter you Aadhar number'}
/>
<button type="submit" className={styles.sendButton}>
<Image
src={SendIcon}
width={50}
height={50}
alt="sendIcon"
onClick={() => sendMessage(inputMsg)}
/>
</button>
</div>
</div>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions apps/amakrushi/src/components/NavBar/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
padding: 5px;
background-color: var(--bg-color);
height: 100px;
height: 85px;
border-bottom: 1px solid #dbdbdb;
}

Expand Down
5 changes: 5 additions & 0 deletions apps/amakrushi/src/context/ContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const ContextProvider: FC<{
const [startTime, setStartTime] = useState(Date.now());
const [endTime, setEndTime] = useState(Date.now());
const [lastMsgId, setLastMsgId] = useState('');
const [kaliaClicked, setKaliaClicked] = useState(false);

const downloadChat = useMemo(() => {
return (e: string) => {
Expand Down Expand Up @@ -641,6 +642,8 @@ const ContextProvider: FC<{
downloadChat,
audioPlaying,
setAudioPlaying,
kaliaClicked,
setKaliaClicked
}),
[
locale,
Expand All @@ -667,6 +670,8 @@ const ContextProvider: FC<{
downloadChat,
audioPlaying,
setAudioPlaying,
kaliaClicked,
setKaliaClicked
]
);

Expand Down

0 comments on commit a8d0086

Please sign in to comment.