A Simple Todo List App Using React Native Expo, Firebase Authentication & Cloud Firestore (Part 5 – Profile Screen Setup)
Created by: Anisa Damayanti, S.Kom.
For Study Purpose Only!
Setelah halaman Todo List berhasil dibuat dengan fitur CRUD pada Part 4, pada bagian ini kita akan mulai mengatur dan mengembangkan halaman Profile pada aplikasi My Todolist Gue.
Halaman Profile merupakan fitur yang digunakan untuk menampilkan dan mengelola informasi akun pengguna yang sedang login. Pada tutorial kali ini, kita akan menggunakan Firebase Authentication dan Cloud Firestore untuk mengambil serta mengelola data profil pengguna.
Kegiatan meliputi pembuatan tampilan halaman Profile, menampilkan informasi akun pengguna (Read), serta mengubah informasi profil (Update) dari Cloud Firestore. Data profil akan diakses berdasarkan UID pengguna yang diperoleh dari Firebase Authentication, sehingga setiap pengguna dapat mengelola informasi profil miliknya sendiri.
Dengan demikian, aplikasi My Todolist Gue akan memiliki fitur pengelolaan profil pengguna yang terintegrasi dengan Firebase, sehingga informasi akun dapat ditampilkan dan diperbarui sesuai kebutuhan.
A. Persiapan Tools
- Pada VSCode pastikan sudah membuka folder project yang sudah berhasil diinstall sebelumnya

- Pastikan pada Terminal VSCode sudah mengarahkan root folder project my-todolist-gue

B. Langkah-langkah Pengaturan Halaman Profile
Persiapan Assets, Components, Navigasi
Assets
- Bukalah folder assets
- Ubahlah file styles.js dengan menambahkan beberapa paragraf script berikut lalu simpan

Components
- Buatlah file baru bernama ProfileScreen.js di dalam folder components

- Copy seluruh paragraf script berikut dan Paste ke dalam file ProfileScreen.js lalu simpan
import React, { useEffect, useState } from "react";
import {View, Text, TextInput, Pressable, ScrollView, Modal} from "react-native";
import { signOut } from "firebase/auth";
import { doc, getDoc, setDoc } from "firebase/firestore";
import { styles } from "../assets/styles";
import { auth, db } from "../database/firebaseConfig";
export default function ProfileScreen({ user }) {
//data profile
const [nama, setNama] = useState("");
const [kelas, setKelas] = useState("");
const [nis, setNis] = useState("");
//mode edit data profile
const [editing, setEditing] = useState(false);
//MODAL KONFIRMASI LOGOUT
const [showLogoutModal, setShowLogoutModal] = useState(false);
//MODAL NOTIFIKASI PROFILE
const [showNotificationModal, setShowNotificationModal] = useState(false);
const [notificationTitle, setNotificationTitle] = useState("");
const [notificationMessage, setNotificationMessage] = useState("");
const [notificationType, setNotificationType] = useState("info");
return (
<>
<ScrollView style={styles.screen} contentContainerStyle={styles.scrollContent}>
<View style={styles.card}>
<Text style={styles.title}>MY PROFILE</Text>
<Text style={styles.subtitle}>Data diri</Text>
<Text style={styles.label}>Email</Text>
<Text style={styles.info}>{user?.email}</Text>
<Text style={styles.label}>UID</Text>
<Text style={styles.uid}>{user?.uid}</Text>
<Text style={styles.label}>Nama</Text>
{editing ? (
<TextInput
style={styles.input}
value={nama}
onChangeText={setNama}
placeholder="Masukkan nama"
placeholderTextColor="#888"
/>
) : (
<Text style={styles.info}>{nama || "-"}</Text>
)}
<Text style={styles.label}>Kelas</Text>
{editing ? (
<TextInput
style={styles.input}
value={kelas}
onChangeText={setKelas}
placeholder="Masukkan kelas"
placeholderTextColor="#888"
/>
) : (
<Text style={styles.info}>{kelas || "-"}</Text>
)}
<Text style={styles.label}>NIS</Text>
{editing ? (
<TextInput
style={styles.input}
value={nis}
onChangeText={setNis}
placeholder="Masukkan NIS"
placeholderTextColor="#888"
keyboardType="numeric"
/>
) : (
<Text style={styles.info}>{nis || "-"}</Text>
)}
{editing ? (
<Pressable style={styles.button} onPress={simpanProfile} hitSlop={10}>
<Text style={styles.buttonText}>Simpan Profile</Text>
</Pressable>
) : (
<Pressable style={styles.button} onPress={() => setEditing(true)} hitSlop={10}>
<Text style={styles.buttonText}>Edit Profile</Text>
</Pressable>
)}
<Pressable style={styles.logoutButton} onPress={bukaModalLogout} hitSlop={10}>
<Text style={styles.buttonText}>LOGOUT</Text>
</Pressable>
</View>
{/* MODAL NOTIFIKASI PROFILE */}
<Modal visible={showNotificationModal} transparent={true} animationType="fade" onRequestClose={tutupNotification}>
<View style={styles.modalOverlay}>
<View style={styles.modalBox}>
<Text
style={[
styles.modalTitle,
notificationType === "success" && styles.modalSuccessTitle,
notificationType === "error" && styles.modalErrorTitle,
]}
>
{notificationTitle}
</Text>
<Text style={styles.modalMessage}>{notificationMessage}</Text>
<Pressable style={styles.modalOkButton} onPress={tutupNotification} hitSlop={10}>
<Text style={styles.modalOkText}>OK</Text>
</Pressable>
</View>
</View>
</Modal>
{/* MODAL KONFIRMASI LOGOUT */}
<Modal visible={showLogoutModal} transparent={true} animationType="fade" onRequestClose={batalLogout}>
<View style={styles.modalOverlay}>
<View style={styles.modalBox}>
<Text style={styles.modalTitle}>Logout</Text>
<Text style={styles.modalMessage}>Apakah Anda yakin ingin keluar dari akun?</Text>
<View style={styles.modalButtonContainer}>
<Pressable style={styles.modalCancelButton} onPress={batalLogout} hitSlop={10}>
<Text style={styles.modalCancelText}>Batal</Text>
</Pressable>
<Pressable style={styles.modalLogoutButton} onPress={konfirmasiLogout} hitSlop={10}>
<Text style={styles.modalLogoutText}>Logout</Text>
</Pressable>
</View>
</View>
</View>
</Modal>
</ScrollView>
</>
);
}
JavaScript- Selanjutnya tambahkan paragraf script berikut di dalam file ProfileScreen.js lalu simpan *posisi di mana menambahkan code lihat gambar



Navigasi
- Ubahlah file MainTabs.js dengan menambahkan beberapa paragraf script berikut lalu simpan

- Selanjutnya me-running project dengan menjalankan perintah: npx expo start -c, lalu tekan Enter

2. tampilan terminal jika berhasil akan memunculkan QR Code yang siap untuk di scan
3. menampilkan web sebagai Live Preview dengan alamat url http://localhost:8081
- Kemudian buka aplikasi Expo Go di device Android/iOS, disarankan untuk login dengan akun Expo yang sama seperti login di terminal dan menggunakan sinyal internet yang sama antara komputer/laptop dengan device

- Pada Web Browser seperti Chrome, Chrome Developer, Mozilla Firefox ataupun Microsoft Edge membuka url berikut: http://localhost:8081

dilihat di Dashboard Cloud Firestore



